Adding two more people to the RELICENSING file.
[tinycc.git] / libtcc.h
Commit [+]AuthorDateLineData
1e14c90c bellard2002-05-13 22:58:22 +00001#ifndef LIBTCC_H
2#define LIBTCC_H
3
74a24d77 grischka2011-08-11 16:55:30 +02004#ifndef LIBTCCAPI
5# define LIBTCCAPI
b56f9562 grischka2009-04-18 13:17:38 +02006#endif
7
356fa0c3 bellard2003-04-26 20:51:42 +00008#ifdef __cplusplus
9extern "C" {
10#endif
11
1e14c90c bellard2002-05-13 22:58:22 +000012struct TCCState;
13
14typedef struct TCCState TCCState;
15
16/* create a new TCC compilation context */
b56f9562 grischka2009-04-18 13:17:38 +020017LIBTCCAPI TCCState *tcc_new(void);
1e14c90c bellard2002-05-13 22:58:22 +000018
19/* free a TCC compilation context */
b56f9562 grischka2009-04-18 13:17:38 +020020LIBTCCAPI void tcc_delete(TCCState *s);
1e14c90c bellard2002-05-13 22:58:22 +000021
05108a3b grischka2013-02-12 19:13:28 +010022/* set CONFIG_TCCDIR at runtime */
23LIBTCCAPI void tcc_set_lib_path(TCCState *s, const char *path);
1e14c90c bellard2002-05-13 22:58:22 +000024
05a919e2 bellard2002-11-02 14:14:08 +000025/* set error/warning display callback */
b56f9562 grischka2009-04-18 13:17:38 +020026LIBTCCAPI void tcc_set_error_func(TCCState *s, void *error_opaque,
05108a3b grischka2013-02-12 19:13:28 +010027 void (*error_func)(void *opaque, const char *msg));
356fa0c3 bellard2003-04-26 20:51:42 +000028
05108a3b grischka2013-02-12 19:13:28 +010029/* set options as from command line (multiple supported) */
30LIBTCCAPI int tcc_set_options(TCCState *s, const char *str);
78e83d87 Detlef Riekenberg2010-04-05 21:21:58 +020031
1e14c90c bellard2002-05-13 22:58:22 +000032/*****************************/
33/* preprocessor */
34
35/* add include path */
b56f9562 grischka2009-04-18 13:17:38 +020036LIBTCCAPI int tcc_add_include_path(TCCState *s, const char *pathname);
1e14c90c bellard2002-05-13 22:58:22 +000037
f5b9220b bellard2002-08-18 13:24:03 +000038/* add in system include path */
b56f9562 grischka2009-04-18 13:17:38 +020039LIBTCCAPI int tcc_add_sysinclude_path(TCCState *s, const char *pathname);
f5b9220b bellard2002-08-18 13:24:03 +000040
1e14c90c bellard2002-05-13 22:58:22 +000041/* define preprocessor symbol 'sym'. Can put optional value */
b56f9562 grischka2009-04-18 13:17:38 +020042LIBTCCAPI void tcc_define_symbol(TCCState *s, const char *sym, const char *value);
1e14c90c bellard2002-05-13 22:58:22 +000043
44/* undefine preprocess symbol 'sym' */
b56f9562 grischka2009-04-18 13:17:38 +020045LIBTCCAPI void tcc_undefine_symbol(TCCState *s, const char *sym);
1e14c90c bellard2002-05-13 22:58:22 +000046
47/*****************************/
48/* compiling */
49
05108a3b grischka2013-02-12 19:13:28 +010050/* add a file (C file, dll, object, library, ld script). Return -1 if error. */
05364072 seyko2015-04-12 15:35:37 +030051LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename, int filetype);
52#define TCC_FILETYPE_BINARY 1
53#define TCC_FILETYPE_C 2
54#define TCC_FILETYPE_ASM 3
55#define TCC_FILETYPE_ASM_PP 4
1e14c90c bellard2002-05-13 22:58:22 +000056
05108a3b grischka2013-02-12 19:13:28 +010057/* compile a string containing a C source. Return -1 if error. */
b56f9562 grischka2009-04-18 13:17:38 +020058LIBTCCAPI int tcc_compile_string(TCCState *s, const char *buf);
1e14c90c bellard2002-05-13 22:58:22 +000059
1e14c90c bellard2002-05-13 22:58:22 +000060/*****************************/
61/* linking commands */
62
f5b9220b bellard2002-08-18 13:24:03 +000063/* set output type. MUST BE CALLED before any compilation */
05108a3b grischka2013-02-12 19:13:28 +010064LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type);
c334b591 seyko2015-01-06 22:19:45 +030065#define TCC_OUTPUT_MEMORY 1 /* output will be run in memory (default) */
66#define TCC_OUTPUT_EXE 2 /* executable file */
67#define TCC_OUTPUT_DLL 3 /* dynamic library */
68#define TCC_OUTPUT_OBJ 4 /* object file */
69#define TCC_OUTPUT_PREPROCESS 5 /* only preprocess (used internally) */
45466d2d bellard2004-10-23 22:49:08 +000070
b2834b35 bellard2002-07-24 22:12:38 +000071/* equivalent to -Lpath option */
b56f9562 grischka2009-04-18 13:17:38 +020072LIBTCCAPI int tcc_add_library_path(TCCState *s, const char *pathname);
1e14c90c bellard2002-05-13 22:58:22 +000073
b2834b35 bellard2002-07-24 22:12:38 +000074/* the library name is the same as the argument of the '-l' option */
b56f9562 grischka2009-04-18 13:17:38 +020075LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname);
b2834b35 bellard2002-07-24 22:12:38 +000076
77/* add a symbol to the compiled program */
52991422 grischka2010-01-14 20:56:04 +010078LIBTCCAPI int tcc_add_symbol(TCCState *s, const char *name, const void *val);
1e14c90c bellard2002-05-13 22:58:22 +000079
05a919e2 bellard2002-11-02 14:14:08 +000080/* output an executable, library or object file. DO NOT call
81 tcc_relocate() before. */
b56f9562 grischka2009-04-18 13:17:38 +020082LIBTCCAPI int tcc_output_file(TCCState *s, const char *filename);
1e14c90c bellard2002-05-13 22:58:22 +000083
05a919e2 bellard2002-11-02 14:14:08 +000084/* link and run main() function and return its value. DO NOT call
85 tcc_relocate() before. */
b56f9562 grischka2009-04-18 13:17:38 +020086LIBTCCAPI int tcc_run(TCCState *s, int argc, char **argv);
1e14c90c bellard2002-05-13 22:58:22 +000087
05108a3b grischka2013-02-12 19:13:28 +010088/* do all relocations (needed before using tcc_get_symbol()) */
89LIBTCCAPI int tcc_relocate(TCCState *s1, void *ptr);
90/* possible values for 'ptr':
ca38792d grischka2012-09-01 11:33:34 +020091 - TCC_RELOCATE_AUTO : Allocate and manage memory internally
92 - NULL : return required memory size for the step below
93 - memory address : copy code to memory passed by the caller
05108a3b grischka2013-02-12 19:13:28 +010094 returns -1 if error. */
ca38792d grischka2012-09-01 11:33:34 +020095#define TCC_RELOCATE_AUTO (void*)1
d8ef07df bellard2002-09-08 22:46:32 +000096
b1697be6 grischka2009-04-16 21:50:43 +020097/* return symbol value or NULL if not found */
b56f9562 grischka2009-04-18 13:17:38 +020098LIBTCCAPI void *tcc_get_symbol(TCCState *s, const char *name);
d8ef07df bellard2002-09-08 22:46:32 +000099
356fa0c3 bellard2003-04-26 20:51:42 +0000100#ifdef __cplusplus
101}
102#endif
103
1e14c90c bellard2002-05-13 22:58:22 +0000104#endif