fixup! riscv: Implement large addend for global address
[tinycc.git] / libtcc.h
blob5949c807b3857752c5c60ab60c4a08cc83a5fe7b
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), NULL for default. */
14 typedef void *TCCReallocFunc(void *ptr, unsigned long size);
15 LIBTCCAPI void tcc_set_realloc(TCCReallocFunc *my_realloc);
17 /*****************************/
18 typedef struct TCCState TCCState;
20 /* create a new TCC compilation context */
21 LIBTCCAPI TCCState *tcc_new(void);
23 /* free a TCC compilation context */
24 LIBTCCAPI void tcc_delete(TCCState *s);
26 /* set CONFIG_TCCDIR at runtime */
27 LIBTCCAPI void tcc_set_lib_path(TCCState *s, const char *path);
29 /* set error/warning callback (optional) */
30 typedef void TCCErrorFunc(void *opaque, const char *msg);
31 LIBTCCAPI void tcc_set_error_func(TCCState *s, void *error_opaque, TCCErrorFunc *error_func);
33 /* set options as from command line (multiple supported) */
34 LIBTCCAPI int tcc_set_options(TCCState *s, const char *str);
36 /*****************************/
37 /* preprocessor */
39 /* add include path */
40 LIBTCCAPI int tcc_add_include_path(TCCState *s, const char *pathname);
42 /* add in system include path */
43 LIBTCCAPI int tcc_add_sysinclude_path(TCCState *s, const char *pathname);
45 /* define preprocessor symbol 'sym'. value can be NULL, sym can be "sym=val" */
46 LIBTCCAPI void tcc_define_symbol(TCCState *s, const char *sym, const char *value);
48 /* undefine preprocess symbol 'sym' */
49 LIBTCCAPI void tcc_undefine_symbol(TCCState *s, const char *sym);
51 /*****************************/
52 /* compiling */
54 /* add a file (C file, dll, object, library, ld 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 -1 if error. */
58 LIBTCCAPI int tcc_compile_string(TCCState *s, const char *buf);
60 /* Tip: to have more specific errors/warnings from tcc_compile_string(),
61 you can prefix the string with "#line <num> \"<filename>\"\n" */
63 /*****************************/
64 /* linking commands */
66 /* set output type. MUST BE CALLED before any compilation */
67 LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type);
68 #define TCC_OUTPUT_MEMORY 1 /* output will be run in memory */
69 #define TCC_OUTPUT_EXE 2 /* executable file */
70 #define TCC_OUTPUT_DLL 4 /* dynamic library */
71 #define TCC_OUTPUT_OBJ 3 /* object file */
72 #define TCC_OUTPUT_PREPROCESS 5 /* only preprocess */
74 /* equivalent to -Lpath option */
75 LIBTCCAPI int tcc_add_library_path(TCCState *s, const char *pathname);
77 /* the library name is the same as the argument of the '-l' option */
78 LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname);
80 /* add a symbol to the compiled program */
81 LIBTCCAPI int tcc_add_symbol(TCCState *s, const char *name, const void *val);
83 /* output an executable, library or object file. DO NOT call
84 tcc_relocate() before. */
85 LIBTCCAPI int tcc_output_file(TCCState *s, const char *filename);
87 /* link and run main() function and return its value. DO NOT call
88 tcc_relocate() before. */
89 LIBTCCAPI int tcc_run(TCCState *s, int argc, char **argv);
91 /* do all relocations (needed before using tcc_get_symbol()) */
92 LIBTCCAPI int tcc_relocate(TCCState *s1);
94 /* return symbol value or NULL if not found */
95 LIBTCCAPI void *tcc_get_symbol(TCCState *s, const char *name);
97 /* list all (global) symbols and their values via 'symbol_cb()' */
98 LIBTCCAPI void tcc_list_symbols(TCCState *s, void *ctx,
99 void (*symbol_cb)(void *ctx, const char *name, const void *val));
101 /* experimental/advanced section (see libtcc_test_mt.c for an example) */
103 /* catch runtime exceptions (optionally limit backtraces at top_func),
104 when using tcc_set_options("-bt") and when not using tcc_run() */
105 LIBTCCAPI void *_tcc_setjmp(TCCState *s1, void *jmp_buf, void *top_func, void *longjmp);
106 #define tcc_setjmp(s1,jb,f) setjmp(_tcc_setjmp(s1, jb, f, longjmp))
108 /* custom error printer for runtime exceptions. Returning 0 stops backtrace */
109 typedef int TCCBtFunc(void *udata, void *pc, const char *file, int line, const char* func, const char *msg);
110 LIBTCCAPI void tcc_set_backtrace_func(TCCState *s1, void* userdata, TCCBtFunc*);
112 #ifdef __cplusplus
114 #endif
116 #endif