From 1b192b23bf0c87aa8874c9087c8087f57042677b Mon Sep 17 00:00:00 2001 From: k1w1 Date: Fri, 4 Dec 2009 16:48:43 -0800 Subject: [PATCH] Checkpoint. More refactoring. --- i386-asm.c | 20 ++-- i386-gen.c | 28 +----- i386-gen.h | 54 +++++++++++ libtcc.c | 238 +---------------------------------------------- tcc.h | 30 +++--- tccasm.c | 20 +++- tccasm.h | 2 + tcccstring.c | 11 --- tccsym.h => tcccstring.h | 39 +++++--- tccgen.c | 11 ++- tccgen.h | 4 +- tccpp.c | 78 ++++------------ tccpp.h | 64 ++++++++++++- tccsym.c | 69 ++++++++++++-- tccsym.h | 29 +++++- 15 files changed, 304 insertions(+), 393 deletions(-) copy tccsym.h => tcccstring.h (53%) diff --git a/i386-asm.c b/i386-asm.c index 649b6f31..68a731a2 100755 --- a/i386-asm.c +++ b/i386-asm.c @@ -18,6 +18,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "tcc.h" +#include "i386-asm-config.h" #define MAX_OPERANDS 3 @@ -343,14 +344,14 @@ static void parse_operand(TCCState *s1, Operand *op) op->type |= indir; } -static void gen_le16(int v) +void gen_le16(int v) { g(v); g(v >> 8); } /* XXX: unify with C code output ? */ -static void gen_expr32(ExprValue *pe) +void gen_expr32(ExprValue *pe) { if (pe->sym) greloc(cur_text_section, pe->sym, ind, R_386_32); @@ -501,7 +502,7 @@ static inline void asm_modrm(int reg, Operand *op) } } -static void asm_opcode(TCCState *s1, int opcode) +void asm_opcode(TCCState *s1, int opcode) { const ASMInstr *pa; int i, modrm_index, reg, v, op1, is_short_jmp, seg_prefix; @@ -867,9 +868,6 @@ static void asm_opcode(TCCState *s1, int opcode) } } -#define NB_SAVED_REGS 3 -#define NB_ASM_REGS 8 - /* return the constraint priority (we allocate first the lowest numbered constraints) */ static inline int constraint_priority(const char *str) @@ -931,8 +929,8 @@ static const char *skip_constraint_modifiers(const char *p) #define is_reg_allocated(reg) (regs_allocated[reg] & reg_mask) -static void asm_compute_constraints(ASMOperand *operands, - int nb_operands, int nb_outputs, +void asm_compute_constraints(ASMOperand *operands, + int nb_operands, int nb_outputs, const uint8_t *clobber_regs, int *pout_reg) { @@ -1163,7 +1161,7 @@ static void asm_compute_constraints(ASMOperand *operands, #endif } -static void subst_asm_operand(CString *add_str, +void subst_asm_operand(CString *add_str, SValue *sv, int modifier) { int r, reg, size, val; @@ -1244,7 +1242,7 @@ static void subst_asm_operand(CString *add_str, } /* generate prolog and epilog code for asm statment */ -static void asm_gen_code(ASMOperand *operands, int nb_operands, +static void asm_gen_code(ASMOperand *operands, int nb_operands, int nb_outputs, int is_output, uint8_t *clobber_regs, int out_reg) @@ -1334,7 +1332,7 @@ static void asm_gen_code(ASMOperand *operands, int nb_operands, } } -static void asm_clobber(uint8_t *clobber_regs, const char *str) +void asm_clobber(uint8_t *clobber_regs, const char *str) { int reg; TokenSym *ts; diff --git a/i386-gen.c b/i386-gen.c index 5d2e7c70..8186e3fa 100755 --- a/i386-gen.c +++ b/i386-gen.c @@ -20,32 +20,6 @@ #include "tcc.h" -/* pretty names for the registers */ -enum { - TREG_EAX = 0, - TREG_ECX, - TREG_EDX, - TREG_ST0, -}; - -const int reg_classes[NB_REGS] = { - /* eax */ RC_INT | RC_EAX, - /* ecx */ RC_INT | RC_ECX, - /* edx */ RC_INT | RC_EDX, - /* st0 */ RC_FLOAT | RC_ST0, -}; - -/* return registers for function */ -#define REG_IRET TREG_EAX /* single word int return register */ -#define REG_LRET TREG_EDX /* second word return register (for long long) */ -#define REG_FRET TREG_ST0 /* float return register */ - -/* defined if function parameters must be evaluated in reverse order */ -#define INVERT_FUNC_PARAMS - -/* defined if structures are passed as pointers. Otherwise structures - are directly pushed on stack. */ -//#define FUNC_STRUCT_PARAM_AS_PTR /******************************************************/ @@ -102,7 +76,7 @@ void gsym(int t) #define psym oad /* instruction + 4 bytes data. Return the address of the data */ -static int oad(int c, int s) +int oad(int c, int s) { int ind1; diff --git a/i386-gen.h b/i386-gen.h index ab7c4a4b..187c4028 100755 --- a/i386-gen.h +++ b/i386-gen.h @@ -58,4 +58,58 @@ #define ELF_START_ADDR 0x08048000 +/* pretty names for the registers */ +enum { + TREG_EAX = 0, + TREG_ECX, + TREG_EDX, + TREG_ST0, +}; + +const int reg_classes[NB_REGS] = { + /* eax */ RC_INT | RC_EAX, + /* ecx */ RC_INT | RC_ECX, + /* edx */ RC_INT | RC_EDX, + /* st0 */ RC_FLOAT | RC_ST0, +}; + +/* return registers for function */ +#define REG_IRET TREG_EAX /* single word int return register */ +#define REG_LRET TREG_EDX /* second word return register (for long long) */ +#define REG_FRET TREG_ST0 /* float return register */ + +/* defined if function parameters must be evaluated in reverse order */ +#define INVERT_FUNC_PARAMS + +/* defined if structures are passed as pointers. Otherwise structures + are directly pushed on stack. */ +//#define FUNC_STRUCT_PARAM_AS_PTR + +void g(int c); +void o(unsigned int c); +void gen_le32(int c); +void store(int r, SValue *v); +void load(int r, SValue *sv); +void gsym(int t); +void gfunc_call(int nb_args); +void gen_opi(int op); +void gen_opf(int op); +void gen_cvt_itof(int t); +void gen_cvt_ftoi(int t); +int gjmp(int t); +void gjmp_addr(int a); +void gsym_addr(int t, int a); +void ggoto(void); +void gfunc_prolog(CType *func_type); +int gtst(int inv, int t); +void gfunc_epilog(void); +void gen_cvt_ftof(int t); + +/* psym is used to put an instruction with a data field which is a + reference to a symbol. It is in fact the same as oad ! */ +#define psym oad + +/* instruction + 4 bytes data. Return the address of the data */ +int oad(int c, int s); + #endif /* __I386_GEN_H__ */ diff --git a/libtcc.c b/libtcc.c index daf42865..c808e39e 100755 --- a/libtcc.c +++ b/libtcc.c @@ -117,12 +117,6 @@ unsigned long rt_prog_main; struct TCCState *tcc_state; /********************************************************/ -/* function prototypes */ - -static void asm_instr(void); -static void asm_global_instr(void); - -/********************************************************/ #ifdef TCC_TARGET_I386 //#include "i386-gen.c" @@ -153,11 +147,11 @@ static void asm_global_instr(void); //#include "tccasm.c" #else -static void asm_instr(void) +void asm_instr(void) { error("inline asm() not supported"); } -static void asm_global_instr(void) +void asm_global_instr(void) { error("inline asm() not supported"); } @@ -201,238 +195,10 @@ BOOL WINAPI DllMain (HANDLE hDll, DWORD dwReason, LPVOID lpReserved) #endif /********************************************************/ -#ifdef CONFIG_TCC_STATIC - -#define RTLD_LAZY 0x001 -#define RTLD_NOW 0x002 -#define RTLD_GLOBAL 0x100 -#define RTLD_DEFAULT NULL - -/* dummy function for profiling */ -void *dlopen(const char *filename, int flag) -{ - return NULL; -} - -void dlclose(void *p) -{ -} - -const char *dlerror(void) -{ - return "error"; -} - -typedef struct TCCSyms { - char *str; - void *ptr; -} TCCSyms; - -#define TCCSYM(a) { #a, &a, }, - -/* add the symbol you want here if no dynamic linking is done */ -static TCCSyms tcc_syms[] = { -#if !defined(CONFIG_TCCBOOT) - TCCSYM(printf) - TCCSYM(fprintf) - TCCSYM(fopen) - TCCSYM(fclose) -#endif - { NULL, NULL }, -}; - -void *resolve_sym(TCCState *s1, const char *symbol) -{ - TCCSyms *p; - p = tcc_syms; - while (p->str != NULL) { - if (!strcmp(p->str, symbol)) - return p->ptr; - p++; - } - return NULL; -} - -#elif defined(_WIN32) -#define dlclose FreeLibrary - -#else -#include - -void *resolve_sym(TCCState *s1, const char *sym) -{ - return dlsym(RTLD_DEFAULT, sym); -} - -#endif - /********************************************************/ -/* we use our own 'finite' function to avoid potential problems with - non standard math libs */ -/* XXX: endianness dependent */ -int ieee_finite(double d) -{ - int *p = (int *)&d; - return ((unsigned)((p[1] | 0x800fffff) + 1)) >> 31; -} -/* copy a string and truncate it. */ -char *pstrcpy(char *buf, int buf_size, const char *s) -{ - char *q, *q_end; - int c; - - if (buf_size > 0) { - q = buf; - q_end = buf + buf_size - 1; - while (q < q_end) { - c = *s++; - if (c == '\0') - break; - *q++ = c; - } - *q = '\0'; - } - return buf; -} - -/* strcat and truncate. */ -char *pstrcat(char *buf, int buf_size, const char *s) -{ - int len; - len = strlen(buf); - if (len < buf_size) - pstrcpy(buf + len, buf_size - len, s); - return buf; -} - -/* extract the basename of a file */ -char *tcc_basename(const char *name) -{ - char *p = strchr(name, 0); - while (p > name && !IS_PATHSEP(p[-1])) - --p; - return p; -} -char *tcc_fileextension (const char *name) -{ - char *b = tcc_basename(name); - char *e = strrchr(b, '.'); - return e ? e : strchr(b, 0); -} - -void set_pages_executable(void *ptr, unsigned long length) -{ -#ifdef _WIN32 - unsigned long old_protect; - VirtualProtect(ptr, length, PAGE_EXECUTE_READWRITE, &old_protect); -#else - unsigned long start, end; - start = (unsigned long)ptr & ~(PAGESIZE - 1); - end = (unsigned long)ptr + length; - end = (end + PAGESIZE - 1) & ~(PAGESIZE - 1); - mprotect((void *)start, end - start, PROT_READ | PROT_WRITE | PROT_EXEC); -#endif -} - -/* memory management */ -#ifdef MEM_DEBUG -int mem_cur_size; -int mem_max_size; -unsigned malloc_usable_size(void*); -#endif - -void tcc_free(void *ptr) -{ -#ifdef MEM_DEBUG - mem_cur_size -= malloc_usable_size(ptr); -#endif - free(ptr); -} - -void *tcc_malloc(unsigned long size) -{ - void *ptr; - ptr = malloc(size); - if (!ptr && size) - error("memory full"); -#ifdef MEM_DEBUG - mem_cur_size += malloc_usable_size(ptr); - if (mem_cur_size > mem_max_size) - mem_max_size = mem_cur_size; -#endif - return ptr; -} - -void *tcc_mallocz(unsigned long size) -{ - void *ptr; - ptr = tcc_malloc(size); - memset(ptr, 0, size); - return ptr; -} - -void *tcc_realloc(void *ptr, unsigned long size) -{ - void *ptr1; -#ifdef MEM_DEBUG - mem_cur_size -= malloc_usable_size(ptr); -#endif - ptr1 = realloc(ptr, size); -#ifdef MEM_DEBUG - /* NOTE: count not correct if alloc error, but not critical */ - mem_cur_size += malloc_usable_size(ptr1); - if (mem_cur_size > mem_max_size) - mem_max_size = mem_cur_size; -#endif - return ptr1; -} - -char *tcc_strdup(const char *str) -{ - char *ptr; - ptr = tcc_malloc(strlen(str) + 1); - strcpy(ptr, str); - return ptr; -} - -#define free(p) use_tcc_free(p) -#define malloc(s) use_tcc_malloc(s) -#define realloc(p, s) use_tcc_realloc(p, s) - -void dynarray_add(void ***ptab, int *nb_ptr, void *data) -{ - int nb, nb_alloc; - void **pp; - - nb = *nb_ptr; - pp = *ptab; - /* every power of two we double array size */ - if ((nb & (nb - 1)) == 0) { - if (!nb) - nb_alloc = 1; - else - nb_alloc = nb * 2; - pp = tcc_realloc(pp, nb_alloc * sizeof(void *)); - if (!pp) - error("memory full"); - *ptab = pp; - } - pp[nb++] = data; - *nb_ptr = nb; -} - -void dynarray_reset(void *pp, int *n) -{ - void **p; - for (p = *(void***)pp; *n; ++p, --*n) - if (*p) - tcc_free(*p); - tcc_free(*(void**)pp); - *(void**)pp = NULL; -} Section *new_section(TCCState *s1, const char *name, int sh_type, int sh_flags) { diff --git a/tcc.h b/tcc.h index c15d4393..7de4725f 100755 --- a/tcc.h +++ b/tcc.h @@ -876,7 +876,6 @@ void type_to_str(char *buf, int buf_size, Sym *get_sym_ref(CType *type, Section *sec, unsigned long offset, unsigned long size); Sym *external_global_sym(int v, CType *type, int r); -Sym *sym_push(int v, CType *type, int r, int c); int tcc_add_dll(TCCState *s, const char *filename, int flags); @@ -1015,20 +1014,6 @@ extern unsigned long rt_prog_main; /* XXX: get rid of this ASAP */ extern struct TCCState *tcc_state; - -#include "tccpp.h" -#include "tcccoff.h" -#include "tccelf.h" -#include "tcccstring.h" -#include "tccgen.h" -#include "tccasm.h" -#include "tccld.h" -#include "tccsym.h" - -#ifdef TCC_TARGET_PE -#include "tccpe.h" -#endif - /* * Include the target specific definitions. */ @@ -1048,4 +1033,19 @@ extern struct TCCState *tcc_state; #include "x86_64-gen.h" #endif +#include "tccpp.h" +#include "tcccoff.h" +#include "tccelf.h" +#include "tcccstring.h" +#include "tccgen.h" +#include "tccasm.h" +#include "tccld.h" +#include "tccsym.h" +#include "tccutil.h" + +#ifdef TCC_TARGET_PE +#include "tccpe.h" +#endif + + #endif /* __TCC_H__ */ diff --git a/tccasm.c b/tccasm.c index fb67ba9b..62a0a15c 100755 --- a/tccasm.c +++ b/tccasm.c @@ -19,6 +19,14 @@ */ #include "tcc.h" +#ifdef TCC_TARGET_I386 +#include "i386-asm-config.h" +#endif + +#ifdef TCC_TARGET_X86_64 +#include "x86_64-asm-config.h" +#endif + static int asm_get_local_label_name(TCCState *s1, unsigned int n) { char buf[64]; @@ -990,7 +998,7 @@ static void asm_instr(void) /* generate loads */ asm_gen_code(operands, nb_operands, nb_outputs, 0, - clobber_regs, out_reg); + clobber_regs, out_reg); /* assemble the string with tcc internal assembler */ tcc_assemble_inline(tcc_state, astr1.data, astr1.size - 1); @@ -1012,7 +1020,7 @@ static void asm_instr(void) cstr_free(&astr1); } -static void asm_global_instr(void) +void asm_global_instr(void) { CString astr; @@ -1040,3 +1048,11 @@ static void asm_global_instr(void) cstr_free(&astr); } + + + + + + + + diff --git a/tccasm.h b/tccasm.h index 8771a8fb..c46927ba 100755 --- a/tccasm.h +++ b/tccasm.h @@ -26,6 +26,8 @@ int asm_int_expr(TCCState *s1); int find_constraint(ASMOperand *operands, int nb_operands, const char *name, const char **pp); int tcc_assemble(TCCState *s1, int do_preprocess); +void asm_instr(void); +void asm_global_instr(void); #endif #endif /* __TCCASM_H__ */ \ No newline at end of file diff --git a/tcccstring.c b/tcccstring.c index 60be2568..59e8d8ff 100755 --- a/tcccstring.c +++ b/tcccstring.c @@ -18,17 +18,6 @@ void cstr_realloc(CString *cstr, int new_size) cstr->data = data; } -/* add a byte */ -inline void cstr_ccat(CString *cstr, int ch) -{ - int size; - size = cstr->size + 1; - if (size > cstr->size_allocated) - cstr_realloc(cstr, size); - ((unsigned char *)cstr->data)[size - 1] = ch; - cstr->size = size; -} - void cstr_cat(CString *cstr, const char *str) { int c; diff --git a/tccsym.h b/tcccstring.h similarity index 53% copy from tccsym.h copy to tcccstring.h index 0f613823..824fc306 100755 --- a/tccsym.h +++ b/tcccstring.h @@ -1,5 +1,5 @@ /* - * Symbol handling for TCC + * String utility functions for TCC * * Copyright (c) 2001-2004 Fabrice Bellard * @@ -17,20 +17,29 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef __TCCSYM_H__ -#define __TCCSYM_H__ +#ifndef __TCCCSTRING_H__ +#define __TCCCSTRING_H__ -Sym *__sym_malloc(void); -inline Sym *sym_malloc(void); -inline void sym_free(Sym *sym); -Sym *sym_find(int v); -Sym *sym_push(int v, CType *type, int r, int c); -Sym *sym_push2(Sym **ps, int v, int t, long c); -Sym *sym_find2(Sym *s, int v); -inline Sym *struct_find(int v); -inline Sym *sym_find(int v); -Sym *global_identifier_push(int v, int t, int c); -void sym_pop(Sym **ptop, Sym *b); +#include "tcc.h" + +/* CString handling */ +void cstr_realloc(CString *cstr, int new_size); +/* add a byte */ +static inline void cstr_ccat(CString *cstr, int ch) +{ + int size; + size = cstr->size + 1; + if (size > cstr->size_allocated) + cstr_realloc(cstr, size); + ((unsigned char *)cstr->data)[size - 1] = ch; + cstr->size = size; +} +void cstr_cat(CString *cstr, const char *str); +void cstr_wccat(CString *cstr, int ch); +void cstr_new(CString *cstr); +void cstr_free(CString *cstr); +#define cstr_reset(cstr) cstr_free(cstr) +void add_char(CString *cstr, int c); -#endif /* __TCCSYM_H__ */ +#endif /* __TCCCSTRING_H__ */ diff --git a/tccgen.c b/tccgen.c index 7b465f0d..ea28fd9f 100755 --- a/tccgen.c +++ b/tccgen.c @@ -3725,7 +3725,7 @@ static void expr_eq(void) } } -static void gexpr(void) +void gexpr(void) { while (1) { expr_eq(); @@ -3774,7 +3774,7 @@ static void expr_const1(void) } /* parse an integer constant and return its value. */ -static int expr_const(void) +int expr_const(void) { int c; expr_const1(); @@ -5165,3 +5165,10 @@ void decl(int l) } } + + + + + + + diff --git a/tccgen.h b/tccgen.h index 7c118bc6..476581e4 100755 --- a/tccgen.h +++ b/tccgen.h @@ -25,9 +25,9 @@ static void expr_type(CType *type); static void unary_type(CType *type); static void block(int *bsym, int *csym, int *case_sym, int *def_sym, int case_reg, int is_expr); -static int expr_const(void); +int expr_const(void); static void expr_eq(void); -static void gexpr(void); +void gexpr(void); void gen_inline_functions(void); void decl(int l); void decl_initializer(CType *type, Section *sec, unsigned long c, diff --git a/tccpp.c b/tccpp.c index 39e7da89..6a15ab34 100755 --- a/tccpp.c +++ b/tccpp.c @@ -18,7 +18,6 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "tcc.h" -#include "tccpp.h" static const char tcc_keywords[] = #define DEF(id, str) str "\0" @@ -637,46 +636,8 @@ void restore_parse_state(ParseState *s) tokc = s->tokc; } -/* return the number of additional 'ints' necessary to store the - token */ -static inline int tok_ext_size(int t) -{ - switch(t) { - /* 4 bytes */ - case TOK_CINT: - case TOK_CUINT: - case TOK_CCHAR: - case TOK_LCHAR: - case TOK_CFLOAT: - case TOK_LINENUM: - return 1; - case TOK_STR: - case TOK_LSTR: - case TOK_PPNUM: - error("unsupported token"); - return 1; - case TOK_CDOUBLE: - case TOK_CLLONG: - case TOK_CULLONG: - return 2; - case TOK_CLDOUBLE: - return LDOUBLE_SIZE / 4; - default: - return 0; - } -} - -/* token string handling */ -static inline void tok_str_new(TokenString *s) -{ - s->str = NULL; - s->len = 0; - s->allocated_len = 0; - s->last_line_num = -1; -} - -static void tok_str_free(int *str) +void tok_str_free(int *str) { tcc_free(str); } @@ -698,7 +659,7 @@ static int *tok_str_realloc(TokenString *s) return str; } -static void tok_str_add(TokenString *s, int t) +void tok_str_add(TokenString *s, int t) { int len, *str; @@ -780,8 +741,10 @@ static void tok_str_add2(TokenString *s, int t, CValue *cv) s->len = len; } +/* token string handling */ + /* add the current parse token in token string 's' */ -static void tok_str_add_tok(TokenString *s) +void tok_str_add_tok(TokenString *s) { CValue cval; @@ -918,7 +881,7 @@ Sym *label_push(Sym **ptop, int v, int flags) /* pop labels until element last is reached. Look if any labels are undefined. Define symbols if '&&label' was used. */ -static void label_pop(Sym **ptop, Sym *slast) +void label_pop(Sym **ptop, Sym *slast) { Sym *s, *s1; for(s = *ptop; s != slast; s = s1) { @@ -2768,25 +2731,6 @@ void next(void) } } -/* push back current token and set current token to 'last_tok'. Only - identifier case handled for labels. */ -static inline void unget_tok(int last_tok) -{ - int i, n; - int *q; - unget_saved_macro_ptr = macro_ptr; - unget_buffer_enabled = 1; - q = unget_saved_buffer; - macro_ptr = q; - *q++ = tok; - n = tok_ext_size(tok) - 1; - for(i=0;istr = NULL; + s->len = 0; + s->allocated_len = 0; + s->last_line_num = -1; +} + +/* add the current parse token in token string 's' */ +void tok_str_add_tok(TokenString *s); +void tok_str_add(TokenString *s, int t); +void tok_str_free(int *str); #endif /* __TCCPP_H__ */ diff --git a/tccsym.c b/tccsym.c index 88d34b76..6d559f13 100755 --- a/tccsym.c +++ b/tccsym.c @@ -49,13 +49,7 @@ inline Sym *sym_malloc(void) return sym; } -inline void sym_free(Sym *sym) -{ - sym->next = sym_free_first; - sym_free_first = sym; -} - -/* push, without hashing */ +/* push, without hashing */ Sym *sym_push2(Sym **ps, int v, int t, long c) { Sym *s; @@ -175,3 +169,64 @@ void sym_pop(Sym **ptop, Sym *b) } *ptop = b; } + +#ifdef CONFIG_TCC_STATIC + +/* dummy function for profiling */ +void *dlopen(const char *filename, int flag) +{ + return NULL; +} + +void dlclose(void *p) +{ +} + +const char *dlerror(void) +{ + return "error"; +} + +typedef struct TCCSyms { + char *str; + void *ptr; +} TCCSyms; + +#define TCCSYM(a) { #a, &a, }, + +/* add the symbol you want here if no dynamic linking is done */ +static TCCSyms tcc_syms[] = { +#if !defined(CONFIG_TCCBOOT) + TCCSYM(printf) + TCCSYM(fprintf) + TCCSYM(fopen) + TCCSYM(fclose) +#endif + { NULL, NULL }, +}; + +void *resolve_sym(TCCState *s1, const char *symbol) +{ + TCCSyms *p; + p = tcc_syms; + while (p->str != NULL) { + if (!strcmp(p->str, symbol)) + return p->ptr; + p++; + } + return NULL; +} + +#elif defined(_WIN32) +#define dlclose FreeLibrary + +#else +#include + +void *resolve_sym(TCCState *s1, const char *sym) +{ + return dlsym(RTLD_DEFAULT, sym); +} + +#endif + diff --git a/tccsym.h b/tccsym.h index 0f613823..e35c90f3 100755 --- a/tccsym.h +++ b/tccsym.h @@ -22,7 +22,12 @@ Sym *__sym_malloc(void); inline Sym *sym_malloc(void); -inline void sym_free(Sym *sym); +static inline void sym_free(Sym *sym) +{ + sym->next = sym_free_first; + sym_free_first = sym; +} + Sym *sym_find(int v); Sym *sym_push(int v, CType *type, int r, int c); Sym *sym_push2(Sym **ps, int v, int t, long c); @@ -30,7 +35,29 @@ Sym *sym_find2(Sym *s, int v); inline Sym *struct_find(int v); inline Sym *sym_find(int v); Sym *global_identifier_push(int v, int t, int c); +Sym *sym_push(int v, CType *type, int r, int c); void sym_pop(Sym **ptop, Sym *b); +void *resolve_sym(TCCState *s1, const char *symbol); + +#ifdef CONFIG_TCC_STATIC + +#define RTLD_LAZY 0x001 +#define RTLD_NOW 0x002 +#define RTLD_GLOBAL 0x100 +#define RTLD_DEFAULT NULL + +/* dummy function for profiling */ +void *dlopen(const char *filename, int flag); +void dlclose(void *p); +const char *dlerror(void); +#elif defined(_WIN32) +#define dlclose FreeLibrary + +#else +#include +#endif #endif /* __TCCSYM_H__ */ + + -- 2.11.4.GIT