LIBTCCAPI tcc_relocate(s) : REMOVED 2nd argument
[tinycc.git] / libtcc.h
blob205ed15480714ed438633cf08816fbf89fd4d9c5
1 #ifndef LIBTCC_H
2 #define LIBTCC_H
4 #ifndef LIBTCCAPI
5 # define LIBTCCAPI
6 #endif
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
12 /*****************************/
13 /* set custom allocator for all allocations (optional) */
15 typedef void *TCCReallocFunc(void *ptr, unsigned long size);
16 LIBTCCAPI void tcc_set_realloc(TCCReallocFunc *my_realloc);
18 /*****************************/
20 typedef struct TCCState TCCState;
22 /* create a new TCC compilation context */
23 LIBTCCAPI TCCState *tcc_new(void);
25 /* free a TCC compilation context */
26 LIBTCCAPI void tcc_delete(TCCState *s);
28 /* set CONFIG_TCCDIR at runtime */
29 LIBTCCAPI void tcc_set_lib_path(TCCState *s, const char *path);
31 /* set error/warning callback (optional) */
32 typedef void TCCErrorFunc(void *opaque, const char *msg);
33 LIBTCCAPI void tcc_set_error_func(TCCState *s, void *error_opaque, TCCErrorFunc *error_func);
35 /* set options as from command line (multiple supported) */
36 LIBTCCAPI int tcc_set_options(TCCState *s, const char *str);
38 /*****************************/
39 /* preprocessor */
41 /* add include path */
42 LIBTCCAPI int tcc_add_include_path(TCCState *s, const char *pathname);
44 /* add in system include path */
45 LIBTCCAPI int tcc_add_sysinclude_path(TCCState *s, const char *pathname);
47 /* define preprocessor symbol 'sym'. value can be NULL, sym can be "sym=val" */
48 LIBTCCAPI void tcc_define_symbol(TCCState *s, const char *sym, const char *value);
50 /* undefine preprocess symbol 'sym' */
51 LIBTCCAPI void tcc_undefine_symbol(TCCState *s, const char *sym);
53 /*****************************/
54 /* compiling */
56 /* add a file (C file, dll, object, library, ld script). Return -1 if error. */
57 LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename);
59 /* compile a string containing a C source. Return -1 if error. */
60 LIBTCCAPI int tcc_compile_string(TCCState *s, const char *buf);
62 /* Tip: to have more specific errors/warnings from tcc_compile_string(),
63 you can prefix the string with "#line <num> \"<filename>\"\n" */
65 /*****************************/
66 /* linking commands */
68 /* set output type. MUST BE CALLED before any compilation */
69 LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type);
70 #define TCC_OUTPUT_MEMORY 1 /* output will be run in memory */
71 #define TCC_OUTPUT_EXE 2 /* executable file */
72 #define TCC_OUTPUT_DLL 4 /* dynamic library */
73 #define TCC_OUTPUT_OBJ 3 /* object file */
74 #define TCC_OUTPUT_PREPROCESS 5 /* only preprocess */
76 /* equivalent to -Lpath option */
77 LIBTCCAPI int tcc_add_library_path(TCCState *s, const char *pathname);
79 /* the library name is the same as the argument of the '-l' option */
80 LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname);
82 /* add a symbol to the compiled program */
83 LIBTCCAPI int tcc_add_symbol(TCCState *s, const char *name, const void *val);
85 /* output an executable, library or object file. DO NOT call
86 tcc_relocate() before. */
87 LIBTCCAPI int tcc_output_file(TCCState *s, const char *filename);
89 /* link and run main() function and return its value. DO NOT call
90 tcc_relocate() before. */
91 LIBTCCAPI int tcc_run(TCCState *s, int argc, char **argv);
93 /* do all relocations (needed before using tcc_get_symbol()) */
94 LIBTCCAPI int tcc_relocate(TCCState *s1);
96 /* return symbol value or NULL if not found */
97 LIBTCCAPI void *tcc_get_symbol(TCCState *s, const char *name);
99 /* list all (global) symbols and their values via 'symbol_cb()' */
100 LIBTCCAPI void tcc_list_symbols(TCCState *s, void *ctx,
101 void (*symbol_cb)(void *ctx, const char *name, const void *val));
103 #ifdef __cplusplus
105 #endif
107 #endif