win32: malloc.h: fix win32 tcc-tcc complication by correcting _STATIC_ASSERT, ideas...
[tinycc.git] / libtcc.h
blob278dca3028a9292e9c35f1bae275ee81e5acba7a
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 struct TCCState;
14 typedef struct TCCState TCCState;
16 /* create a new TCC compilation context */
17 LIBTCCAPI TCCState *tcc_new(void);
19 /* free a TCC compilation context */
20 LIBTCCAPI void tcc_delete(TCCState *s);
22 /* add debug information in the generated code */
23 LIBTCCAPI void tcc_enable_debug(TCCState *s);
25 /* set error/warning display callback */
26 LIBTCCAPI void tcc_set_error_func(TCCState *s, void *error_opaque,
27 void (*error_func)(void *opaque, const char *msg));
29 /* set/reset a warning */
30 LIBTCCAPI int tcc_set_warning(TCCState *s, const char *warning_name, int value);
32 /* set linker option */
33 LIBTCCAPI const char * tcc_set_linker(TCCState *s, char *option, int multi);
35 /*****************************/
36 /* preprocessor */
38 /* add include path */
39 LIBTCCAPI int tcc_add_include_path(TCCState *s, const char *pathname);
41 /* add in system include path */
42 LIBTCCAPI int tcc_add_sysinclude_path(TCCState *s, const char *pathname);
44 /* define preprocessor symbol 'sym'. Can put optional value */
45 LIBTCCAPI void tcc_define_symbol(TCCState *s, const char *sym, const char *value);
47 /* undefine preprocess symbol 'sym' */
48 LIBTCCAPI void tcc_undefine_symbol(TCCState *s, const char *sym);
50 /*****************************/
51 /* compiling */
53 /* add a file (either a C file, dll, an object, a library or an ld
54 script). Return -1 if error. */
55 LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename);
57 /* compile a string containing a C source. Return non zero if
58 error. */
59 LIBTCCAPI int tcc_compile_string(TCCState *s, const char *buf);
61 /*****************************/
62 /* linking commands */
64 /* set output type. MUST BE CALLED before any compilation */
65 #define TCC_OUTPUT_MEMORY 0 /* output will be ran in memory (no
66 output file) (default) */
67 #define TCC_OUTPUT_EXE 1 /* executable file */
68 #define TCC_OUTPUT_DLL 2 /* dynamic library */
69 #define TCC_OUTPUT_OBJ 3 /* object file */
70 #define TCC_OUTPUT_PREPROCESS 4 /* preprocessed file (used internally) */
71 LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type);
73 #define TCC_OUTPUT_FORMAT_ELF 0 /* default output format: ELF */
74 #define TCC_OUTPUT_FORMAT_BINARY 1 /* binary image output */
75 #define TCC_OUTPUT_FORMAT_COFF 2 /* COFF */
77 /* equivalent to -Lpath option */
78 LIBTCCAPI int tcc_add_library_path(TCCState *s, const char *pathname);
80 /* the library name is the same as the argument of the '-l' option */
81 LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname);
83 /* add a symbol to the compiled program */
84 LIBTCCAPI int tcc_add_symbol(TCCState *s, const char *name, const void *val);
86 /* output an executable, library or object file. DO NOT call
87 tcc_relocate() before. */
88 LIBTCCAPI int tcc_output_file(TCCState *s, const char *filename);
90 /* link and run main() function and return its value. DO NOT call
91 tcc_relocate() before. */
92 LIBTCCAPI int tcc_run(TCCState *s, int argc, char **argv);
94 /* do all relocations (needed before using tcc_get_symbol())
95 possible values for 'ptr':
96 - TCC_RELOCATE_AUTO : Allocate and manage memory internally
97 - NULL : return required memory size for the step below
98 - memory address : copy code to memory passed by the caller
99 returns -1 on error. */
100 LIBTCCAPI int tcc_relocate(TCCState *s1, void *ptr);
101 #define TCC_RELOCATE_AUTO (void*)1
103 /* return symbol value or NULL if not found */
104 LIBTCCAPI void *tcc_get_symbol(TCCState *s, const char *name);
106 /* set CONFIG_TCCDIR at runtime */
107 LIBTCCAPI void tcc_set_lib_path(TCCState *s, const char *path);
109 #ifdef __cplusplus
111 #endif
113 #endif