Better fix for old macho format
[tinycc.git] / libtcc.h
blob5ddfda9dfcd4918c0f3d8697c331ef0561f71daf
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 typedef void (*TCCErrorFunc)(void *opaque, const char *msg);
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 /* set CONFIG_TCCDIR at runtime */
25 LIBTCCAPI void tcc_set_lib_path(TCCState *s, const char *path);
27 /* set error/warning display callback */
28 LIBTCCAPI void tcc_set_error_func(TCCState *s, void *error_opaque, TCCErrorFunc error_func);
30 /* return error/warning callback */
31 LIBTCCAPI TCCErrorFunc tcc_get_error_func(TCCState *s);
33 /* return error/warning callback opaque pointer */
34 LIBTCCAPI void *tcc_get_error_opaque(TCCState *s);
36 /* set options as from command line (multiple supported) */
37 LIBTCCAPI void tcc_set_options(TCCState *s, const char *str);
39 /*****************************/
40 /* preprocessor */
42 /* add include path */
43 LIBTCCAPI int tcc_add_include_path(TCCState *s, const char *pathname);
45 /* add in system include path */
46 LIBTCCAPI int tcc_add_sysinclude_path(TCCState *s, const char *pathname);
48 /* define preprocessor symbol 'sym'. value can be NULL, sym can be "sym=val" */
49 LIBTCCAPI void tcc_define_symbol(TCCState *s, const char *sym, const char *value);
51 /* undefine preprocess symbol 'sym' */
52 LIBTCCAPI void tcc_undefine_symbol(TCCState *s, const char *sym);
54 /*****************************/
55 /* compiling */
57 /* add a file (C file, dll, object, library, ld script). Return -1 if error. */
58 LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename);
60 /* compile a string containing a C source. Return -1 if 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 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, void *ptr);
93 /* possible values for 'ptr':
94 - TCC_RELOCATE_AUTO : Allocate and manage memory internally
95 - NULL : return required memory size for the step below
96 - memory address : copy code to memory passed by the caller
97 returns -1 if error. */
98 #define TCC_RELOCATE_AUTO (void*)1
100 /* return symbol value or NULL if not found */
101 LIBTCCAPI void *tcc_get_symbol(TCCState *s, const char *name);
103 /* return symbol value or NULL if not found */
104 LIBTCCAPI void tcc_list_symbols(TCCState *s, void *ctx,
105 void (*symbol_cb)(void *ctx, const char *name, const void *val));
107 #ifdef __cplusplus
109 #endif
111 #endif