Stop setting -Wno-unused-result switch in Makefile
[tinycc.git] / libtcc.h
blob791cd29dab5958fb3a5499bec505235b1e99f652
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 struct vio_module_t;
18 typedef struct vio_fd {
19 int fd;
20 void *vio_udata;
21 struct vio_module_t *vio_module;
22 } vio_fd;
24 #define CALL_VIO_OPEN_FIRST 0x01
25 #define CALL_VIO_OPEN_LAST 0x02
27 typedef struct vio_module_t {
28 void *user_data;
29 struct TCCState *tcc_state;
30 int call_vio_open_flags; /*CALL_VIO_OPEN_FIRST, CALL_VIO_OPEN_LAST, one or both */
31 int (*vio_open)(vio_fd *fd, const char *fn, int oflag) ;
32 off_t (*vio_lseek)(vio_fd fd, off_t offset, int whence);
33 size_t (*vio_read)(vio_fd fd, void *buf, size_t bytes);
34 int (*vio_close)(vio_fd *fd);
35 } vio_module_t;
38 /* create a new TCC compilation context */
39 LIBTCCAPI TCCState *tcc_new(void);
41 /* free a TCC compilation context */
42 LIBTCCAPI void tcc_delete(TCCState *s);
44 /* add debug information in the generated code */
45 LIBTCCAPI void tcc_enable_debug(TCCState *s);
47 /* set error/warning display callback */
48 LIBTCCAPI void tcc_set_error_func(TCCState *s, void *error_opaque,
49 void (*error_func)(void *opaque, const char *msg));
51 /* set/reset a warning */
52 LIBTCCAPI int tcc_set_warning(TCCState *s, const char *warning_name, int value);
54 /* set linker option */
55 LIBTCCAPI const char * tcc_set_linker(TCCState *s, char *option, int multi);
57 /* set virtual io module */
58 LIBTCCAPI void tcc_set_vio_module(TCCState *s, vio_module_t *vio_module);
60 /*****************************/
61 /* preprocessor */
63 /* add include path */
64 LIBTCCAPI int tcc_add_include_path(TCCState *s, const char *pathname);
66 /* add in system include path */
67 LIBTCCAPI int tcc_add_sysinclude_path(TCCState *s, const char *pathname);
69 /* define preprocessor symbol 'sym'. Can put optional value */
70 LIBTCCAPI void tcc_define_symbol(TCCState *s, const char *sym, const char *value);
72 /* undefine preprocess symbol 'sym' */
73 LIBTCCAPI void tcc_undefine_symbol(TCCState *s, const char *sym);
75 /*****************************/
76 /* compiling */
78 /* add a file (either a C file, dll, an object, a library or an ld
79 script). Return -1 if error. */
80 LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename);
82 /* compile a string containing a C source. Return non zero if
83 error. */
84 LIBTCCAPI int tcc_compile_string(TCCState *s, const char *buf);
86 /* compile a string containing a C source. Return non zero if
87 error. Can associate a name with string for errors. */
88 int tcc_compile_named_string(TCCState *s, const char *buf, const char *strname);
90 /*****************************/
91 /* linking commands */
93 /* set output type. MUST BE CALLED before any compilation */
94 #define TCC_OUTPUT_MEMORY 0 /* output will be ran in memory (no
95 output file) (default) */
96 #define TCC_OUTPUT_EXE 1 /* executable file */
97 #define TCC_OUTPUT_DLL 2 /* dynamic library */
98 #define TCC_OUTPUT_OBJ 3 /* object file */
99 #define TCC_OUTPUT_PREPROCESS 4 /* preprocessed file (used internally) */
100 LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type);
102 #define TCC_OUTPUT_FORMAT_ELF 0 /* default output format: ELF */
103 #define TCC_OUTPUT_FORMAT_BINARY 1 /* binary image output */
104 #define TCC_OUTPUT_FORMAT_COFF 2 /* COFF */
106 /* equivalent to -Lpath option */
107 LIBTCCAPI int tcc_add_library_path(TCCState *s, const char *pathname);
109 /* the library name is the same as the argument of the '-l' option */
110 LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname);
112 /* add a symbol to the compiled program */
113 LIBTCCAPI int tcc_add_symbol(TCCState *s, const char *name, const void *val);
115 /* output an executable, library or object file. DO NOT call
116 tcc_relocate() before. */
117 LIBTCCAPI int tcc_output_file(TCCState *s, const char *filename);
119 /* link and run main() function and return its value. DO NOT call
120 tcc_relocate() before. */
121 LIBTCCAPI int tcc_run(TCCState *s, int argc, char **argv);
123 /* do all relocations (needed before using tcc_get_symbol())
124 possible values for 'ptr':
125 - TCC_RELOCATE_AUTO : Allocate and manage memory internally
126 - NULL : return required memory size for the step below
127 - memory address : copy code to memory passed by the caller
128 returns -1 on error. */
129 LIBTCCAPI int tcc_relocate(TCCState *s1, void *ptr);
130 #define TCC_RELOCATE_AUTO (void*)1
132 /* return symbol value or NULL if not found */
133 LIBTCCAPI void *tcc_get_symbol(TCCState *s, const char *name);
135 /* set CONFIG_TCCDIR at runtime */
136 LIBTCCAPI void tcc_set_lib_path(TCCState *s, const char *path);
138 #ifdef __cplusplus
140 #endif
142 #endif