- 所有 tcc 文件/内容/宏改名为 pcc (tcc.c->pcc.c, tccelf.c->pccelf.c, libtcc.c->libpcc.c 等) - 支持架构: i386, x86_64, ARM, ARM64, RISC-V, C67 - 支持格式: PE, ELF, Mach-O, COFF - 完整预处理、代码生成、链接器、调试信息 - 构建成功: pcc.exe (x86_64 Windows) - 功能测试通过: 递归/结构体/浮点/switch/循环 - 自编译测试通过: pcc 可以编译自身
117 行
4.1 KiB
C
117 行
4.1 KiB
C
#ifndef LIBPCC_H
|
|
#define LIBPCC_H
|
|
|
|
#ifndef LIBPCCAPI
|
|
# define LIBPCCAPI
|
|
#endif
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/*****************************/
|
|
/* set custom allocator for all allocations (optional), NULL for default. */
|
|
typedef void *TCCReallocFunc(void *ptr, unsigned long size);
|
|
LIBPCCAPI void pcc_set_realloc(TCCReallocFunc *my_realloc);
|
|
|
|
/*****************************/
|
|
typedef struct PCCState PCCState;
|
|
|
|
/* create a new PCC compilation context */
|
|
LIBPCCAPI PCCState *pcc_new(void);
|
|
|
|
/* free a PCC compilation context */
|
|
LIBPCCAPI void pcc_delete(PCCState *s);
|
|
|
|
/* set CONFIG_PCCDIR at runtime */
|
|
LIBPCCAPI void pcc_set_lib_path(PCCState *s, const char *path);
|
|
|
|
/* set error/warning callback (optional) */
|
|
typedef void TCCErrorFunc(void *opaque, const char *msg);
|
|
LIBPCCAPI void pcc_set_error_func(PCCState *s, void *error_opaque, TCCErrorFunc *error_func);
|
|
|
|
/* set options as from command line (multiple supported) */
|
|
LIBPCCAPI int pcc_set_options(PCCState *s, const char *str);
|
|
|
|
/*****************************/
|
|
/* preprocessor */
|
|
|
|
/* add include path */
|
|
LIBPCCAPI int pcc_add_include_path(PCCState *s, const char *pathname);
|
|
|
|
/* add in system include path */
|
|
LIBPCCAPI int pcc_add_sysinclude_path(PCCState *s, const char *pathname);
|
|
|
|
/* define preprocessor symbol 'sym'. value can be NULL, sym can be "sym=val" */
|
|
LIBPCCAPI void pcc_define_symbol(PCCState *s, const char *sym, const char *value);
|
|
|
|
/* undefine preprocess symbol 'sym' */
|
|
LIBPCCAPI void pcc_undefine_symbol(PCCState *s, const char *sym);
|
|
|
|
/*****************************/
|
|
/* compiling */
|
|
|
|
/* add a file (C file, dll, object, library, ld script). Return -1 if error. */
|
|
LIBPCCAPI int pcc_add_file(PCCState *s, const char *filename);
|
|
|
|
/* compile a string containing a C source. Return -1 if error. */
|
|
LIBPCCAPI int pcc_compile_string(PCCState *s, const char *buf);
|
|
|
|
/* Tip: to have more specific errors/warnings from pcc_compile_string(),
|
|
you can prefix the string with "#line <num> \"<filename>\"\n" */
|
|
|
|
/*****************************/
|
|
/* linking commands */
|
|
|
|
/* set output type. MUST BE CALLED before any compilation */
|
|
LIBPCCAPI int pcc_set_output_type(PCCState *s, int output_type);
|
|
#define PCC_OUTPUT_MEMORY 1 /* output will be run in memory */
|
|
#define PCC_OUTPUT_EXE 2 /* executable file */
|
|
#define PCC_OUTPUT_DLL 4 /* dynamic library */
|
|
#define PCC_OUTPUT_OBJ 3 /* object file */
|
|
#define PCC_OUTPUT_PREPROCESS 5 /* only preprocess */
|
|
|
|
/* equivalent to -Lpath option */
|
|
LIBPCCAPI int pcc_add_library_path(PCCState *s, const char *pathname);
|
|
|
|
/* the library name is the same as the argument of the '-l' option */
|
|
LIBPCCAPI int pcc_add_library(PCCState *s, const char *libraryname);
|
|
|
|
/* add a symbol to the compiled program */
|
|
LIBPCCAPI int pcc_add_symbol(PCCState *s, const char *name, const void *val);
|
|
|
|
/* output an executable, library or object file. DO NOT call
|
|
pcc_relocate() before. */
|
|
LIBPCCAPI int pcc_output_file(PCCState *s, const char *filename);
|
|
|
|
/* link and run main() function and return its value. DO NOT call
|
|
pcc_relocate() before. */
|
|
LIBPCCAPI int pcc_run(PCCState *s, int argc, char **argv);
|
|
|
|
/* do all relocations (needed before using pcc_get_symbol()) */
|
|
LIBPCCAPI int pcc_relocate(PCCState *s1);
|
|
|
|
/* return symbol value or NULL if not found */
|
|
LIBPCCAPI void *pcc_get_symbol(PCCState *s, const char *name);
|
|
|
|
/* list all (global) symbols and their values via 'symbol_cb()' */
|
|
LIBPCCAPI void pcc_list_symbols(PCCState *s, void *ctx,
|
|
void (*symbol_cb)(void *ctx, const char *name, const void *val));
|
|
|
|
/* experimental/advanced section (see libpcc_test_mt.c for an example) */
|
|
|
|
/* catch runtime exceptions (optionally limit backtraces at top_func),
|
|
when using pcc_set_options("-bt") and when not using pcc_run() */
|
|
LIBPCCAPI void *_pcc_setjmp(PCCState *s1, void *jmp_buf, void *top_func, void *longjmp);
|
|
#define pcc_setjmp(s1,jb,f) setjmp(_pcc_setjmp(s1, jb, f, longjmp))
|
|
|
|
/* custom error printer for runtime exceptions. Returning 0 stops backtrace */
|
|
typedef int TCCBtFunc(void *udata, void *pc, const char *file, int line, const char* func, const char *msg);
|
|
LIBPCCAPI void pcc_set_backtrace_func(PCCState *s1, void* userdata, TCCBtFunc*);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|