struct variable behind guard, proper macro check, and remove some whitespace.

Wrap runtime_main as per its declaration in tcc.h.
Fix preprocessor check for TCC_ARM_EABI macro definition.

Signed-off-by: Joseph Poirier <jdpoirier@gmail.com>
This commit is contained in:
Joseph Poirier 2013-11-08 13:24:15 -06:00
parent fbb4841606
commit 0650ab01c8
2 changed files with 56 additions and 54 deletions

View file

@ -1,6 +1,6 @@
/* /*
* ARMv4 code generator for TCC * ARMv4 code generator for TCC
* *
* Copyright (c) 2003 Daniel Glöckner * Copyright (c) 2003 Daniel Glöckner
* Copyright (c) 2012 Thomas Preud'homme * Copyright (c) 2012 Thomas Preud'homme
* *
@ -46,7 +46,7 @@
#define RC_INT 0x0001 /* generic integer register */ #define RC_INT 0x0001 /* generic integer register */
#define RC_FLOAT 0x0002 /* generic float register */ #define RC_FLOAT 0x0002 /* generic float register */
#define RC_R0 0x0004 #define RC_R0 0x0004
#define RC_R1 0x0008 #define RC_R1 0x0008
#define RC_R2 0x0010 #define RC_R2 0x0010
#define RC_R3 0x0020 #define RC_R3 0x0020
#define RC_R12 0x0040 #define RC_R12 0x0040
@ -211,7 +211,7 @@ void o(uint32_t i)
cur_text_section->data[ind++] = i&255; cur_text_section->data[ind++] = i&255;
i>>=8; i>>=8;
cur_text_section->data[ind++] = i&255; cur_text_section->data[ind++] = i&255;
i>>=8; i>>=8;
cur_text_section->data[ind++] = i&255; cur_text_section->data[ind++] = i&255;
i>>=8; i>>=8;
cur_text_section->data[ind++] = i; cur_text_section->data[ind++] = i;
@ -506,7 +506,7 @@ void load(int r, SValue *sv)
sign=1; sign=1;
fc=-fc; fc=-fc;
} }
v = fr & VT_VALMASK; v = fr & VT_VALMASK;
if (fr & VT_LVAL) { if (fr & VT_LVAL) {
uint32_t base = 0xB; // fp uint32_t base = 0xB; // fp
@ -645,8 +645,8 @@ void store(int r, SValue *sv)
sign=1; sign=1;
fc=-fc; fc=-fc;
} }
v = fr & VT_VALMASK; v = fr & VT_VALMASK;
if (fr & VT_LVAL || fr == VT_LOCAL) { if (fr & VT_LVAL || fr == VT_LOCAL) {
uint32_t base = 0xb; uint32_t base = 0xb;
if(v < VT_CONST) { if(v < VT_CONST) {
@ -660,16 +660,16 @@ void store(int r, SValue *sv)
v1.sym=sv->sym; v1.sym=sv->sym;
load(base=14, &v1); load(base=14, &v1);
fc=sign=0; fc=sign=0;
v=VT_LOCAL; v=VT_LOCAL;
} }
if(v == VT_LOCAL) { if(v == VT_LOCAL) {
if(is_float(ft)) { if(is_float(ft)) {
calcaddr(&base,&fc,&sign,1020,2); calcaddr(&base,&fc,&sign,1020,2);
#ifdef TCC_ARM_VFP #ifdef TCC_ARM_VFP
op=0xED000A00; /* fsts */ op=0xED000A00; /* fsts */
if(!sign) if(!sign)
op|=0x800000; op|=0x800000;
if ((ft & VT_BTYPE) != VT_FLOAT) if ((ft & VT_BTYPE) != VT_FLOAT)
op|=0x100; /* fsts -> fstd */ op|=0x100; /* fsts -> fstd */
o(op|(vfpr(r)<<12)|(fc>>2)|(base<<16)); o(op|(vfpr(r)<<12)|(fc>>2)|(base<<16));
#else #else
@ -802,7 +802,7 @@ int assign_fpreg(struct avail_regs *avregs, int align, int size)
/* Return 1 if this function returns via an sret pointer, 0 otherwise */ /* Return 1 if this function returns via an sret pointer, 0 otherwise */
ST_FUNC int gfunc_sret(CType *vt, CType *ret, int *ret_align) { ST_FUNC int gfunc_sret(CType *vt, CType *ret, int *ret_align) {
#if TCC_ARM_EABI #ifdef TCC_ARM_EABI
int size, align; int size, align;
size = type_size(vt, &align); size = type_size(vt, &align);
if (size > 4) { if (size > 4) {
@ -855,7 +855,7 @@ void gfunc_call(int nb_args)
vtop[-nb_args+1]=tmp; vtop[-nb_args+1]=tmp;
--nb_args; --nb_args;
} }
vpushi(0), nb_args++; vpushi(0), nb_args++;
vtop->type.t = VT_LLONG; vtop->type.t = VT_LLONG;
#endif #endif
@ -1023,7 +1023,7 @@ void gfunc_call(int nb_args)
size = 8; size = 8;
else else
size = LDOUBLE_SIZE; size = LDOUBLE_SIZE;
if (size == 12) if (size == 12)
r|=0x400000; r|=0x400000;
else if(size == 8) else if(size == 8)
@ -1362,7 +1362,7 @@ int gtst(int inv, int t)
return gtst(inv, t); return gtst(inv, t);
} else if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) { } else if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
/* constant jmp optimization */ /* constant jmp optimization */
if ((vtop->c.i != 0) != inv) if ((vtop->c.i != 0) != inv)
t = gjmp(t); t = gjmp(t);
} else { } else {
v = gv(RC_INT); v = gv(RC_INT);
@ -1370,7 +1370,7 @@ int gtst(int inv, int t)
vtop->r = VT_CMP; vtop->r = VT_CMP;
vtop->c.i = TOK_NE; vtop->c.i = TOK_NE;
return gtst(inv, t); return gtst(inv, t);
} }
} }
vtop--; vtop--;
return t; return t;
@ -1628,7 +1628,7 @@ void gen_opf(int op)
case TOK_UGE: op=TOK_GE; break; case TOK_UGE: op=TOK_GE; break;
case TOK_UGT: op=TOK_GT; break; case TOK_UGT: op=TOK_GT; break;
} }
vtop->r = VT_CMP; vtop->r = VT_CMP;
vtop->c.i = op; vtop->c.i = op;
return; return;
@ -1779,7 +1779,7 @@ void gen_opf(int op)
r=fpr(gv(RC_FLOAT)); r=fpr(gv(RC_FLOAT));
vswap(); vswap();
r2=fpr(gv(RC_FLOAT)); r2=fpr(gv(RC_FLOAT));
} }
break; break;
default: default:
if(op >= TOK_ULT && op <= TOK_GT) { if(op >= TOK_ULT && op <= TOK_GT) {

View file

@ -1,6 +1,6 @@
/* /*
* TCC - Tiny C Compiler * TCC - Tiny C Compiler
* *
* Copyright (c) 2001-2004 Fabrice Bellard * Copyright (c) 2001-2004 Fabrice Bellard
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
@ -156,7 +156,7 @@ PUB_FUNC char *pstrcat(char *buf, int buf_size, const char *s)
{ {
int len; int len;
len = strlen(buf); len = strlen(buf);
if (len < buf_size) if (len < buf_size)
pstrcpy(buf + len, buf_size - len, s); pstrcpy(buf + len, buf_size - len, s);
return buf; return buf;
} }
@ -275,7 +275,7 @@ ST_FUNC void dynarray_add(void ***ptab, int *nb_ptr, void *data)
{ {
int nb, nb_alloc; int nb, nb_alloc;
void **pp; void **pp;
nb = *nb_ptr; nb = *nb_ptr;
pp = *ptab; pp = *ptab;
/* every power of two we double array size */ /* every power of two we double array size */
@ -371,7 +371,7 @@ ST_FUNC void section_realloc(Section *sec, unsigned long new_size)
{ {
unsigned long size; unsigned long size;
unsigned char *data; unsigned char *data;
size = sec->data_allocated; size = sec->data_allocated;
if (size == 0) if (size == 0)
size = 1; size = 1;
@ -414,7 +414,7 @@ ST_FUNC Section *find_section(TCCState *s1, const char *name)
int i; int i;
for(i = 1; i < s1->nb_sections; i++) { for(i = 1; i < s1->nb_sections; i++) {
sec = s1->sections[i]; sec = s1->sections[i];
if (!strcmp(name, sec->name)) if (!strcmp(name, sec->name))
return sec; return sec;
} }
/* sections are created as PROGBITS */ /* sections are created as PROGBITS */
@ -423,7 +423,7 @@ ST_FUNC Section *find_section(TCCState *s1, const char *name)
/* update sym->c so that it points to an external symbol in section /* update sym->c so that it points to an external symbol in section
'section' with value 'value' */ 'section' with value 'value' */
ST_FUNC void put_extern_sym2(Sym *sym, Section *section, ST_FUNC void put_extern_sym2(Sym *sym, Section *section,
addr_t value, unsigned long size, addr_t value, unsigned long size,
int can_add_underscore) int can_add_underscore)
{ {
@ -434,7 +434,7 @@ ST_FUNC void put_extern_sym2(Sym *sym, Section *section,
if (section == NULL) if (section == NULL)
sh_num = SHN_UNDEF; sh_num = SHN_UNDEF;
else if (section == SECTION_ABS) else if (section == SECTION_ABS)
sh_num = SHN_ABS; sh_num = SHN_ABS;
else else
sh_num = section->sh_num; sh_num = section->sh_num;
@ -468,13 +468,13 @@ ST_FUNC void put_extern_sym2(Sym *sym, Section *section,
switch(sym->v) { switch(sym->v) {
#ifdef TCC_TARGET_PE #ifdef TCC_TARGET_PE
/* XXX: we rely only on malloc hooks */ /* XXX: we rely only on malloc hooks */
case TOK_malloc: case TOK_malloc:
case TOK_free: case TOK_free:
case TOK_realloc: case TOK_realloc:
case TOK_memalign: case TOK_memalign:
case TOK_calloc: case TOK_calloc:
#endif #endif
case TOK_memcpy: case TOK_memcpy:
case TOK_memmove: case TOK_memmove:
case TOK_memset: case TOK_memset:
case TOK_strlen: case TOK_strlen:
@ -527,7 +527,7 @@ ST_FUNC void put_extern_sym2(Sym *sym, Section *section,
} }
} }
ST_FUNC void put_extern_sym(Sym *sym, Section *section, ST_FUNC void put_extern_sym(Sym *sym, Section *section,
addr_t value, unsigned long size) addr_t value, unsigned long size)
{ {
put_extern_sym2(sym, section, value, size, 1); put_extern_sym2(sym, section, value, size, 1);
@ -567,7 +567,7 @@ static void error1(TCCState *s1, int is_warning, const char *fmt, va_list ap)
{ {
char buf[2048]; char buf[2048];
BufferedFile **pf, *f; BufferedFile **pf, *f;
buf[0] = '\0'; buf[0] = '\0';
/* use upper file if inline ":asm:" or token ":paste:" */ /* use upper file if inline ":asm:" or token ":paste:" */
for (f = file; f && f->filename[0] == ':'; f = f->prev) for (f = file; f && f->filename[0] == ':'; f = f->prev)
@ -718,28 +718,28 @@ static int tcc_compile(TCCState *s1)
cur_text_section = NULL; cur_text_section = NULL;
funcname = ""; funcname = "";
anon_sym = SYM_FIRST_ANOM; anon_sym = SYM_FIRST_ANOM;
/* file info: full path + filename */ /* file info: full path + filename */
section_sym = 0; /* avoid warning */ section_sym = 0; /* avoid warning */
if (s1->do_debug) { if (s1->do_debug) {
section_sym = put_elf_sym(symtab_section, 0, 0, section_sym = put_elf_sym(symtab_section, 0, 0,
ELFW(ST_INFO)(STB_LOCAL, STT_SECTION), 0, ELFW(ST_INFO)(STB_LOCAL, STT_SECTION), 0,
text_section->sh_num, NULL); text_section->sh_num, NULL);
getcwd(buf, sizeof(buf)); getcwd(buf, sizeof(buf));
#ifdef _WIN32 #ifdef _WIN32
normalize_slashes(buf); normalize_slashes(buf);
#endif #endif
pstrcat(buf, sizeof(buf), "/"); pstrcat(buf, sizeof(buf), "/");
put_stabs_r(buf, N_SO, 0, 0, put_stabs_r(buf, N_SO, 0, 0,
text_section->data_offset, text_section, section_sym); text_section->data_offset, text_section, section_sym);
put_stabs_r(file->filename, N_SO, 0, 0, put_stabs_r(file->filename, N_SO, 0, 0,
text_section->data_offset, text_section, section_sym); text_section->data_offset, text_section, section_sym);
} }
/* an elf symbol of type STT_FILE must be put so that STB_LOCAL /* an elf symbol of type STT_FILE must be put so that STB_LOCAL
symbols can be safely used */ symbols can be safely used */
put_elf_sym(symtab_section, 0, 0, put_elf_sym(symtab_section, 0, 0,
ELFW(ST_INFO)(STB_LOCAL, STT_FILE), 0, ELFW(ST_INFO)(STB_LOCAL, STT_FILE), 0,
SHN_ABS, file->filename); SHN_ABS, file->filename);
/* define some often used types */ /* define some often used types */
@ -794,7 +794,7 @@ static int tcc_compile(TCCState *s1)
/* end of translation unit info */ /* end of translation unit info */
if (s1->do_debug) { if (s1->do_debug) {
put_stabs_r(NULL, N_SO, 0, 0, put_stabs_r(NULL, N_SO, 0, 0,
text_section->data_offset, text_section, section_sym); text_section->data_offset, text_section, section_sym);
} }
} }
@ -803,7 +803,7 @@ static int tcc_compile(TCCState *s1)
/* reset define stack, but leave -Dsymbols (may be incorrect if /* reset define stack, but leave -Dsymbols (may be incorrect if
they are undefined) */ they are undefined) */
free_defines(define_start); free_defines(define_start);
gen_inline_functions(); gen_inline_functions();
@ -1004,13 +1004,13 @@ LIBTCCAPI TCCState *tcc_new(void)
/* symbols are always generated for linking stage */ /* symbols are always generated for linking stage */
symtab_section = new_symtab(s, ".symtab", SHT_SYMTAB, 0, symtab_section = new_symtab(s, ".symtab", SHT_SYMTAB, 0,
".strtab", ".strtab",
".hashtab", SHF_PRIVATE); ".hashtab", SHF_PRIVATE);
strtab_section = symtab_section->link; strtab_section = symtab_section->link;
s->symtab = symtab_section; s->symtab = symtab_section;
/* private symbol table for dynamic symbols */ /* private symbol table for dynamic symbols */
s->dynsymtab_section = new_symtab(s, ".dynsymtab", SHT_SYMTAB, SHF_PRIVATE, s->dynsymtab_section = new_symtab(s, ".dynsymtab", SHT_SYMTAB, SHF_PRIVATE,
".dynstrtab", ".dynstrtab",
".dynhashtab", SHF_PRIVATE); ".dynhashtab", SHF_PRIVATE);
s->alacarte_link = 1; s->alacarte_link = 1;
s->nocommon = 1; s->nocommon = 1;
@ -1026,7 +1026,9 @@ LIBTCCAPI TCCState *tcc_new(void)
#ifdef TCC_TARGET_I386 #ifdef TCC_TARGET_I386
s->seg_size = 32; s->seg_size = 32;
#endif #endif
#ifdef TCC_IS_NATIVE
s->runtime_main = "main"; s->runtime_main = "main";
#endif
return s; return s;
} }
@ -1044,7 +1046,7 @@ LIBTCCAPI void tcc_delete(TCCState *s1)
for(i = 0; i < s1->nb_priv_sections; i++) for(i = 0; i < s1->nb_priv_sections; i++)
free_section(s1->priv_sections[i]); free_section(s1->priv_sections[i]);
dynarray_reset(&s1->priv_sections, &s1->nb_priv_sections); dynarray_reset(&s1->priv_sections, &s1->nb_priv_sections);
/* free any loaded DLLs */ /* free any loaded DLLs */
#ifdef TCC_IS_NATIVE #ifdef TCC_IS_NATIVE
for ( i = 0; i < s1->nb_loaded_dlls; i++) { for ( i = 0; i < s1->nb_loaded_dlls; i++) {
@ -1053,7 +1055,7 @@ LIBTCCAPI void tcc_delete(TCCState *s1)
dlclose(ref->handle); dlclose(ref->handle);
} }
#endif #endif
/* free loaded dlls array */ /* free loaded dlls array */
dynarray_reset(&s1->loaded_dlls, &s1->nb_loaded_dlls); dynarray_reset(&s1->loaded_dlls, &s1->nb_loaded_dlls);
@ -1079,7 +1081,7 @@ LIBTCCAPI void tcc_delete(TCCState *s1)
#ifdef TCC_IS_NATIVE #ifdef TCC_IS_NATIVE
# ifdef HAVE_SELINUX # ifdef HAVE_SELINUX
munmap (s1->write_mem, s1->mem_size); munmap (s1->write_mem, s1->mem_size);
munmap (s1->runtime_mem, s1->mem_size); munmap (s1->runtime_mem, s1->mem_size);
# else # else
tcc_free(s1->runtime_mem); tcc_free(s1->runtime_mem);
# endif # endif
@ -1186,7 +1188,7 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags)
#endif #endif
ret = 0; ret = 0;
} else { } else {
ret = tcc_load_dll(s1, fd, filename, ret = tcc_load_dll(s1, fd, filename,
(flags & AFF_REFERENCED_DLL) != 0); (flags & AFF_REFERENCED_DLL) != 0);
} }
goto the_end; goto the_end;
@ -1318,9 +1320,9 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type)
/* define symbol */ /* define symbol */
tcc_define_symbol(s, "__BOUNDS_CHECKING_ON", NULL); tcc_define_symbol(s, "__BOUNDS_CHECKING_ON", NULL);
/* create bounds sections */ /* create bounds sections */
bounds_section = new_section(s, ".bounds", bounds_section = new_section(s, ".bounds",
SHT_PROGBITS, SHF_ALLOC); SHT_PROGBITS, SHF_ALLOC);
lbounds_section = new_section(s, ".lbounds", lbounds_section = new_section(s, ".lbounds",
SHT_PROGBITS, SHF_ALLOC); SHT_PROGBITS, SHF_ALLOC);
} }
#endif #endif
@ -1693,7 +1695,7 @@ static const TCCOption tcc_options[] = {
{ "isystem", TCC_OPTION_isystem, TCC_OPTION_HAS_ARG }, { "isystem", TCC_OPTION_isystem, TCC_OPTION_HAS_ARG },
{ "nostdinc", TCC_OPTION_nostdinc, 0 }, { "nostdinc", TCC_OPTION_nostdinc, 0 },
{ "nostdlib", TCC_OPTION_nostdlib, 0 }, { "nostdlib", TCC_OPTION_nostdlib, 0 },
{ "print-search-dirs", TCC_OPTION_print_search_dirs, 0 }, { "print-search-dirs", TCC_OPTION_print_search_dirs, 0 },
{ "v", TCC_OPTION_v, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, { "v", TCC_OPTION_v, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
{ "w", TCC_OPTION_w, 0 }, { "w", TCC_OPTION_w, 0 },
{ "pipe", TCC_OPTION_pipe, 0}, { "pipe", TCC_OPTION_pipe, 0},
@ -1859,7 +1861,7 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int argc, char **argv)
goto unsupported_option; goto unsupported_option;
break; break;
case TCC_OPTION_W: case TCC_OPTION_W:
if (tcc_set_warning(s, optarg, 1) < 0 && if (tcc_set_warning(s, optarg, 1) < 0 &&
s->warn_unsupported) s->warn_unsupported)
goto unsupported_option; goto unsupported_option;
break; break;
@ -1946,7 +1948,7 @@ PUB_FUNC void tcc_print_stats(TCCState *s, int64_t total_time)
tt = 0.001; tt = 0.001;
if (total_bytes < 1) if (total_bytes < 1)
total_bytes = 1; total_bytes = 1;
printf("%d idents, %d lines, %d bytes, %0.3f s, %d lines/s, %0.1f MB/s\n", printf("%d idents, %d lines, %d bytes, %0.3f s, %d lines/s, %0.1f MB/s\n",
tok_ident - TOK_IDENT, total_lines, total_bytes, tok_ident - TOK_IDENT, total_lines, total_bytes,
tt, (int)(total_lines / tt), tt, (int)(total_lines / tt),
total_bytes / tt / 1000000.0); total_bytes / tt / 1000000.0);
@ -1955,7 +1957,7 @@ PUB_FUNC void tcc_print_stats(TCCState *s, int64_t total_time)
PUB_FUNC void tcc_set_environment(TCCState *s) PUB_FUNC void tcc_set_environment(TCCState *s)
{ {
char * path; char * path;
path = getenv("C_INCLUDE_PATH"); path = getenv("C_INCLUDE_PATH");
if(path != NULL) { if(path != NULL) {
tcc_add_include_path(s, path); tcc_add_include_path(s, path);