1 /**
2 Copyright: Copyright (c) 2017, Joakim Brännström. All rights reserved.
3 License: MPL-2
4 Author: Joakim Brännström (joakim.brannstrom@gmx.com)
5 
6 This Source Code Form is subject to the terms of the Mozilla Public License,
7 v.2.0. If a copy of the MPL was not distributed with this file, You can obtain
8 one at http://mozilla.org/MPL/2.0/.
9 */
10 module dextool.plugin.fuzzer.backend.interface_;
11 
12 import dsrcgen.cpp : CppModule, CppHModule;
13 
14 import dextool.type : FileName, DextoolVersion, CustomHeader, WriteStrategy;
15 
16 /** Control various aspects of the analyze and generation like what nodes to
17  * process.
18  */
19 @safe interface Controller {
20     /// Query the controller with the filename of the symbol for a decision
21     /// if it shall be processed.
22     bool doSymbolAtLocation(const string filename, const string symbol);
23 
24     /** Query the controller for a decision if it shall be processed. */
25     bool doSymbol(string symbol);
26 }
27 
28 /** Transformations that are governed by user input or other factors the
29  * backend is unaware of.
30  */
31 @safe interface Transform {
32     /// Returns: the transformed name to a filename suitable for a header.
33     FileName createHeaderFile(string name);
34 
35     /// Returns: the transformed name to a filename suitable for an implementation.
36     FileName createImplFile(string name);
37 
38     /// Returns: path where to write the raw initial corpora for fuzzing
39     /// based on the number of total parameters.
40     FileName createFuzzyDataFile(string name);
41 
42     /// Returns: path for xml config to be written to.
43     FileName createXmlConfigFile(string name);
44 
45     /// Returns: A unique filename.
46     FileName createFuzzCase(string name, ulong id);
47 }
48 
49 /// Static parameters that are not changed while the backend is working.
50 @safe interface Parameter {
51     /// Dextool Tool version.
52     DextoolVersion getToolVersion();
53 
54     /// Custom header to prepend generated files with.
55     CustomHeader getCustomHeader();
56 }
57 
58 /// Data produced by the generator like files.
59 @safe interface Product {
60     /** Data pushed from the generator to be written to files.
61      *
62      * The put value is the code generation tree. It allows the caller of
63      * Generator to inject more data in the tree before writing. For example a
64      * custom header.
65      *
66      * Params:
67      *   fname = file the content is intended to be written to.
68      *   hdr_data = data to write to the file.
69      */
70     void putFile(FileName fname, CppHModule data);
71 
72     /// ditto.
73     void putFile(FileName fname, CppModule data, WriteStrategy strategy = WriteStrategy.overwrite);
74 
75     /// Raw data to be written.
76     void putFile(FileName fname, const(ubyte)[] data);
77 
78     /// Raw data to be written.
79     void putFile(FileName fname, string data, WriteStrategy strategy = WriteStrategy.overwrite);
80 }