added better error support
[tinycc.git] / libtcc.h
blob0fe2c0f163c953c8ab74c26556790dd4af756ec3
1 #ifndef LIBTCC_H
2 #define LIBTCC_H
4 struct TCCState;
6 typedef struct TCCState TCCState;
8 /* create a new TCC compilation context */
9 TCCState *tcc_new(void);
11 /* free a TCC compilation context */
12 void tcc_delete(TCCState *s);
14 /* add debug information in the generated code */
15 void tcc_enable_debug(TCCState *s);
17 /* set error/warning display callback */
18 void tcc_set_error_func(TCCState *s, void *error_opaque,
19 void (*error_func)(void *opaque, const char *msg));
21 /*****************************/
22 /* preprocessor */
24 /* add include path */
25 int tcc_add_include_path(TCCState *s, const char *pathname);
27 /* add in system include path */
28 int tcc_add_sysinclude_path(TCCState *s, const char *pathname);
30 /* define preprocessor symbol 'sym'. Can put optional value */
31 void tcc_define_symbol(TCCState *s, const char *sym, const char *value);
33 /* undefine preprocess symbol 'sym' */
34 void tcc_undefine_symbol(TCCState *s, const char *sym);
36 /*****************************/
37 /* compiling */
39 /* add a file (either a C file, dll, an object, a library or an ld
40 script). Return -1 if error. */
41 int tcc_add_file(TCCState *s, const char *filename);
43 /* compile a string containing a C source. Return non zero if
44 error. */
45 int tcc_compile_string(TCCState *s, const char *buf);
47 /*****************************/
48 /* linking commands */
50 /* set output type. MUST BE CALLED before any compilation */
51 #define TCC_OUTPUT_MEMORY 0 /* output will be ran in memory (no
52 output file) (default) */
53 #define TCC_OUTPUT_EXE 1 /* executable file */
54 #define TCC_OUTPUT_DLL 2 /* dynamic library */
55 #define TCC_OUTPUT_OBJ 3 /* object file */
56 int tcc_set_output_type(TCCState *s, int output_type);
58 /* equivalent to -Lpath option */
59 int tcc_add_library_path(TCCState *s, const char *pathname);
61 /* the library name is the same as the argument of the '-l' option */
62 int tcc_add_library(TCCState *s, const char *libraryname);
64 /* add a symbol to the compiled program */
65 int tcc_add_symbol(TCCState *s, const char *name, unsigned long val);
67 /* output an executable, library or object file. DO NOT call
68 tcc_relocate() before. */
69 int tcc_output_file(TCCState *s, const char *filename);
71 /* link and run main() function and return its value. DO NOT call
72 tcc_relocate() before. */
73 int tcc_run(TCCState *s, int argc, char **argv);
75 /* do all relocations (needed before using tcc_get_symbol()). Return
76 non zero if link error. */
77 int tcc_relocate(TCCState *s);
79 /* return symbol value or error */
80 void *tcc_get_symbol(TCCState *s, const char *name);
82 #endif