re-apply VLA by Thomas Preud'homme
[tinycc.git] / libtcc.h
blobbf328d37574b8a8e76acd2ed8dbe853cf0834086
1 #ifndef LIBTCC_H
2 #define LIBTCC_H
4 #ifdef LIBTCC_AS_DLL
5 #define LIBTCCAPI __declspec(dllexport)
6 #else
7 #define LIBTCCAPI
8 #endif
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
14 struct TCCState;
16 typedef struct TCCState TCCState;
18 /* create a new TCC compilation context */
19 LIBTCCAPI TCCState *tcc_new(void);
21 /* free a TCC compilation context */
22 LIBTCCAPI void tcc_delete(TCCState *s);
24 /* add debug information in the generated code */
25 LIBTCCAPI void tcc_enable_debug(TCCState *s);
27 /* set error/warning display callback */
28 LIBTCCAPI void tcc_set_error_func(TCCState *s, void *error_opaque,
29 void (*error_func)(void *opaque, const char *msg));
31 /* set/reset a warning */
32 LIBTCCAPI int tcc_set_warning(TCCState *s, const char *warning_name, int value);
34 /* set linker option */
35 LIBTCCAPI const char * tcc_set_linker(TCCState *s, char *option, int multi);
37 /*****************************/
38 /* preprocessor */
40 /* add include path */
41 LIBTCCAPI int tcc_add_include_path(TCCState *s, const char *pathname);
43 /* add in system include path */
44 LIBTCCAPI int tcc_add_sysinclude_path(TCCState *s, const char *pathname);
46 /* define preprocessor symbol 'sym'. Can put optional value */
47 LIBTCCAPI void tcc_define_symbol(TCCState *s, const char *sym, const char *value);
49 /* undefine preprocess symbol 'sym' */
50 LIBTCCAPI void tcc_undefine_symbol(TCCState *s, const char *sym);
52 /*****************************/
53 /* compiling */
55 /* add a file (either a C file, dll, an object, a library or an ld
56 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 non zero if
60 error. */
61 LIBTCCAPI int tcc_compile_string(TCCState *s, const char *buf);
63 /*****************************/
64 /* linking commands */
66 /* set output type. MUST BE CALLED before any compilation */
67 #define TCC_OUTPUT_MEMORY 0 /* output will be ran in memory (no
68 output file) (default) */
69 #define TCC_OUTPUT_EXE 1 /* executable file */
70 #define TCC_OUTPUT_DLL 2 /* dynamic library */
71 #define TCC_OUTPUT_OBJ 3 /* object file */
72 #define TCC_OUTPUT_PREPROCESS 4 /* preprocessed file (used internally) */
73 LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type);
75 #define TCC_OUTPUT_FORMAT_ELF 0 /* default output format: ELF */
76 #define TCC_OUTPUT_FORMAT_BINARY 1 /* binary image output */
77 #define TCC_OUTPUT_FORMAT_COFF 2 /* COFF */
79 /* equivalent to -Lpath option */
80 LIBTCCAPI int tcc_add_library_path(TCCState *s, const char *pathname);
82 /* the library name is the same as the argument of the '-l' option */
83 LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname);
85 /* add a symbol to the compiled program */
86 LIBTCCAPI int tcc_add_symbol(TCCState *s, const char *name, const void *val);
88 /* output an executable, library or object file. DO NOT call
89 tcc_relocate() before. */
90 LIBTCCAPI int tcc_output_file(TCCState *s, const char *filename);
92 /* link and run main() function and return its value. DO NOT call
93 tcc_relocate() before. */
94 LIBTCCAPI int tcc_run(TCCState *s, int argc, char **argv);
96 /* Do all relocations (needed before using tcc_get_symbol())
97 Returns -1 on error. */
98 LIBTCCAPI int tcc_relocate(TCCState *s1);
100 /* return symbol value or NULL if not found */
101 LIBTCCAPI void *tcc_get_symbol(TCCState *s, const char *name);
103 /* set CONFIG_TCCDIR at runtime */
104 LIBTCCAPI void tcc_set_lib_path(TCCState *s, const char *path);
107 /*****************************/
108 /* Miscellaneous */
110 /* Get default target filename for this compilation */
111 LIBTCCAPI const char *tcc_default_target(TCCState *s);
113 /* Generate make dependencies for target and store them into file
115 * !target - use default target name
116 * !filename - use (target.o -> target.d)
118 LIBTCCAPI void tcc_gen_makedeps(TCCState *s, const char *target, const char *filename);
120 #ifdef __cplusplus
122 #endif
124 #endif