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 cpptooling.type : CustomHeader; 15 import dextool.io : WriteStrategy; 16 import dextool.type : DextoolVersion, Path; 17 18 /** Control various aspects of the analyze and generation like what nodes to 19 * process. 20 */ 21 @safe interface Controller { 22 /// Query the controller with the filename of the symbol for a decision 23 /// if it shall be processed. 24 bool doSymbolAtLocation(const string filename, const string symbol); 25 26 /** Query the controller for a decision if it shall be processed. */ 27 bool doSymbol(string symbol); 28 } 29 30 /** Transformations that are governed by user input or other factors the 31 * backend is unaware of. 32 */ 33 @safe interface Transform { 34 /// Returns: the transformed name to a filename suitable for a header. 35 Path createHeaderFile(string name); 36 37 /// Returns: the transformed name to a filename suitable for an implementation. 38 Path createImplFile(string name); 39 40 /// Returns: path where to write the raw initial corpora for fuzzing 41 /// based on the number of total parameters. 42 Path createFuzzyDataFile(string name); 43 44 /// Returns: path for xml config to be written to. 45 Path createXmlConfigFile(string name); 46 47 /// Returns: A unique filename. 48 Path createFuzzCase(string name, ulong id); 49 } 50 51 /// Static parameters that are not changed while the backend is working. 52 @safe interface Parameter { 53 /// Dextool Tool version. 54 DextoolVersion getToolVersion(); 55 56 /// Custom header to prepend generated files with. 57 CustomHeader getCustomHeader(); 58 } 59 60 /// Data produced by the generator like files. 61 @safe interface Product { 62 /** Data pushed from the generator to be written to files. 63 * 64 * The put value is the code generation tree. It allows the caller of 65 * Generator to inject more data in the tree before writing. For example a 66 * custom header. 67 * 68 * Params: 69 * fname = file the content is intended to be written to. 70 * hdr_data = data to write to the file. 71 */ 72 void putFile(Path fname, CppHModule data); 73 74 /// ditto. 75 void putFile(Path fname, CppModule data, WriteStrategy strategy = WriteStrategy.overwrite); 76 77 /// Raw data to be written. 78 void putFile(Path fname, const(ubyte)[] data); 79 80 /// Raw data to be written. 81 void putFile(Path fname, string data, WriteStrategy strategy = WriteStrategy.overwrite); 82 }