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