1 module deimos.libtcc; 2 3 pragma(lib, "tcc"); 4 5 extern (C) nothrow @nogc: 6 7 struct TCCState{} 8 9 /** Create a new TCC compilation context */ 10 TCCState* tcc_new() pure; 11 12 /** Free a TCC compilation context */ 13 void tcc_delete(scope TCCState* s) pure; 14 15 /** Set CONFIG_TCCDIR at runtime */ 16 void tcc_set_lib_path(scope TCCState* s, scope const char* path) pure; 17 18 /** Set error/warning display callback */ 19 void tcc_set_error_func(scope TCCState* s, void* error_opaque, 20 void function(void* opaque, const char* msg) error_func) pure; 21 22 /** Set options as from command line (multiple supported) */ 23 int tcc_set_options(scope TCCState *s, scope const char *str) pure; 24 25 /*****************************/ 26 /** Preprocessor */ 27 28 /** Add include path */ 29 int tcc_add_include_path(scope TCCState* s, scope const char* pathname) pure; 30 31 /** Add const system include path */ 32 int tcc_add_sysinclude_path(scope TCCState* s, scope const char* pathname) pure; 33 34 /** Define preprocessor symbol 'sym'. Can put optional value */ 35 void tcc_define_symbol(scope TCCState* s, scope const char* sym, scope const char* value) pure; 36 37 /** Undefine preprocess symbol 'sym' */ 38 void tcc_undefine_symbol(scope TCCState* s, scope const char* sym) pure; 39 40 /*****************************/ 41 /** Compiling */ 42 43 /** Add a file (C file, dll, object, library, ld script). Return -1 if error. */ 44 int tcc_add_file(scope TCCState* s, scope const char* filename) pure; 45 46 /** Compile a string containing a C source. Return -1 if error. */ 47 int tcc_compile_string(scope TCCState* s, scope const char* buf) pure; 48 49 /*****************************/ 50 /** Linking commands */ 51 52 /** Set output type. MUST BE CALLED before any compilation */ 53 int tcc_set_output_type(scope TCCState* s, int output_type) pure; 54 55 enum { 56 TCC_OUTPUT_MEMORY = 0, /** Output will be run const memory (default) */ 57 TCC_OUTPUT_EXE = 1, /** Executable file */ 58 TCC_OUTPUT_DLL = 2, /** Dynamic library */ 59 TCC_OUTPUT_OBJ = 3, /** Object file */ 60 TCC_OUTPUT_PREPROCESS = 4, /** Only preprocess (used internally) */ 61 } 62 63 /** Equivalent to -Lpath option */ 64 int tcc_add_library_path(scope TCCState* s, scope const char* pathname) pure; 65 66 /** The library name is the same as the argument of the '-l' option */ 67 int tcc_add_library(scope TCCState* s, scope const char* libraryname) pure; 68 69 /** Add a symbol to the compiled program */ 70 int tcc_add_symbol(scope TCCState* s, scope const char* name, scope const void* val) pure; 71 72 /** Output an executable, library or object file. DO NOT call 73 tcc_relocate() before. */ 74 int tcc_output_file(scope TCCState* s, scope const char* filename); 75 76 /** Link and run main() function and return its value. DO NOT call 77 tcc_relocate() before. */ 78 int tcc_run(scope TCCState* s, int argc, char** argv); 79 80 81 /** Do all relocations (needed before using tcc_get_symbol()) */ 82 int tcc_relocate(scope TCCState* s1, void* ptr); 83 /** Possible values for 'ptr': 84 - TCC_RELOCATE_AUTO : Allocate and manage memory internally 85 - NULL : return required memory size for the step below 86 - memory address : copy code to memory passed by the caller 87 returns -1 if error. */ 88 enum TCC_RELOCATE_AUTO = cast(void*) 1; 89 90 /** Return symbol value or NULL if not found */ 91 void* tcc_get_symbol(scope TCCState* s, scope const char* name) pure;