rename error/warning -> tcc_(error/warning)

master
grischka 2011-08-11 17:07:56 +02:00
parent 74a24d77fd
commit bf374a5f23
15 changed files with 275 additions and 285 deletions

View File

@ -195,7 +195,7 @@ void o(uint32_t i)
ind1 = ind + 4; ind1 = ind + 4;
if (!cur_text_section) if (!cur_text_section)
error("compiler error! This happens f.ex. if the compiler\n" tcc_error("compiler error! This happens f.ex. if the compiler\n"
"can't evaluate constant expressions outside of a function."); "can't evaluate constant expressions outside of a function.");
if (ind1 > cur_text_section->data_allocated) if (ind1 > cur_text_section->data_allocated)
section_realloc(cur_text_section, ind1); section_realloc(cur_text_section, ind1);
@ -324,7 +324,7 @@ ST_FUNC uint32_t encbranch(int pos, int addr, int fail)
addr/=4; addr/=4;
if(addr>=0x1000000 || addr<-0x1000000) { if(addr>=0x1000000 || addr<-0x1000000) {
if(fail) if(fail)
error("FIXME: function bigger than 32MB"); tcc_error("FIXME: function bigger than 32MB");
return 0; return 0;
} }
return 0x0A000000|(addr&0xffffff); return 0x0A000000|(addr&0xffffff);
@ -366,14 +366,14 @@ void gsym(int t)
static uint32_t vfpr(int r) static uint32_t vfpr(int r)
{ {
if(r<TREG_F0 || r>TREG_F7) if(r<TREG_F0 || r>TREG_F7)
error("compiler error! register %i is no vfp register",r); tcc_error("compiler error! register %i is no vfp register",r);
return r-5; return r-5;
} }
#else #else
static uint32_t fpr(int r) static uint32_t fpr(int r)
{ {
if(r<TREG_F0 || r>TREG_F3) if(r<TREG_F0 || r>TREG_F3)
error("compiler error! register %i is no fpa register",r); tcc_error("compiler error! register %i is no fpa register",r);
return r-5; return r-5;
} }
#endif #endif
@ -383,7 +383,7 @@ static uint32_t intr(int r)
if(r==4) if(r==4)
return 12; return 12;
if((r<0 || r>4) && r!=14) if((r<0 || r>4) && r!=14)
error("compiler error! register %i is no int register",r); tcc_error("compiler error! register %i is no int register",r);
return r; return r;
} }
@ -443,7 +443,7 @@ static uint32_t mapcc(int cc)
case TOK_GT: case TOK_GT:
return 0xC0000000; /* GT */ return 0xC0000000; /* GT */
} }
error("unexpected condition code"); tcc_error("unexpected condition code");
return 0xE0000000; /* AL */ return 0xE0000000; /* AL */
} }
@ -476,7 +476,7 @@ static int negcc(int cc)
case TOK_GT: case TOK_GT:
return TOK_LE; return TOK_LE;
} }
error("unexpected condition code"); tcc_error("unexpected condition code");
return TOK_NE; return TOK_NE;
} }
@ -616,7 +616,7 @@ void load(int r, SValue *sv)
return; return;
} }
} }
error("load unimplemented!"); tcc_error("load unimplemented!");
} }
/* store register 'r' in lvalue 'v' */ /* store register 'r' in lvalue 'v' */
@ -697,7 +697,7 @@ void store(int r, SValue *sv)
return; return;
} }
} }
error("store unimplemented"); tcc_error("store unimplemented");
} }
static void gadd_sp(int val) static void gadd_sp(int val)
@ -1271,7 +1271,7 @@ done:
vtop->r = retreg; vtop->r = retreg;
break; break;
default: default:
error("gen_opi %i unimplemented!",op); tcc_error("gen_opi %i unimplemented!",op);
} }
} }
@ -1325,7 +1325,7 @@ void gen_opf(int op)
break; break;
default: default:
if(op < TOK_ULT && op > TOK_GT) { if(op < TOK_ULT && op > TOK_GT) {
error("unknown fp op %x!",op); tcc_error("unknown fp op %x!",op);
return; return;
} }
if(is_zero(-1)) { if(is_zero(-1)) {
@ -1520,7 +1520,7 @@ void gen_opf(int op)
case TOK_UGE: case TOK_UGE:
case TOK_ULE: case TOK_ULE:
case TOK_UGT: case TOK_UGT:
error("unsigned comparision on floats?"); tcc_error("unsigned comparision on floats?");
break; break;
case TOK_LT: case TOK_LT:
op=TOK_Nset; op=TOK_Nset;
@ -1564,7 +1564,7 @@ void gen_opf(int op)
vtop[-1].r = VT_CMP; vtop[-1].r = VT_CMP;
vtop[-1].c.i = op; vtop[-1].c.i = op;
} else { } else {
error("unknown fp op %x!",op); tcc_error("unknown fp op %x!",op);
return; return;
} }
} }
@ -1661,7 +1661,7 @@ ST_FUNC void gen_cvt_itof1(int t)
return; return;
} }
} }
error("unimplemented gen_cvt_itof %x!",vtop->type.t); tcc_error("unimplemented gen_cvt_itof %x!",vtop->type.t);
} }
/* convert fp to int 't' type */ /* convert fp to int 't' type */
@ -1721,7 +1721,7 @@ void gen_cvt_ftoi(int t)
vtop->r = REG_IRET; vtop->r = REG_IRET;
return; return;
} }
error("unimplemented gen_cvt_ftoi!"); tcc_error("unimplemented gen_cvt_ftoi!");
} }
/* convert from one floating point type to another */ /* convert from one floating point type to another */

View File

@ -95,7 +95,7 @@ enum {
#define ALWAYS_ASSERT(x) \ #define ALWAYS_ASSERT(x) \
do {\ do {\
if (!(x))\ if (!(x))\
error("internal compiler error file at %s:%d", __FILE__, __LINE__);\ tcc_error("internal compiler error file at %s:%d", __FILE__, __LINE__);\
} while (0) } while (0)
/* defined if function parameters must be evaluated in reverse order */ /* defined if function parameters must be evaluated in reverse order */
@ -1572,7 +1572,7 @@ void load(int r, SValue * sv)
load(r, &v1); load(r, &v1);
fr = r; fr = r;
} else if ((ft & VT_BTYPE) == VT_LDOUBLE) { } else if ((ft & VT_BTYPE) == VT_LDOUBLE) {
error("long double not supported"); tcc_error("long double not supported");
} else if ((ft & VT_TYPE) == VT_BYTE) { } else if ((ft & VT_TYPE) == VT_BYTE) {
size = 1; size = 1;
} else if ((ft & VT_TYPE) == (VT_BYTE | VT_UNSIGNED)) { } else if ((ft & VT_TYPE) == (VT_BYTE | VT_UNSIGNED)) {
@ -1726,7 +1726,7 @@ void store(int r, SValue * v)
/* XXX: incorrect if float reg to reg */ /* XXX: incorrect if float reg to reg */
if (bt == VT_LDOUBLE) { if (bt == VT_LDOUBLE) {
error("long double not supported"); tcc_error("long double not supported");
} else { } else {
if (bt == VT_SHORT) if (bt == VT_SHORT)
size = 2; size = 2;
@ -1881,7 +1881,7 @@ void gfunc_call(int nb_args)
int args_sizes[NoCallArgsPassedOnStack]; int args_sizes[NoCallArgsPassedOnStack];
if (nb_args > NoCallArgsPassedOnStack) { if (nb_args > NoCallArgsPassedOnStack) {
error("more than 10 function params not currently supported"); tcc_error("more than 10 function params not currently supported");
// handle more than 10, put some on the stack // handle more than 10, put some on the stack
} }
@ -1896,9 +1896,9 @@ void gfunc_call(int nb_args)
if ((vtop->type.t & VT_BTYPE) == VT_LLONG) { if ((vtop->type.t & VT_BTYPE) == VT_LLONG) {
error("long long not supported"); tcc_error("long long not supported");
} else if ((vtop->type.t & VT_BTYPE) == VT_LDOUBLE) { } else if ((vtop->type.t & VT_BTYPE) == VT_LDOUBLE) {
error("long double not supported"); tcc_error("long double not supported");
} else if ((vtop->type.t & VT_BTYPE) == VT_DOUBLE) { } else if ((vtop->type.t & VT_BTYPE) == VT_DOUBLE) {
size = 8; size = 8;
} else { } else {
@ -2329,7 +2329,7 @@ void gen_opf(int op)
if ((ft & VT_BTYPE) == VT_LDOUBLE) if ((ft & VT_BTYPE) == VT_LDOUBLE)
error("long doubles not supported"); tcc_error("long doubles not supported");
if (op >= TOK_ULT && op <= TOK_GT) { if (op >= TOK_ULT && op <= TOK_GT) {
@ -2481,7 +2481,7 @@ void gen_cvt_ftoi(int t)
r = vtop->r; r = vtop->r;
if (t != VT_INT) if (t != VT_INT)
error("long long not supported"); tcc_error("long long not supported");
else { else {
if ((vtop->type.t & VT_BTYPE) == VT_DOUBLE) { if ((vtop->type.t & VT_BTYPE) == VT_DOUBLE) {
C67_DPTRUNC(r, r); C67_DPTRUNC(r, r);

View File

@ -243,7 +243,7 @@ static inline int get_reg_shift(TCCState *s1)
int shift, v; int shift, v;
#ifdef I386_ASM_16 #ifdef I386_ASM_16
if (s1->seg_size == 16) if (s1->seg_size == 16)
error("invalid effective address"); tcc_error("invalid effective address");
#endif #endif
v = asm_int_expr(s1); v = asm_int_expr(s1);
switch(v) { switch(v) {
@ -342,7 +342,7 @@ static void parse_operand(TCCState *s1, Operand *op)
goto no_skip; goto no_skip;
} else { } else {
reg_error: reg_error:
error("unknown register"); tcc_error("unknown register");
} }
next(); next();
no_skip: ; no_skip: ;
@ -551,12 +551,12 @@ static inline void asm_modrm(int reg, Operand *op)
} else if ((sib_reg1 == 3) && (reg2 == 7)) { } else if ((sib_reg1 == 3) && (reg2 == 7)) {
reg1 = 1; reg1 = 1;
} else { } else {
error("invalid effective address"); tcc_error("invalid effective address");
} }
if (op->e.v == 0) if (op->e.v == 0)
mod = 0; mod = 0;
} else { } else {
error("invalid register"); tcc_error("invalid register");
} }
g(mod + (reg << 3) + reg1); g(mod + (reg << 3) + reg1);
} }
@ -599,18 +599,18 @@ ST_FUNC void asm_opcode(TCCState *s1, int opcode)
if (tok == ';' || tok == TOK_LINEFEED) if (tok == ';' || tok == TOK_LINEFEED)
break; break;
if (nb_ops >= MAX_OPERANDS) { if (nb_ops >= MAX_OPERANDS) {
error("incorrect number of operands"); tcc_error("incorrect number of operands");
} }
parse_operand(s1, pop); parse_operand(s1, pop);
if (tok == ':') { if (tok == ':') {
if (pop->type != OP_SEG || seg_prefix) if (pop->type != OP_SEG || seg_prefix)
error("incorrect prefix"); tcc_error("incorrect prefix");
seg_prefix = segment_prefixes[pop->reg]; seg_prefix = segment_prefixes[pop->reg];
next(); next();
parse_operand(s1, pop); parse_operand(s1, pop);
#ifndef I386_ASM_16 #ifndef I386_ASM_16
if (!(pop->type & OP_EA)) { if (!(pop->type & OP_EA)) {
error("segment prefix must be followed by memory reference"); tcc_error("segment prefix must be followed by memory reference");
} }
#endif #endif
} }
@ -701,12 +701,12 @@ ST_FUNC void asm_opcode(TCCState *s1, int opcode)
#ifdef I386_ASM_16 #ifdef I386_ASM_16
if (opcode == TOK_ASM_o32) { if (opcode == TOK_ASM_o32) {
if (s1->seg_size == 32) if (s1->seg_size == 32)
error("incorrect prefix"); tcc_error("incorrect prefix");
else else
o32 = data32 = 1; o32 = data32 = 1;
} else if (opcode == TOK_ASM_a32) { } else if (opcode == TOK_ASM_a32) {
if (s1->seg_size == 32) if (s1->seg_size == 32)
error("incorrect prefix"); tcc_error("incorrect prefix");
else else
a32 = addr32 = 1; a32 = addr32 = 1;
} }
@ -716,7 +716,7 @@ ST_FUNC void asm_opcode(TCCState *s1, int opcode)
g(b); g(b);
return; return;
} else { } else {
error("unknown opcode '%s'", tcc_error("unknown opcode '%s'",
get_tok_str(opcode, NULL)); get_tok_str(opcode, NULL));
} }
} }
@ -731,7 +731,7 @@ ST_FUNC void asm_opcode(TCCState *s1, int opcode)
(ops[0].type & (OP_SEG | OP_IM8S | OP_IM32 | OP_IM64))) (ops[0].type & (OP_SEG | OP_IM8S | OP_IM32 | OP_IM64)))
s = 2; s = 2;
else else
error("cannot infer opcode suffix"); tcc_error("cannot infer opcode suffix");
} }
} }
@ -849,7 +849,7 @@ ST_FUNC void asm_opcode(TCCState *s1, int opcode)
else else
v += 0x0f10; v += 0x0f10;
} else { } else {
error("invalid displacement"); tcc_error("invalid displacement");
} }
} }
} }
@ -883,7 +883,7 @@ ST_FUNC void asm_opcode(TCCState *s1, int opcode)
goto modrm_found; goto modrm_found;
} }
#ifdef ASM_DEBUG #ifdef ASM_DEBUG
error("bad op table"); tcc_error("bad op table");
#endif #endif
modrm_found: modrm_found:
modrm_index = i; modrm_index = i;
@ -912,7 +912,7 @@ ST_FUNC void asm_opcode(TCCState *s1, int opcode)
#endif #endif
gen_expr32(&ops[1].e); gen_expr32(&ops[1].e);
if (ops[0].e.sym) if (ops[0].e.sym)
error("cannot relocate"); tcc_error("cannot relocate");
gen_le16(ops[0].e.v); gen_le16(ops[0].e.v);
return; return;
} }
@ -944,7 +944,7 @@ ST_FUNC void asm_opcode(TCCState *s1, int opcode)
#endif #endif
if (ops[i].e.sym) if (ops[i].e.sym)
error_relocate: error_relocate:
error("cannot relocate"); tcc_error("cannot relocate");
else else
gen_le16(ops[i].e.v); gen_le16(ops[i].e.v);
} else { } else {
@ -1032,7 +1032,7 @@ static inline int constraint_priority(const char *str)
pr = 4; pr = 4;
break; break;
default: default:
error("unknown constraint '%c'", c); tcc_error("unknown constraint '%c'", c);
pr = 0; pr = 0;
} }
if (pr > priority) if (pr > priority)
@ -1083,11 +1083,11 @@ ST_FUNC void asm_compute_constraints(ASMOperand *operands,
/* this is a reference to another constraint */ /* this is a reference to another constraint */
k = find_constraint(operands, nb_operands, str, NULL); k = find_constraint(operands, nb_operands, str, NULL);
if ((unsigned)k >= i || i < nb_outputs) if ((unsigned)k >= i || i < nb_outputs)
error("invalid reference in constraint %d ('%s')", tcc_error("invalid reference in constraint %d ('%s')",
i, str); i, str);
op->ref_index = k; op->ref_index = k;
if (operands[k].input_index >= 0) if (operands[k].input_index >= 0)
error("cannot reference twice the same operand"); tcc_error("cannot reference twice the same operand");
operands[k].input_index = i; operands[k].input_index = i;
op->priority = 5; op->priority = 5;
} else { } else {
@ -1147,7 +1147,7 @@ ST_FUNC void asm_compute_constraints(ASMOperand *operands,
/* FALL THRU */ /* FALL THRU */
case '&': case '&':
if (j >= nb_outputs) if (j >= nb_outputs)
error("'%c' modifier can only be applied to outputs", c); tcc_error("'%c' modifier can only be applied to outputs", c);
reg_mask = REG_IN_MASK | REG_OUT_MASK; reg_mask = REG_IN_MASK | REG_OUT_MASK;
goto try_next; goto try_next;
case 'A': case 'A':
@ -1238,7 +1238,7 @@ ST_FUNC void asm_compute_constraints(ASMOperand *operands,
} }
break; break;
default: default:
error("asm constraint %d ('%s') could not be satisfied", tcc_error("asm constraint %d ('%s') could not be satisfied",
j, op->constraint); j, op->constraint);
break; break;
} }
@ -1261,7 +1261,7 @@ ST_FUNC void asm_compute_constraints(ASMOperand *operands,
if (!(regs_allocated[reg] & REG_OUT_MASK)) if (!(regs_allocated[reg] & REG_OUT_MASK))
goto reg_found2; goto reg_found2;
} }
error("could not find free output register for reloading"); tcc_error("could not find free output register for reloading");
reg_found2: reg_found2:
*pout_reg = reg; *pout_reg = reg;
break; break;
@ -1314,7 +1314,7 @@ ST_FUNC void subst_asm_operand(CString *add_str,
} else if (r & VT_LVAL) { } else if (r & VT_LVAL) {
reg = r & VT_VALMASK; reg = r & VT_VALMASK;
if (reg >= VT_CONST) if (reg >= VT_CONST)
error("internal compiler error"); tcc_error("internal compiler error");
snprintf(buf, sizeof(buf), "(%%%s)", snprintf(buf, sizeof(buf), "(%%%s)",
get_tok_str(TOK_ASM_eax + reg, NULL)); get_tok_str(TOK_ASM_eax + reg, NULL));
cstr_cat(add_str, buf); cstr_cat(add_str, buf);
@ -1322,7 +1322,7 @@ ST_FUNC void subst_asm_operand(CString *add_str,
/* register case */ /* register case */
reg = r & VT_VALMASK; reg = r & VT_VALMASK;
if (reg >= VT_CONST) if (reg >= VT_CONST)
error("internal compiler error"); tcc_error("internal compiler error");
/* choose register operand size */ /* choose register operand size */
if ((sv->type.t & VT_BTYPE) == VT_BYTE) if ((sv->type.t & VT_BTYPE) == VT_BYTE)
@ -1340,11 +1340,11 @@ ST_FUNC void subst_asm_operand(CString *add_str,
if (modifier == 'b') { if (modifier == 'b') {
if (reg >= 4) if (reg >= 4)
error("cannot use byte register"); tcc_error("cannot use byte register");
size = 1; size = 1;
} else if (modifier == 'h') { } else if (modifier == 'h') {
if (reg >= 4) if (reg >= 4)
error("cannot use byte register"); tcc_error("cannot use byte register");
size = -1; size = -1;
} else if (modifier == 'w') { } else if (modifier == 'w') {
size = 2; size = 2;
@ -1492,7 +1492,7 @@ ST_FUNC void asm_clobber(uint8_t *clobber_regs, const char *str)
reg -= TOK_ASM_rax; reg -= TOK_ASM_rax;
#endif #endif
} else { } else {
error("invalid clobber register '%s'", str); tcc_error("invalid clobber register '%s'", str);
} }
clobber_regs[reg] = 1; clobber_regs[reg] = 1;
} }

View File

@ -1068,7 +1068,7 @@ ST_FUNC void gen_bounded_ptr_deref(void)
case 12: func = TOK___bound_ptr_indir12; break; case 12: func = TOK___bound_ptr_indir12; break;
case 16: func = TOK___bound_ptr_indir16; break; case 16: func = TOK___bound_ptr_indir16; break;
default: default:
error("unhandled size when derefencing bounded pointer"); tcc_error("unhandled size when derefencing bounded pointer");
func = 0; func = 0;
break; break;
} }

View File

@ -193,7 +193,7 @@ static void il_type_to_str(char *buf, int buf_size,
pstrcat(buf, buf_size, tstr); pstrcat(buf, buf_size, tstr);
break; break;
case VT_STRUCT: case VT_STRUCT:
error("structures not handled yet"); tcc_error("structures not handled yet");
break; break;
case VT_FUNC: case VT_FUNC:
s = sym_find((unsigned)t >> VT_STRUCT_SHIFT); s = sym_find((unsigned)t >> VT_STRUCT_SHIFT);
@ -387,7 +387,7 @@ void gfunc_start(GFuncContext *c, int func_call)
void gfunc_param(GFuncContext *c) void gfunc_param(GFuncContext *c)
{ {
if ((vtop->t & VT_BTYPE) == VT_STRUCT) { if ((vtop->t & VT_BTYPE) == VT_STRUCT) {
error("structures passed as value not handled yet"); tcc_error("structures passed as value not handled yet");
} else { } else {
/* simply push on stack */ /* simply push on stack */
gv(RC_ST0); gv(RC_ST0);

View File

@ -69,11 +69,11 @@ ST_DATA struct TCCState *tcc_state;
#ifndef CONFIG_TCC_ASM #ifndef CONFIG_TCC_ASM
ST_FUNC void asm_instr(void) ST_FUNC void asm_instr(void)
{ {
error("inline asm() not supported"); tcc_error("inline asm() not supported");
} }
ST_FUNC void asm_global_instr(void) ST_FUNC void asm_global_instr(void)
{ {
error("inline asm() not supported"); tcc_error("inline asm() not supported");
} }
#endif #endif
@ -213,7 +213,7 @@ PUB_FUNC void *tcc_malloc(unsigned long size)
void *ptr; void *ptr;
ptr = malloc(size); ptr = malloc(size);
if (!ptr && size) if (!ptr && size)
error("memory full"); tcc_error("memory full");
#ifdef MEM_DEBUG #ifdef MEM_DEBUG
mem_cur_size += malloc_usable_size(ptr); mem_cur_size += malloc_usable_size(ptr);
if (mem_cur_size > mem_max_size) if (mem_cur_size > mem_max_size)
@ -283,7 +283,7 @@ PUB_FUNC void dynarray_add(void ***ptab, int *nb_ptr, void *data)
nb_alloc = nb * 2; nb_alloc = nb * 2;
pp = tcc_realloc(pp, nb_alloc * sizeof(void *)); pp = tcc_realloc(pp, nb_alloc * sizeof(void *));
if (!pp) if (!pp)
error("memory full"); tcc_error("memory full");
*ptab = pp; *ptab = pp;
} }
pp[nb++] = data; pp[nb++] = data;
@ -378,7 +378,7 @@ ST_FUNC void section_realloc(Section *sec, unsigned long new_size)
size = size * 2; size = size * 2;
data = tcc_realloc(sec->data, size); data = tcc_realloc(sec->data, size);
if (!data) if (!data)
error("memory full"); tcc_error("memory full");
memset(data + sec->data_allocated, 0, size - sec->data_allocated); memset(data + sec->data_allocated, 0, size - sec->data_allocated);
sec->data = data; sec->data = data;
sec->data_allocated = size; sec->data_allocated = size;
@ -609,7 +609,7 @@ LIBTCCAPI void tcc_set_error_func(TCCState *s, void *error_opaque,
} }
/* error without aborting current compilation */ /* error without aborting current compilation */
PUB_FUNC void error_noabort(const char *fmt, ...) PUB_FUNC void tcc_error_noabort(const char *fmt, ...)
{ {
TCCState *s1 = tcc_state; TCCState *s1 = tcc_state;
va_list ap; va_list ap;
@ -619,7 +619,7 @@ PUB_FUNC void error_noabort(const char *fmt, ...)
va_end(ap); va_end(ap);
} }
PUB_FUNC void error(const char *fmt, ...) PUB_FUNC void tcc_error(const char *fmt, ...)
{ {
TCCState *s1 = tcc_state; TCCState *s1 = tcc_state;
va_list ap; va_list ap;
@ -636,7 +636,7 @@ PUB_FUNC void error(const char *fmt, ...)
} }
} }
PUB_FUNC void warning(const char *fmt, ...) PUB_FUNC void tcc_warning(const char *fmt, ...)
{ {
TCCState *s1 = tcc_state; TCCState *s1 = tcc_state;
va_list ap; va_list ap;
@ -790,7 +790,7 @@ static int tcc_compile(TCCState *s1)
if (tok != TOK_EOF) if (tok != TOK_EOF)
expect("declaration"); expect("declaration");
if (pvtop != vtop) if (pvtop != vtop)
warning("internal compiler error: vstack leak? (%d)", vtop - pvtop); tcc_warning("internal compiler error: vstack leak? (%d)", vtop - pvtop);
/* end of translation unit info */ /* end of translation unit info */
if (s1->do_debug) { if (s1->do_debug) {
@ -1105,7 +1105,7 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags)
ret = tcc_open(s1, filename); ret = tcc_open(s1, filename);
if (ret < 0) { if (ret < 0) {
if (flags & AFF_PRINT_ERROR) if (flags & AFF_PRINT_ERROR)
error_noabort("file '%s' not found", filename); tcc_error_noabort("file '%s' not found", filename);
return ret; return ret;
} }
@ -1143,7 +1143,7 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags)
size = read(fd, &ehdr, sizeof(ehdr)); size = read(fd, &ehdr, sizeof(ehdr));
lseek(fd, 0, SEEK_SET); lseek(fd, 0, SEEK_SET);
if (size <= 0) { if (size <= 0) {
error_noabort("could not read header"); tcc_error_noabort("could not read header");
goto the_end; goto the_end;
} }
@ -1174,7 +1174,7 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags)
goto the_end; goto the_end;
} }
#endif #endif
error_noabort("unrecognized ELF file"); tcc_error_noabort("unrecognized ELF file");
goto the_end; goto the_end;
} }
@ -1198,7 +1198,7 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags)
ret = tcc_load_ldscript(s1); ret = tcc_load_ldscript(s1);
#endif #endif
if (ret < 0) if (ret < 0)
error_noabort("unrecognized file type"); tcc_error_noabort("unrecognized file type");
the_end: the_end:
tcc_close(); tcc_close();
@ -1247,7 +1247,7 @@ ST_FUNC int tcc_add_crt(TCCState *s, const char *filename)
{ {
if (-1 == tcc_add_library_internal(s, "%s/%s", if (-1 == tcc_add_library_internal(s, "%s/%s",
filename, 0, s->crt_paths, s->nb_crt_paths)) filename, 0, s->crt_paths, s->nb_crt_paths))
error_noabort("file '%s' not found", filename); tcc_error_noabort("file '%s' not found", filename);
return 0; return 0;
} }
@ -1485,14 +1485,14 @@ PUB_FUNC const char * tcc_set_linker(TCCState *s, char *option, int multi)
} else if (link_option(option, "fini=", &p)) { } else if (link_option(option, "fini=", &p)) {
s->fini_symbol = p; s->fini_symbol = p;
if (s->warn_unsupported) if (s->warn_unsupported)
warning("ignoring -fini %s", p); tcc_warning("ignoring -fini %s", p);
} else if (link_option(option, "image-base=", &p)) { } else if (link_option(option, "image-base=", &p)) {
s->text_addr = strtoul(p, &end, 16); s->text_addr = strtoul(p, &end, 16);
s->has_text_addr = 1; s->has_text_addr = 1;
} else if (link_option(option, "init=", &p)) { } else if (link_option(option, "init=", &p)) {
s->init_symbol = p; s->init_symbol = p;
if (s->warn_unsupported) if (s->warn_unsupported)
warning("ignoring -init %s", p); tcc_warning("ignoring -init %s", p);
} else if (link_option(option, "oformat=", &p)) { } else if (link_option(option, "oformat=", &p)) {
#if defined(TCC_TARGET_PE) #if defined(TCC_TARGET_PE)
if (strstart(p, "pe-", NULL)) { if (strstart(p, "pe-", NULL)) {
@ -1647,7 +1647,7 @@ PUB_FUNC void tcc_gen_makedeps(TCCState *s, const char *target, const char *file
/* XXX return err codes instead of error() ? */ /* XXX return err codes instead of error() ? */
depout = fopen(filename, "w"); depout = fopen(filename, "w");
if (!depout) if (!depout)
error("could not open '%s'", filename); tcc_error("could not open '%s'", filename);
fprintf(depout, "%s : \\\n", target); fprintf(depout, "%s : \\\n", target);
for (i=0; i<s->nb_target_deps; ++i) for (i=0; i<s->nb_target_deps; ++i)

22
tcc.c
View File

@ -254,11 +254,11 @@ static void exec_other_tcc(TCCState *s, char **argv, const char *optarg)
printf("tcc: using '%s'\n", child_name), fflush(stdout); printf("tcc: using '%s'\n", child_name), fflush(stdout);
execvp(argv[0] = child_path, argv); execvp(argv[0] = child_path, argv);
} }
error("'%s' not found", child_name); tcc_error("'%s' not found", child_name);
case 0: /* ignore -march etc. */ case 0: /* ignore -march etc. */
break; break;
default: default:
warning("unsupported option \"-m%s\"", optarg); tcc_warning("unsupported option \"-m%s\"", optarg);
} }
} }
#endif #endif
@ -301,7 +301,7 @@ static int parse_args(TCCState *s, int argc, char **argv)
for(;;) { for(;;) {
p1 = popt->name; p1 = popt->name;
if (p1 == NULL) if (p1 == NULL)
error("invalid option -- '%s'", r); tcc_error("invalid option -- '%s'", r);
r1 = r + 1; r1 = r + 1;
for(;;) { for(;;) {
if (*p1 == '\0') if (*p1 == '\0')
@ -319,7 +319,7 @@ static int parse_args(TCCState *s, int argc, char **argv)
optarg = r1; optarg = r1;
} else { } else {
if (optind >= argc) if (optind >= argc)
error("argument to '%s' is missing", r); tcc_error("argument to '%s' is missing", r);
optarg = argv[optind++]; optarg = argv[optind++];
} }
} else { } else {
@ -334,7 +334,7 @@ static int parse_args(TCCState *s, int argc, char **argv)
case TCC_OPTION_I: case TCC_OPTION_I:
if (tcc_add_include_path(s, optarg) < 0) if (tcc_add_include_path(s, optarg) < 0)
error("too many include paths"); tcc_error("too many include paths");
break; break;
case TCC_OPTION_D: case TCC_OPTION_D:
parse_option_D(s, optarg); parse_option_D(s, optarg);
@ -443,7 +443,7 @@ static int parse_args(TCCState *s, int argc, char **argv)
break; break;
case TCC_OPTION_Wl: case TCC_OPTION_Wl:
if ((r = (char *) tcc_set_linker(s, (char *)optarg, TRUE))) if ((r = (char *) tcc_set_linker(s, (char *)optarg, TRUE)))
error("unsupported linker option '%s'", r); tcc_error("unsupported linker option '%s'", r);
break; break;
case TCC_OPTION_E: case TCC_OPTION_E:
output_type = TCC_OUTPUT_PREPROCESS; output_type = TCC_OUTPUT_PREPROCESS;
@ -459,7 +459,7 @@ static int parse_args(TCCState *s, int argc, char **argv)
default: default:
if (s->warn_unsupported) { if (s->warn_unsupported) {
unsupported_option: unsupported_option:
warning("unsupported option '%s'", r); tcc_warning("unsupported option '%s'", r);
} }
break; break;
} }
@ -528,9 +528,9 @@ int main(int argc, char **argv)
if (output_type == TCC_OUTPUT_OBJ && !reloc_output) { if (output_type == TCC_OUTPUT_OBJ && !reloc_output) {
/* accepts only a single input file */ /* accepts only a single input file */
if (nb_objfiles != 1) if (nb_objfiles != 1)
error("cannot specify multiple files with -c"); tcc_error("cannot specify multiple files with -c");
if (nb_libraries != 0) if (nb_libraries != 0)
error("cannot specify libraries with -c"); tcc_error("cannot specify libraries with -c");
} }
if (output_type == TCC_OUTPUT_PREPROCESS) { if (output_type == TCC_OUTPUT_PREPROCESS) {
@ -539,7 +539,7 @@ int main(int argc, char **argv)
} else { } else {
s->outfile = fopen(outfile, "w"); s->outfile = fopen(outfile, "w");
if (!s->outfile) if (!s->outfile)
error("could not open '%s'", outfile); tcc_error("could not open '%s'", outfile);
} }
} }
@ -557,7 +557,7 @@ int main(int argc, char **argv)
filename = files[i]; filename = files[i];
if (filename[0] == '-' && filename[1] == 'l') { if (filename[0] == '-' && filename[1] == 'l') {
if (tcc_add_library(s, filename + 2) < 0) { if (tcc_add_library(s, filename + 2) < 0) {
error_noabort("cannot find %s", filename); tcc_error_noabort("cannot find %s", filename);
ret = 1; ret = 1;
} }
} else { } else {

6
tcc.h
View File

@ -985,9 +985,9 @@ PUB_FUNC char *tcc_strdup(const char *str);
PUB_FUNC void tcc_memstats(void); PUB_FUNC void tcc_memstats(void);
PUB_FUNC void dynarray_add(void ***ptab, int *nb_ptr, void *data); PUB_FUNC void dynarray_add(void ***ptab, int *nb_ptr, void *data);
PUB_FUNC void dynarray_reset(void *pp, int *n); PUB_FUNC void dynarray_reset(void *pp, int *n);
PUB_FUNC void error_noabort(const char *fmt, ...); PUB_FUNC void tcc_error_noabort(const char *fmt, ...);
PUB_FUNC void error(const char *fmt, ...); PUB_FUNC void tcc_error(const char *fmt, ...);
PUB_FUNC void warning(const char *fmt, ...); PUB_FUNC void tcc_warning(const char *fmt, ...);
/* other utilities */ /* other utilities */
ST_INLN void cstr_ccat(CString *cstr, int ch); ST_INLN void cstr_ccat(CString *cstr, int ch);

View File

@ -54,7 +54,7 @@ static void asm_expr_unary(TCCState *s1, ExprValue *pe)
if (sym && sym->r == 0) if (sym && sym->r == 0)
sym = sym->prev_tok; sym = sym->prev_tok;
if (!sym) if (!sym)
error("local label '%d' not found backward", n); tcc_error("local label '%d' not found backward", n);
} else { } else {
/* forward */ /* forward */
if (!sym || sym->r) { if (!sym || sym->r) {
@ -69,7 +69,7 @@ static void asm_expr_unary(TCCState *s1, ExprValue *pe)
pe->v = n; pe->v = n;
pe->sym = NULL; pe->sym = NULL;
} else { } else {
error("invalid number syntax"); tcc_error("invalid number syntax");
} }
next(); next();
break; break;
@ -83,7 +83,7 @@ static void asm_expr_unary(TCCState *s1, ExprValue *pe)
next(); next();
asm_expr_unary(s1, pe); asm_expr_unary(s1, pe);
if (pe->sym) if (pe->sym)
error("invalid operation with label"); tcc_error("invalid operation with label");
if (op == '-') if (op == '-')
pe->v = -pe->v; pe->v = -pe->v;
else else
@ -119,7 +119,7 @@ static void asm_expr_unary(TCCState *s1, ExprValue *pe)
} }
next(); next();
} else { } else {
error("bad expression syntax [%s]", get_tok_str(tok, &tokc)); tcc_error("bad expression syntax [%s]", get_tok_str(tok, &tokc));
} }
break; break;
} }
@ -139,7 +139,7 @@ static void asm_expr_prod(TCCState *s1, ExprValue *pe)
next(); next();
asm_expr_unary(s1, &e2); asm_expr_unary(s1, &e2);
if (pe->sym || e2.sym) if (pe->sym || e2.sym)
error("invalid operation with label"); tcc_error("invalid operation with label");
switch(op) { switch(op) {
case '*': case '*':
pe->v *= e2.v; pe->v *= e2.v;
@ -147,7 +147,7 @@ static void asm_expr_prod(TCCState *s1, ExprValue *pe)
case '/': case '/':
if (e2.v == 0) { if (e2.v == 0) {
div_error: div_error:
error("division by zero"); tcc_error("division by zero");
} }
pe->v /= e2.v; pe->v /= e2.v;
break; break;
@ -180,7 +180,7 @@ static void asm_expr_logic(TCCState *s1, ExprValue *pe)
next(); next();
asm_expr_prod(s1, &e2); asm_expr_prod(s1, &e2);
if (pe->sym || e2.sym) if (pe->sym || e2.sym)
error("invalid operation with label"); tcc_error("invalid operation with label");
switch(op) { switch(op) {
case '&': case '&':
pe->v &= e2.v; pe->v &= e2.v;
@ -234,7 +234,7 @@ static inline void asm_expr_sum(TCCState *s1, ExprValue *pe)
pe->sym = NULL; /* same symbols can be substracted to NULL */ pe->sym = NULL; /* same symbols can be substracted to NULL */
} else { } else {
cannot_relocate: cannot_relocate:
error("invalid operation with label"); tcc_error("invalid operation with label");
} }
} }
} }
@ -266,7 +266,7 @@ static void asm_new_label1(TCCState *s1, int label, int is_local,
if (sym->r) { if (sym->r) {
/* the label is already defined */ /* the label is already defined */
if (!is_local) { if (!is_local) {
error("assembler label '%s' already defined", tcc_error("assembler label '%s' already defined",
get_tok_str(label, NULL)); get_tok_str(label, NULL));
} else { } else {
/* redefinition of local labels is possible */ /* redefinition of local labels is possible */
@ -341,7 +341,7 @@ static void asm_parse_directive(TCCState *s1)
n = asm_int_expr(s1); n = asm_int_expr(s1);
if (tok1 == TOK_ASM_align) { if (tok1 == TOK_ASM_align) {
if (n < 0 || (n & (n-1)) != 0) if (n < 0 || (n & (n-1)) != 0)
error("alignment must be a positive power of two"); tcc_error("alignment must be a positive power of two");
offset = (ind + n - 1) & -n; offset = (ind + n - 1) & -n;
size = offset - ind; size = offset - ind;
/* the section must have a compatible alignment */ /* the section must have a compatible alignment */
@ -372,7 +372,7 @@ static void asm_parse_directive(TCCState *s1)
p = tokc.cstr->data; p = tokc.cstr->data;
if (tok != TOK_PPNUM) { if (tok != TOK_PPNUM) {
error_constant: error_constant:
error("64 bit constant"); tcc_error("64 bit constant");
} }
vl = strtoll(p, (char **)&p, 0); vl = strtoll(p, (char **)&p, 0);
if (*p != '\0') if (*p != '\0')
@ -431,7 +431,7 @@ static void asm_parse_directive(TCCState *s1)
next(); next();
repeat = asm_int_expr(s1); repeat = asm_int_expr(s1);
if (repeat < 0) { if (repeat < 0) {
error("repeat < 0; .fill ignored"); tcc_error("repeat < 0; .fill ignored");
break; break;
} }
size = 1; size = 1;
@ -440,7 +440,7 @@ static void asm_parse_directive(TCCState *s1)
next(); next();
size = asm_int_expr(s1); size = asm_int_expr(s1);
if (size < 0) { if (size < 0) {
error("size < 0; .fill ignored"); tcc_error("size < 0; .fill ignored");
break; break;
} }
if (size > 8) if (size > 8)
@ -473,7 +473,7 @@ static void asm_parse_directive(TCCState *s1)
/* XXX: handle section symbols too */ /* XXX: handle section symbols too */
n = asm_int_expr(s1); n = asm_int_expr(s1);
if (n < ind) if (n < ind)
error("attempt to .org backwards"); tcc_error("attempt to .org backwards");
v = 0; v = 0;
size = n - ind; size = n - ind;
goto zero_pad; goto zero_pad;
@ -554,7 +554,7 @@ static void asm_parse_directive(TCCState *s1)
pstrcat(filename, sizeof(filename), get_tok_str(tok, NULL)); pstrcat(filename, sizeof(filename), get_tok_str(tok, NULL));
if (s1->warn_unsupported) if (s1->warn_unsupported)
warning("ignoring .file %s", filename); tcc_warning("ignoring .file %s", filename);
next(); next();
} }
@ -572,7 +572,7 @@ static void asm_parse_directive(TCCState *s1)
pstrcat(ident, sizeof(ident), get_tok_str(tok, NULL)); pstrcat(ident, sizeof(ident), get_tok_str(tok, NULL));
if (s1->warn_unsupported) if (s1->warn_unsupported)
warning("ignoring .ident %s", ident); tcc_warning("ignoring .ident %s", ident);
next(); next();
} }
@ -584,14 +584,14 @@ static void asm_parse_directive(TCCState *s1)
next(); next();
sym = label_find(tok); sym = label_find(tok);
if (!sym) { if (!sym) {
error("label not found: %s", get_tok_str(tok, NULL)); tcc_error("label not found: %s", get_tok_str(tok, NULL));
} }
next(); next();
skip(','); skip(',');
/* XXX .size name,label2-label1 */ /* XXX .size name,label2-label1 */
if (s1->warn_unsupported) if (s1->warn_unsupported)
warning("ignoring .size %s,*", get_tok_str(tok, NULL)); tcc_warning("ignoring .size %s,*", get_tok_str(tok, NULL));
while (tok != '\n' && tok != CH_EOF) { while (tok != '\n' && tok != CH_EOF) {
next(); next();
@ -624,7 +624,7 @@ static void asm_parse_directive(TCCState *s1)
sym->type.t = VT_FUNC; sym->type.t = VT_FUNC;
} }
else if (s1->warn_unsupported) else if (s1->warn_unsupported)
warning("change type of '%s' from 0x%x to '%s' ignored", tcc_warning("change type of '%s' from 0x%x to '%s' ignored",
get_tok_str(sym->v, NULL), sym->type.t, newtype); get_tok_str(sym->v, NULL), sym->type.t, newtype);
next(); next();
@ -660,7 +660,7 @@ static void asm_parse_directive(TCCState *s1)
Section *sec; Section *sec;
next(); next();
if (!last_text_section) if (!last_text_section)
error("no previous section referenced"); tcc_error("no previous section referenced");
sec = cur_text_section; sec = cur_text_section;
use_section1(s1, last_text_section); use_section1(s1, last_text_section);
last_text_section = sec; last_text_section = sec;
@ -687,7 +687,7 @@ static void asm_parse_directive(TCCState *s1)
break; break;
#endif #endif
default: default:
error("unknown assembler directive '.%s'", get_tok_str(tok, NULL)); tcc_error("unknown assembler directive '.%s'", get_tok_str(tok, NULL));
break; break;
} }
} }
@ -913,7 +913,7 @@ static void subst_asm_operands(ASMOperand *operands, int nb_operands,
modifier = *str++; modifier = *str++;
index = find_constraint(operands, nb_operands, str, &str); index = find_constraint(operands, nb_operands, str, &str);
if (index < 0) if (index < 0)
error("invalid operand reference after %%"); tcc_error("invalid operand reference after %%");
op = &operands[index]; op = &operands[index];
sv = *op->vt; sv = *op->vt;
if (op->reg >= 0) { if (op->reg >= 0) {
@ -942,7 +942,7 @@ static void parse_asm_operands(ASMOperand *operands, int *nb_operands_ptr,
nb_operands = *nb_operands_ptr; nb_operands = *nb_operands_ptr;
for(;;) { for(;;) {
if (nb_operands >= MAX_ASM_OPERANDS) if (nb_operands >= MAX_ASM_OPERANDS)
error("too many asm operands"); tcc_error("too many asm operands");
op = &operands[nb_operands++]; op = &operands[nb_operands++];
op->id = 0; op->id = 0;
if (tok == '[') { if (tok == '[') {

View File

@ -533,7 +533,7 @@ ST_FUNC int tcc_output_coff(TCCState *s1, FILE *f)
} else { } else {
if (pCoff_str_table - Coff_str_table + strlen(name) > if (pCoff_str_table - Coff_str_table + strlen(name) >
MAX_STR_TABLE - 1) MAX_STR_TABLE - 1)
error("String table too large"); tcc_error("String table too large");
csym._n._n_n._n_zeroes = 0; csym._n._n_n._n_zeroes = 0;
csym._n._n_n._n_offset = csym._n._n_n._n_offset =
@ -563,11 +563,7 @@ ST_FUNC int tcc_output_coff(TCCState *s1, FILE *f)
} }
if (k >= nFuncs) { if (k >= nFuncs) {
char s[256]; tcc_error("debug info can't find function: %s", name);
sprintf(s, "debug info can't find function: %s", name);
error(s);
} }
// put a Function Name // put a Function Name
@ -734,13 +730,7 @@ void SortSymbolTable(void)
} }
if (k >= nFuncs) { if (k >= nFuncs) {
char s[256]; tcc_error("debug (sort) info can't find function: %s", name2);
sprintf(s,
"debug (sort) info can't find function: %s",
name2);
error(s);
} }
if (strcmp(AssociatedFile[k], name) == 0) { if (strcmp(AssociatedFile[k], name) == 0) {
@ -767,7 +757,7 @@ void SortSymbolTable(void)
} }
if (n != nb_syms) if (n != nb_syms)
error("Internal Compiler error, debug info"); tcc_error("Internal Compiler error, debug info");
// copy it all back // copy it all back
@ -864,7 +854,7 @@ Section *FindSection(TCCState * s1, const char *sname)
return s; return s;
} }
error("could not find section %s", sname); tcc_error("could not find section %s", sname);
return 0; return 0;
} }
@ -882,39 +872,39 @@ ST_FUNC int tcc_load_coff(TCCState * s1, int fd)
f = fdopen(fd, "rb"); f = fdopen(fd, "rb");
if (!f) { if (!f) {
error("Unable to open .out file for input"); tcc_error("Unable to open .out file for input");
} }
if (fread(&file_hdr, FILHSZ, 1, f) != 1) if (fread(&file_hdr, FILHSZ, 1, f) != 1)
error("error reading .out file for input"); tcc_error("error reading .out file for input");
if (fread(&o_filehdr, sizeof(o_filehdr), 1, f) != 1) if (fread(&o_filehdr, sizeof(o_filehdr), 1, f) != 1)
error("error reading .out file for input"); tcc_error("error reading .out file for input");
// first read the string table // first read the string table
if (fseek(f, file_hdr.f_symptr + file_hdr.f_nsyms * SYMESZ, SEEK_SET)) if (fseek(f, file_hdr.f_symptr + file_hdr.f_nsyms * SYMESZ, SEEK_SET))
error("error reading .out file for input"); tcc_error("error reading .out file for input");
if (fread(&str_size, sizeof(int), 1, f) != 1) if (fread(&str_size, sizeof(int), 1, f) != 1)
error("error reading .out file for input"); tcc_error("error reading .out file for input");
Coff_str_table = (char *) tcc_malloc(str_size); Coff_str_table = (char *) tcc_malloc(str_size);
if (fread(Coff_str_table, str_size - 4, 1, f) != 1) if (fread(Coff_str_table, str_size - 4, 1, f) != 1)
error("error reading .out file for input"); tcc_error("error reading .out file for input");
// read/process all the symbols // read/process all the symbols
// seek back to symbols // seek back to symbols
if (fseek(f, file_hdr.f_symptr, SEEK_SET)) if (fseek(f, file_hdr.f_symptr, SEEK_SET))
error("error reading .out file for input"); tcc_error("error reading .out file for input");
for (i = 0; i < file_hdr.f_nsyms; i++) { for (i = 0; i < file_hdr.f_nsyms; i++) {
if (fread(&csym, SYMESZ, 1, f) != 1) if (fread(&csym, SYMESZ, 1, f) != 1)
error("error reading .out file for input"); tcc_error("error reading .out file for input");
if (csym._n._n_n._n_zeroes == 0) { if (csym._n._n_n._n_zeroes == 0) {
name = Coff_str_table + csym._n._n_n._n_offset - 4; name = Coff_str_table + csym._n._n_n._n_offset - 4;
@ -949,7 +939,7 @@ ST_FUNC int tcc_load_coff(TCCState * s1, int fd)
if (csym.n_numaux == 1) { if (csym.n_numaux == 1) {
if (fread(&csym, SYMESZ, 1, f) != 1) if (fread(&csym, SYMESZ, 1, f) != 1)
error("error reading .out file for input"); tcc_error("error reading .out file for input");
i++; i++;
} }
} }

View File

@ -166,7 +166,7 @@ static void *get_elf_sym_addr(TCCState *s, const char *name, int err)
sym = &((ElfW(Sym) *)symtab_section->data)[sym_index]; sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
if (!sym_index || sym->st_shndx == SHN_UNDEF) { if (!sym_index || sym->st_shndx == SHN_UNDEF) {
if (err) if (err)
error("%s not defined", name); tcc_error("%s not defined", name);
return NULL; return NULL;
} }
return (void*)(uplong)sym->st_value; return (void*)(uplong)sym->st_value;
@ -242,7 +242,7 @@ ST_FUNC int add_elf_sym(Section *s, uplong value, unsigned long size,
printf("new_bind=%x new_shndx=%x new_vis=%x old_bind=%x old_shndx=%x old_vis=%x\n", printf("new_bind=%x new_shndx=%x new_vis=%x old_bind=%x old_shndx=%x old_vis=%x\n",
sym_bind, sh_num, new_vis, esym_bind, esym->st_shndx, esym_vis); sym_bind, sh_num, new_vis, esym_bind, esym->st_shndx, esym_vis);
#endif #endif
error_noabort("'%s' defined twice", name); tcc_error_noabort("'%s' defined twice", name);
} }
} else { } else {
do_patch: do_patch:
@ -459,7 +459,7 @@ ST_FUNC void relocate_syms(TCCState *s1, int do_resolve)
if (sym_bind == STB_WEAK) { if (sym_bind == STB_WEAK) {
sym->st_value = 0; sym->st_value = 0;
} else { } else {
error_noabort("undefined symbol '%s'", name); tcc_error_noabort("undefined symbol '%s'", name);
} }
} else if (sh_num < SHN_LORESERVE) { } else if (sh_num < SHN_LORESERVE) {
/* add section base */ /* add section base */
@ -586,7 +586,7 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s)
case R_386_16: case R_386_16:
if (s1->output_format != TCC_OUTPUT_FORMAT_BINARY) { if (s1->output_format != TCC_OUTPUT_FORMAT_BINARY) {
output_file: output_file:
error("can only produce 16-bit binary files"); tcc_error("can only produce 16-bit binary files");
} }
*(short *)ptr += val; *(short *)ptr += val;
break; break;
@ -614,7 +614,7 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s)
x += add_jmp_table(s1, val) - val; /* add veneer */ x += add_jmp_table(s1, val) - val; /* add veneer */
#endif #endif
if((x & 3) != 0 || x >= 0x4000000 || x < -0x4000000) if((x & 3) != 0 || x >= 0x4000000 || x < -0x4000000)
error("can't relocate value at %x",addr); tcc_error("can't relocate value at %x",addr);
x >>= 2; x >>= 2;
x &= 0xffffff; x &= 0xffffff;
(*(int *)ptr) |= x; (*(int *)ptr) |= x;
@ -628,7 +628,7 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s)
x = (x * 2) / 2; x = (x * 2) / 2;
x += val - addr; x += val - addr;
if((x^(x>>1))&0x40000000) if((x^(x>>1))&0x40000000)
error("can't relocate value at %x",addr); tcc_error("can't relocate value at %x",addr);
(*(int *)ptr) |= x & 0x7fffffff; (*(int *)ptr) |= x & 0x7fffffff;
} }
case R_ARM_ABS32: case R_ARM_ABS32:
@ -728,7 +728,7 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s)
} }
#endif #endif
if (diff <= -2147483647 || diff > 2147483647) { if (diff <= -2147483647 || diff > 2147483647) {
error("internal error: relocation failed"); tcc_error("internal error: relocation failed");
} }
} }
*(int *)ptr += diff; *(int *)ptr += diff;
@ -837,7 +837,7 @@ static void put_got_offset(TCCState *s1, int index, unsigned long val)
n *= 2; n *= 2;
tab = tcc_realloc(s1->got_offsets, n * sizeof(unsigned long)); tab = tcc_realloc(s1->got_offsets, n * sizeof(unsigned long));
if (!tab) if (!tab)
error("memory full"); tcc_error("memory full");
s1->got_offsets = tab; s1->got_offsets = tab;
memset(s1->got_offsets + s1->nb_got_offsets, 0, memset(s1->got_offsets + s1->nb_got_offsets, 0,
(n - s1->nb_got_offsets) * sizeof(unsigned long)); (n - s1->nb_got_offsets) * sizeof(unsigned long));
@ -975,7 +975,7 @@ static void put_got_entry(TCCState *s1,
/* if we build a DLL, we add a %ebx offset */ /* if we build a DLL, we add a %ebx offset */
if (s1->output_type == TCC_OUTPUT_DLL) if (s1->output_type == TCC_OUTPUT_DLL)
error("DLLs unimplemented!"); tcc_error("DLLs unimplemented!");
/* add a PLT entry */ /* add a PLT entry */
plt = s1->plt; plt = s1->plt;
@ -1000,7 +1000,7 @@ static void put_got_entry(TCCState *s1,
offset = plt->data_offset - 16; offset = plt->data_offset - 16;
} }
#elif defined(TCC_TARGET_C67) #elif defined(TCC_TARGET_C67)
error("C67 got not implemented"); tcc_error("C67 got not implemented");
#else #else
#error unsupported CPU #error unsupported CPU
#endif #endif
@ -1543,7 +1543,7 @@ static int elf_output_file(TCCState *s1, const char *filename)
if (ELFW(ST_BIND)(sym->st_info) == STB_WEAK || if (ELFW(ST_BIND)(sym->st_info) == STB_WEAK ||
!strcmp(name, "_fp_hw")) { !strcmp(name, "_fp_hw")) {
} else { } else {
error_noabort("undefined symbol '%s'", name); tcc_error_noabort("undefined symbol '%s'", name);
} }
} }
} else if (s1->rdynamic && } else if (s1->rdynamic &&
@ -1581,7 +1581,7 @@ static int elf_output_file(TCCState *s1, const char *filename)
if (ELFW(ST_BIND)(esym->st_info) == STB_WEAK) { if (ELFW(ST_BIND)(esym->st_info) == STB_WEAK) {
/* weak symbols can stay undefined */ /* weak symbols can stay undefined */
} else { } else {
warning("undefined dynamic symbol '%s'", name); tcc_warning("undefined dynamic symbol '%s'", name);
} }
} }
} }
@ -2061,7 +2061,7 @@ static int elf_output_file(TCCState *s1, const char *filename)
unlink(filename); unlink(filename);
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, mode); fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, mode);
if (fd < 0) { if (fd < 0) {
error_noabort("could not write '%s'", filename); tcc_error_noabort("could not write '%s'", filename);
goto fail; goto fail;
} }
f = fdopen(fd, "wb"); f = fdopen(fd, "wb");
@ -2244,7 +2244,7 @@ ST_FUNC int tcc_load_object_file(TCCState *s1,
if (ehdr.e_ident[5] != ELFDATA2LSB || if (ehdr.e_ident[5] != ELFDATA2LSB ||
ehdr.e_machine != EM_TCC_TARGET) { ehdr.e_machine != EM_TCC_TARGET) {
fail1: fail1:
error_noabort("invalid object file"); tcc_error_noabort("invalid object file");
return -1; return -1;
} }
/* read sections */ /* read sections */
@ -2265,7 +2265,7 @@ ST_FUNC int tcc_load_object_file(TCCState *s1,
sh = &shdr[i]; sh = &shdr[i];
if (sh->sh_type == SHT_SYMTAB) { if (sh->sh_type == SHT_SYMTAB) {
if (symtab) { if (symtab) {
error_noabort("object must contain only one symtab"); tcc_error_noabort("object must contain only one symtab");
fail: fail:
ret = -1; ret = -1;
goto the_end; goto the_end;
@ -2329,7 +2329,7 @@ ST_FUNC int tcc_load_object_file(TCCState *s1,
sm_table[i].new_section = 1; sm_table[i].new_section = 1;
found: found:
if (sh->sh_type != s->sh_type) { if (sh->sh_type != s->sh_type) {
error_noabort("invalid section type"); tcc_error_noabort("invalid section type");
goto fail; goto fail;
} }
@ -2462,7 +2462,7 @@ ST_FUNC int tcc_load_object_file(TCCState *s1,
#endif #endif
) { ) {
invalid_reloc: invalid_reloc:
error_noabort("Invalid relocation entry [%2d] '%s' @ %.8x", tcc_error_noabort("Invalid relocation entry [%2d] '%s' @ %.8x",
i, strsec + sh->sh_name, rel->r_offset); i, strsec + sh->sh_name, rel->r_offset);
goto fail; goto fail;
} }
@ -2564,7 +2564,7 @@ ST_FUNC int tcc_load_archive(TCCState *s1, int fd)
if (len == 0) if (len == 0)
break; break;
if (len != sizeof(hdr)) { if (len != sizeof(hdr)) {
error_noabort("invalid archive"); tcc_error_noabort("invalid archive");
return -1; return -1;
} }
memcpy(ar_size, hdr.ar_size, sizeof(hdr.ar_size)); memcpy(ar_size, hdr.ar_size, sizeof(hdr.ar_size));
@ -2618,7 +2618,7 @@ ST_FUNC int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level)
/* test CPU specific stuff */ /* test CPU specific stuff */
if (ehdr.e_ident[5] != ELFDATA2LSB || if (ehdr.e_ident[5] != ELFDATA2LSB ||
ehdr.e_machine != EM_TCC_TARGET) { ehdr.e_machine != EM_TCC_TARGET) {
error_noabort("bad architecture"); tcc_error_noabort("bad architecture");
return -1; return -1;
} }
@ -2698,7 +2698,7 @@ ST_FUNC int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level)
goto already_loaded; goto already_loaded;
} }
if (tcc_add_dll(s1, name, AFF_REFERENCED_DLL) < 0) { if (tcc_add_dll(s1, name, AFF_REFERENCED_DLL) < 0) {
error_noabort("referenced dll '%s' not found", name); tcc_error_noabort("referenced dll '%s' not found", name);
ret = -1; ret = -1;
goto the_end; goto the_end;
} }
@ -2921,7 +2921,7 @@ static int ld_add_file_list(TCCState *s1, const char *cmd, int as_needed)
for(;;) { for(;;) {
libname[0] = '\0'; libname[0] = '\0';
if (t == LD_TOK_EOF) { if (t == LD_TOK_EOF) {
error_noabort("unexpected end of file"); tcc_error_noabort("unexpected end of file");
ret = -1; ret = -1;
goto lib_parse_error; goto lib_parse_error;
} else if (t == ')') { } else if (t == ')') {
@ -2929,14 +2929,14 @@ static int ld_add_file_list(TCCState *s1, const char *cmd, int as_needed)
} else if (t == '-') { } else if (t == '-') {
t = ld_next(s1, filename, sizeof(filename)); t = ld_next(s1, filename, sizeof(filename));
if ((t != LD_TOK_NAME) || (filename[0] != 'l')) { if ((t != LD_TOK_NAME) || (filename[0] != 'l')) {
error_noabort("library name expected"); tcc_error_noabort("library name expected");
ret = -1; ret = -1;
goto lib_parse_error; goto lib_parse_error;
} }
strcpy(libname, &filename[1]); strcpy(libname, &filename[1]);
libname_to_filename(s1, libname, filename); libname_to_filename(s1, libname, filename);
} else if (t != LD_TOK_NAME) { } else if (t != LD_TOK_NAME) {
error_noabort("filename expected"); tcc_error_noabort("filename expected");
ret = -1; ret = -1;
goto lib_parse_error; goto lib_parse_error;
} }
@ -3005,7 +3005,7 @@ ST_FUNC int tcc_load_ldscript(TCCState *s1)
for(;;) { for(;;) {
t = ld_next(s1, filename, sizeof(filename)); t = ld_next(s1, filename, sizeof(filename));
if (t == LD_TOK_EOF) { if (t == LD_TOK_EOF) {
error_noabort("unexpected end of file"); tcc_error_noabort("unexpected end of file");
return -1; return -1;
} else if (t == ')') { } else if (t == ')') {
break; break;

150
tccgen.c
View File

@ -294,7 +294,7 @@ static void vsetc(CType *type, int r, CValue *vc)
int v; int v;
if (vtop >= vstack + (VSTACK_SIZE - 1)) if (vtop >= vstack + (VSTACK_SIZE - 1))
error("memory full"); tcc_error("memory full");
/* cannot let cpu flags if other instruction are generated. Also /* cannot let cpu flags if other instruction are generated. Also
avoid leaving VT_JMP anywhere except on the top of the stack avoid leaving VT_JMP anywhere except on the top of the stack
because it would complicate the code generator. */ because it would complicate the code generator. */
@ -403,7 +403,7 @@ static Sym *external_sym(int v, CType *type, int r, char *asm_label)
s->r = r | VT_CONST | VT_SYM; s->r = r | VT_CONST | VT_SYM;
s->type.t |= VT_EXTERN; s->type.t |= VT_EXTERN;
} else if (!is_compatible_types(&s->type, type)) { } else if (!is_compatible_types(&s->type, type)) {
error("incompatible types for redefinition of '%s'", tcc_error("incompatible types for redefinition of '%s'",
get_tok_str(v, NULL)); get_tok_str(v, NULL));
} }
return s; return s;
@ -449,7 +449,7 @@ ST_FUNC void vswap(void)
ST_FUNC void vpushv(SValue *v) ST_FUNC void vpushv(SValue *v)
{ {
if (vtop >= vstack + (VSTACK_SIZE - 1)) if (vtop >= vstack + (VSTACK_SIZE - 1))
error("memory full"); tcc_error("memory full");
vtop++; vtop++;
*vtop = *v; *vtop = *v;
} }
@ -1260,7 +1260,7 @@ static void gen_opl(int op)
b = ind; b = ind;
o(0x1A000000 | encbranch(ind, 0, 1)); o(0x1A000000 | encbranch(ind, 0, 1));
#elif defined(TCC_TARGET_C67) #elif defined(TCC_TARGET_C67)
error("not implemented"); tcc_error("not implemented");
#else #else
#error not supported #error not supported
#endif #endif
@ -1333,7 +1333,7 @@ static void gen_opic(int op)
/* if division by zero, generate explicit division */ /* if division by zero, generate explicit division */
if (l2 == 0) { if (l2 == 0) {
if (const_wanted) if (const_wanted)
error("division by zero in constant"); tcc_error("division by zero in constant");
goto general_case; goto general_case;
} }
switch(op) { switch(op) {
@ -1460,7 +1460,7 @@ static void gen_opif(int op)
case '/': case '/':
if (f2 == 0.0) { if (f2 == 0.0) {
if (const_wanted) if (const_wanted)
error("division by zero in constant"); tcc_error("division by zero in constant");
goto general_case; goto general_case;
} }
f1 /= f2; f1 /= f2;
@ -1530,7 +1530,7 @@ static void check_comparison_pointer_types(SValue *p1, SValue *p2, int op)
/* accept comparison between pointer and integer with a warning */ /* accept comparison between pointer and integer with a warning */
if ((is_integer_btype(bt1) || is_integer_btype(bt2)) && op != '-') { if ((is_integer_btype(bt1) || is_integer_btype(bt2)) && op != '-') {
if (op != TOK_LOR && op != TOK_LAND ) if (op != TOK_LOR && op != TOK_LAND )
warning("comparison between pointer and integer"); tcc_warning("comparison between pointer and integer");
return; return;
} }
@ -1544,7 +1544,7 @@ static void check_comparison_pointer_types(SValue *p1, SValue *p2, int op)
type2 = pointed_type(type2); type2 = pointed_type(type2);
} else if (bt2 != VT_FUNC) { } else if (bt2 != VT_FUNC) {
invalid_operands: invalid_operands:
error("invalid operands to binary %s", get_tok_str(op, NULL)); tcc_error("invalid operands to binary %s", get_tok_str(op, NULL));
} }
if ((type1->t & VT_BTYPE) == VT_VOID || if ((type1->t & VT_BTYPE) == VT_VOID ||
(type2->t & VT_BTYPE) == VT_VOID) (type2->t & VT_BTYPE) == VT_VOID)
@ -1558,7 +1558,7 @@ static void check_comparison_pointer_types(SValue *p1, SValue *p2, int op)
if (op == '-') if (op == '-')
goto invalid_operands; goto invalid_operands;
else else
warning("comparison of distinct pointer types lacks a cast"); tcc_warning("comparison of distinct pointer types lacks a cast");
} }
} }
@ -1589,7 +1589,7 @@ ST_FUNC void gen_op(int op)
/* if both pointers, then it must be the '-' op */ /* if both pointers, then it must be the '-' op */
if (bt1 == VT_PTR && bt2 == VT_PTR) { if (bt1 == VT_PTR && bt2 == VT_PTR) {
if (op != '-') if (op != '-')
error("cannot use pointers here"); tcc_error("cannot use pointers here");
check_comparison_pointer_types(vtop - 1, vtop, op); check_comparison_pointer_types(vtop - 1, vtop, op);
/* XXX: check that types are compatible */ /* XXX: check that types are compatible */
if (vtop[-1].type.t & VT_VLA) { if (vtop[-1].type.t & VT_VLA) {
@ -1610,7 +1610,7 @@ ST_FUNC void gen_op(int op)
} else { } else {
/* exactly one pointer : must be '+' or '-'. */ /* exactly one pointer : must be '+' or '-'. */
if (op != '-' && op != '+') if (op != '-' && op != '+')
error("cannot use pointers here"); tcc_error("cannot use pointers here");
/* Put pointer as first operand */ /* Put pointer as first operand */
if (bt2 == VT_PTR) { if (bt2 == VT_PTR) {
vswap(); vswap();
@ -1623,7 +1623,7 @@ ST_FUNC void gen_op(int op)
else { else {
u = pointed_size(&vtop[-1].type); u = pointed_size(&vtop[-1].type);
if (u < 0) if (u < 0)
error("unknown array element size"); tcc_error("unknown array element size");
#ifdef TCC_TARGET_X86_64 #ifdef TCC_TARGET_X86_64
vpushll(u); vpushll(u);
#else #else
@ -1664,7 +1664,7 @@ ST_FUNC void gen_op(int op)
/* floats can only be used for a few operations */ /* floats can only be used for a few operations */
if (op != '+' && op != '-' && op != '*' && op != '/' && if (op != '+' && op != '-' && op != '*' && op != '/' &&
(op < TOK_ULT || op > TOK_GT)) (op < TOK_ULT || op > TOK_GT))
error("invalid operands for binary operation"); tcc_error("invalid operands for binary operation");
goto std_op; goto std_op;
} else if (bt1 == VT_LLONG || bt2 == VT_LLONG) { } else if (bt1 == VT_LLONG || bt2 == VT_LLONG) {
/* cast to biggest op */ /* cast to biggest op */
@ -1962,7 +1962,7 @@ static void gen_cast(CType *type)
(dbt & VT_BTYPE) == VT_SHORT) { (dbt & VT_BTYPE) == VT_SHORT) {
if (sbt == VT_PTR) { if (sbt == VT_PTR) {
vtop->type.t = VT_INT; vtop->type.t = VT_INT;
warning("nonportable conversion from pointer to char/short"); tcc_warning("nonportable conversion from pointer to char/short");
} }
force_charshort_cast(dbt); force_charshort_cast(dbt);
} else if ((dbt & VT_BTYPE) == VT_INT) { } else if ((dbt & VT_BTYPE) == VT_INT) {
@ -2259,7 +2259,7 @@ static void gen_assign_cast(CType *dt)
dbt = dt->t & VT_BTYPE; dbt = dt->t & VT_BTYPE;
sbt = st->t & VT_BTYPE; sbt = st->t & VT_BTYPE;
if (dt->t & VT_CONSTANT) if (dt->t & VT_CONSTANT)
warning("assignment of read-only location"); tcc_warning("assignment of read-only location");
switch(dbt) { switch(dbt) {
case VT_PTR: case VT_PTR:
/* special cases for pointers */ /* special cases for pointers */
@ -2268,7 +2268,7 @@ static void gen_assign_cast(CType *dt)
goto type_ok; goto type_ok;
/* accept implicit pointer to integer cast with warning */ /* accept implicit pointer to integer cast with warning */
if (is_integer_btype(sbt)) { if (is_integer_btype(sbt)) {
warning("assignment makes pointer from integer without a cast"); tcc_warning("assignment makes pointer from integer without a cast");
goto type_ok; goto type_ok;
} }
type1 = pointed_type(dt); type1 = pointed_type(dt);
@ -2276,7 +2276,7 @@ static void gen_assign_cast(CType *dt)
if (sbt == VT_FUNC) { if (sbt == VT_FUNC) {
if ((type1->t & VT_BTYPE) != VT_VOID && if ((type1->t & VT_BTYPE) != VT_VOID &&
!is_compatible_types(pointed_type(dt), st)) !is_compatible_types(pointed_type(dt), st))
warning("assignment from incompatible pointer type"); tcc_warning("assignment from incompatible pointer type");
goto type_ok; goto type_ok;
} }
if (sbt != VT_PTR) if (sbt != VT_PTR)
@ -2292,19 +2292,19 @@ static void gen_assign_cast(CType *dt)
tmp_type1.t &= ~(VT_UNSIGNED | VT_CONSTANT | VT_VOLATILE); tmp_type1.t &= ~(VT_UNSIGNED | VT_CONSTANT | VT_VOLATILE);
tmp_type2.t &= ~(VT_UNSIGNED | VT_CONSTANT | VT_VOLATILE); tmp_type2.t &= ~(VT_UNSIGNED | VT_CONSTANT | VT_VOLATILE);
if (!is_compatible_types(&tmp_type1, &tmp_type2)) if (!is_compatible_types(&tmp_type1, &tmp_type2))
warning("assignment from incompatible pointer type"); tcc_warning("assignment from incompatible pointer type");
} }
/* check const and volatile */ /* check const and volatile */
if ((!(type1->t & VT_CONSTANT) && (type2->t & VT_CONSTANT)) || if ((!(type1->t & VT_CONSTANT) && (type2->t & VT_CONSTANT)) ||
(!(type1->t & VT_VOLATILE) && (type2->t & VT_VOLATILE))) (!(type1->t & VT_VOLATILE) && (type2->t & VT_VOLATILE)))
warning("assignment discards qualifiers from pointer target type"); tcc_warning("assignment discards qualifiers from pointer target type");
break; break;
case VT_BYTE: case VT_BYTE:
case VT_SHORT: case VT_SHORT:
case VT_INT: case VT_INT:
case VT_LLONG: case VT_LLONG:
if (sbt == VT_PTR || sbt == VT_FUNC) { if (sbt == VT_PTR || sbt == VT_FUNC) {
warning("assignment makes integer from pointer without a cast"); tcc_warning("assignment makes integer from pointer without a cast");
} }
/* XXX: more tests */ /* XXX: more tests */
break; break;
@ -2317,7 +2317,7 @@ static void gen_assign_cast(CType *dt)
error: error:
type_to_str(buf1, sizeof(buf1), st, NULL); type_to_str(buf1, sizeof(buf1), st, NULL);
type_to_str(buf2, sizeof(buf2), dt, NULL); type_to_str(buf2, sizeof(buf2), dt, NULL);
error("cannot cast '%s' to '%s'", buf1, buf2); tcc_error("cannot cast '%s' to '%s'", buf1, buf2);
} }
break; break;
} }
@ -2340,7 +2340,7 @@ ST_FUNC void vstore(void)
vtop->type.t = ft & (VT_TYPE & ~(VT_BITFIELD | (-1 << VT_STRUCT_SHIFT))); vtop->type.t = ft & (VT_TYPE & ~(VT_BITFIELD | (-1 << VT_STRUCT_SHIFT)));
/* XXX: factorize */ /* XXX: factorize */
if (ft & VT_CONSTANT) if (ft & VT_CONSTANT)
warning("assignment of read-only location"); tcc_warning("assignment of read-only location");
} else { } else {
delayed_cast = 0; delayed_cast = 0;
if (!(ft & VT_BITFIELD)) if (!(ft & VT_BITFIELD))
@ -2551,7 +2551,7 @@ static void parse_attribute(AttributeDef *ad)
next(); next();
n = expr_const(); n = expr_const();
if (n <= 0 || (n & (n - 1)) != 0) if (n <= 0 || (n & (n - 1)) != 0)
error("alignment must be a positive power of two"); tcc_error("alignment must be a positive power of two");
skip(')'); skip(')');
} else { } else {
n = MAX_ALIGN; n = MAX_ALIGN;
@ -2618,7 +2618,7 @@ static void parse_attribute(AttributeDef *ad)
ad->mode = VT_INT + 1; ad->mode = VT_INT + 1;
break; break;
default: default:
warning("__mode__(%s) not supported\n", get_tok_str(tok, NULL)); tcc_warning("__mode__(%s) not supported\n", get_tok_str(tok, NULL));
break; break;
} }
next(); next();
@ -2632,7 +2632,7 @@ static void parse_attribute(AttributeDef *ad)
break; break;
default: default:
if (tcc_state->warn_unsupported) if (tcc_state->warn_unsupported)
warning("'%s' attribute ignored", get_tok_str(t, NULL)); tcc_warning("'%s' attribute ignored", get_tok_str(t, NULL));
/* skip parameters */ /* skip parameters */
if (tok == '(') { if (tok == '(') {
int parenthesis = 0; int parenthesis = 0;
@ -2675,7 +2675,7 @@ static void struct_decl(CType *type, int u)
s = struct_find(v); s = struct_find(v);
if (s) { if (s) {
if (s->type.t != a) if (s->type.t != a)
error("invalid type"); tcc_error("invalid type");
goto do_decl; goto do_decl;
} }
} else { } else {
@ -2693,7 +2693,7 @@ static void struct_decl(CType *type, int u)
if (tok == '{') { if (tok == '{') {
next(); next();
if (s->c != -1) if (s->c != -1)
error("struct/union/enum already defined"); tcc_error("struct/union/enum already defined");
/* cannot be empty */ /* cannot be empty */
c = 0; c = 0;
/* non empty enums are not allowed */ /* non empty enums are not allowed */
@ -2737,7 +2737,7 @@ static void struct_decl(CType *type, int u)
expect("identifier"); expect("identifier");
if ((type1.t & VT_BTYPE) == VT_FUNC || if ((type1.t & VT_BTYPE) == VT_FUNC ||
(type1.t & (VT_TYPEDEF | VT_STATIC | VT_EXTERN | VT_INLINE))) (type1.t & (VT_TYPEDEF | VT_STATIC | VT_EXTERN | VT_INLINE)))
error("invalid type for '%s'", tcc_error("invalid type for '%s'",
get_tok_str(v, NULL)); get_tok_str(v, NULL));
} }
if (tok == ':') { if (tok == ':') {
@ -2745,10 +2745,10 @@ static void struct_decl(CType *type, int u)
bit_size = expr_const(); bit_size = expr_const();
/* XXX: handle v = 0 case for messages */ /* XXX: handle v = 0 case for messages */
if (bit_size < 0) if (bit_size < 0)
error("negative width in bit-field '%s'", tcc_error("negative width in bit-field '%s'",
get_tok_str(v, NULL)); get_tok_str(v, NULL));
if (v && bit_size == 0) if (v && bit_size == 0)
error("zero width for bit-field '%s'", tcc_error("zero width for bit-field '%s'",
get_tok_str(v, NULL)); get_tok_str(v, NULL));
} }
size = type_size(&type1, &align); size = type_size(&type1, &align);
@ -2770,10 +2770,10 @@ static void struct_decl(CType *type, int u)
bt != VT_BOOL && bt != VT_BOOL &&
bt != VT_ENUM && bt != VT_ENUM &&
bt != VT_LLONG) bt != VT_LLONG)
error("bitfields must have scalar type"); tcc_error("bitfields must have scalar type");
bsize = size * 8; bsize = size * 8;
if (bit_size > bsize) { if (bit_size > bsize) {
error("width of '%s' exceeds its type", tcc_error("width of '%s' exceeds its type",
get_tok_str(v, NULL)); get_tok_str(v, NULL));
} else if (bit_size == bsize) { } else if (bit_size == bsize) {
/* no need for bit fields */ /* no need for bit fields */
@ -2883,7 +2883,7 @@ static int parse_btype(CType *type, AttributeDef *ad)
next(); next();
basic_type1: basic_type1:
if ((t & VT_BTYPE) != 0) if ((t & VT_BTYPE) != 0)
error("too many basic types"); tcc_error("too many basic types");
t |= u; t |= u;
typespec_found = 1; typespec_found = 1;
break; break;
@ -3036,7 +3036,7 @@ static int parse_btype(CType *type, AttributeDef *ad)
} }
the_end: the_end:
if ((t & (VT_SIGNED|VT_UNSIGNED)) == (VT_SIGNED|VT_UNSIGNED)) if ((t & (VT_SIGNED|VT_UNSIGNED)) == (VT_SIGNED|VT_UNSIGNED))
error("signed and unsigned modifier"); tcc_error("signed and unsigned modifier");
if (tcc_state->char_is_unsigned) { if (tcc_state->char_is_unsigned) {
if ((t & (VT_SIGNED|VT_UNSIGNED|VT_BTYPE)) == VT_BYTE) if ((t & (VT_SIGNED|VT_UNSIGNED|VT_BTYPE)) == VT_BYTE)
t |= VT_UNSIGNED; t |= VT_UNSIGNED;
@ -3115,7 +3115,7 @@ static void post_type(CType *type, AttributeDef *ad)
if (l != FUNC_OLD) { if (l != FUNC_OLD) {
if (!parse_btype(&pt, &ad1)) { if (!parse_btype(&pt, &ad1)) {
if (l) { if (l) {
error("invalid type"); tcc_error("invalid type");
} else { } else {
l = FUNC_OLD; l = FUNC_OLD;
goto old_proto; goto old_proto;
@ -3126,7 +3126,7 @@ static void post_type(CType *type, AttributeDef *ad)
break; break;
type_decl(&pt, &ad1, &n, TYPE_DIRECT | TYPE_ABSTRACT); type_decl(&pt, &ad1, &n, TYPE_DIRECT | TYPE_ABSTRACT);
if ((pt.t & VT_BTYPE) == VT_VOID) if ((pt.t & VT_BTYPE) == VT_VOID)
error("parameter declared as void"); tcc_error("parameter declared as void");
arg_size += (type_size(&pt, &align) + PTR_SIZE - 1) / PTR_SIZE; arg_size += (type_size(&pt, &align) + PTR_SIZE - 1) / PTR_SIZE;
} else { } else {
old_proto: old_proto:
@ -3185,10 +3185,10 @@ static void post_type(CType *type, AttributeDef *ad)
if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) { if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
n = vtop->c.i; n = vtop->c.i;
if (n < 0) if (n < 0)
error("invalid array size"); tcc_error("invalid array size");
} else { } else {
if (!is_integer_btype(vtop->type.t & VT_BTYPE)) if (!is_integer_btype(vtop->type.t & VT_BTYPE))
error("size of variable length array should be an integer"); tcc_error("size of variable length array should be an integer");
t1 = VT_VLA; t1 = VT_VLA;
} }
} }
@ -3358,7 +3358,7 @@ static void gfunc_param_typed(Sym *func, Sym *arg)
gen_cast(&type); gen_cast(&type);
} }
} else if (arg == NULL) { } else if (arg == NULL) {
error("too many arguments to function"); tcc_error("too many arguments to function");
} else { } else {
type = arg->type; type = arg->type;
type.t &= ~VT_CONSTANT; /* need to do that to avoid false warning */ type.t &= ~VT_CONSTANT; /* need to do that to avoid false warning */
@ -3571,7 +3571,7 @@ ST_FUNC void unary(void)
/* in order to force cast, we add zero */ /* in order to force cast, we add zero */
unary(); unary();
if ((vtop->type.t & VT_BTYPE) == VT_PTR) if ((vtop->type.t & VT_BTYPE) == VT_PTR)
error("pointer not accepted for unary plus"); tcc_error("pointer not accepted for unary plus");
vpushi(0); vpushi(0);
gen_op('+'); gen_op('+');
break; break;
@ -3586,7 +3586,7 @@ ST_FUNC void unary(void)
if (t == TOK_SIZEOF) { if (t == TOK_SIZEOF) {
if (!(type.t & VT_VLA)) { if (!(type.t & VT_VLA)) {
if (size < 0) if (size < 0)
error("sizeof applied to an incomplete type"); tcc_error("sizeof applied to an incomplete type");
vpushi(size); vpushi(size);
} else { } else {
vla_runtime_type_size(&type, &align); vla_runtime_type_size(&type, &align);
@ -3632,10 +3632,10 @@ ST_FUNC void unary(void)
next(); next();
skip('('); skip('(');
if (tok != TOK_CINT) { if (tok != TOK_CINT) {
error("__builtin_frame_address only takes integers"); tcc_error("__builtin_frame_address only takes integers");
} }
if (tokc.i != 0) { if (tokc.i != 0) {
error("TCC only supports __builtin_frame_address(0)"); tcc_error("TCC only supports __builtin_frame_address(0)");
} }
next(); next();
skip(')'); skip(')');
@ -3728,11 +3728,11 @@ ST_FUNC void unary(void)
s = sym_find(t); s = sym_find(t);
if (!s) { if (!s) {
if (tok != '(') if (tok != '(')
error("'%s' undeclared", get_tok_str(t, NULL)); tcc_error("'%s' undeclared", get_tok_str(t, NULL));
/* for simple function calls, we tolerate undeclared /* for simple function calls, we tolerate undeclared
external reference to int() function */ external reference to int() function */
if (tcc_state->warn_implicit_function_declaration) if (tcc_state->warn_implicit_function_declaration)
warning("implicit declaration of function '%s'", tcc_warning("implicit declaration of function '%s'",
get_tok_str(t, NULL)); get_tok_str(t, NULL));
s = external_global_sym(t, &func_old_type, 0); s = external_global_sym(t, &func_old_type, 0);
} }
@ -3783,7 +3783,7 @@ ST_FUNC void unary(void)
break; break;
} }
if (!s) if (!s)
error("field not found: %s", get_tok_str(tok & ~SYM_FIELD, NULL)); tcc_error("field not found: %s", get_tok_str(tok & ~SYM_FIELD, NULL));
/* add field offset to pointer */ /* add field offset to pointer */
vtop->type = char_pointer_type; /* change type to 'char *' */ vtop->type = char_pointer_type; /* change type to 'char *' */
vpushi(s->c); vpushi(s->c);
@ -3869,7 +3869,7 @@ ST_FUNC void unary(void)
} }
} }
if (sa) if (sa)
error("too few arguments to function"); tcc_error("too few arguments to function");
skip(')'); skip(')');
if (!nocode_wanted) { if (!nocode_wanted) {
gfunc_call(nb_args); gfunc_call(nb_args);
@ -4383,7 +4383,7 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym,
case VT_FUNC: case VT_FUNC:
for(p=vtop->type.ref;p;p=p->prev) for(p=vtop->type.ref;p;p=p->prev)
if(p->prev==s) if(p->prev==s)
error("unsupported expression type"); tcc_error("unsupported expression type");
} }
} }
/* pop locally defined symbols */ /* pop locally defined symbols */
@ -4441,14 +4441,14 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym,
} else if (tok == TOK_BREAK) { } else if (tok == TOK_BREAK) {
/* compute jump */ /* compute jump */
if (!bsym) if (!bsym)
error("cannot break"); tcc_error("cannot break");
*bsym = gjmp(*bsym); *bsym = gjmp(*bsym);
next(); next();
skip(';'); skip(';');
} else if (tok == TOK_CONTINUE) { } else if (tok == TOK_CONTINUE) {
/* compute jump */ /* compute jump */
if (!csym) if (!csym)
error("cannot continue"); tcc_error("cannot continue");
*csym = gjmp(*csym); *csym = gjmp(*csym);
next(); next();
skip(';'); skip(';');
@ -4537,7 +4537,7 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym,
next(); next();
v2 = expr_const(); v2 = expr_const();
if (v2 < v1) if (v2 < v1)
warning("empty case range"); tcc_warning("empty case range");
} }
/* since a case is like a label, we must skip it with a jmp */ /* since a case is like a label, we must skip it with a jmp */
b = gjmp(0); b = gjmp(0);
@ -4566,7 +4566,7 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym,
if (!def_sym) if (!def_sym)
expect("switch"); expect("switch");
if (*def_sym) if (*def_sym)
error("too many 'default'"); tcc_error("too many 'default'");
*def_sym = ind; *def_sym = ind;
is_expr = 0; is_expr = 0;
goto block_after_label; goto block_after_label;
@ -4608,7 +4608,7 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym,
s = label_find(b); s = label_find(b);
if (s) { if (s) {
if (s->r == LABEL_DEFINED) if (s->r == LABEL_DEFINED)
error("duplicate label '%s'", get_tok_str(s->v, NULL)); tcc_error("duplicate label '%s'", get_tok_str(s->v, NULL));
gsym(s->jnext); gsym(s->jnext);
s->r = LABEL_DEFINED; s->r = LABEL_DEFINED;
} else { } else {
@ -4618,7 +4618,7 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym,
/* we accept this, but it is a mistake */ /* we accept this, but it is a mistake */
block_after_label: block_after_label:
if (tok == '}') { if (tok == '}') {
warning("deprecated use of label at end of compound statement"); tcc_warning("deprecated use of label at end of compound statement");
} else { } else {
if (is_expr) if (is_expr)
vpop(); vpop();
@ -4730,7 +4730,7 @@ static void decl_designator(CType *type, Section *sec, unsigned long c,
} else { } else {
f = *cur_field; f = *cur_field;
if (!f) if (!f)
error("too many field init"); tcc_error("too many field init");
/* XXX: fix this mess by using explicit storage field */ /* XXX: fix this mess by using explicit storage field */
type1 = f->type; type1 = f->type;
type1.t |= (type->t & ~VT_TYPE); type1.t |= (type->t & ~VT_TYPE);
@ -4747,7 +4747,7 @@ static void decl_designator(CType *type, Section *sec, unsigned long c,
int i; int i;
if (!sec) if (!sec)
error("range init not supported yet for dynamic storage"); tcc_error("range init not supported yet for dynamic storage");
c_end = c + nb_elems * elem_size; c_end = c + nb_elems * elem_size;
if (c_end > sec->data_allocated) if (c_end > sec->data_allocated)
section_realloc(sec, c_end); section_realloc(sec, c_end);
@ -4785,7 +4785,7 @@ static void init_putv(CType *type, Section *sec, unsigned long c,
global_expr = saved_global_expr; global_expr = saved_global_expr;
/* NOTE: symbols are accepted */ /* NOTE: symbols are accepted */
if ((vtop->r & (VT_VALMASK | VT_LVAL)) != VT_CONST) if ((vtop->r & (VT_VALMASK | VT_LVAL)) != VT_CONST)
error("initializer element is not constant"); tcc_error("initializer element is not constant");
break; break;
case EXPR_ANY: case EXPR_ANY:
expr_eq(); expr_eq();
@ -4822,7 +4822,7 @@ static void init_putv(CType *type, Section *sec, unsigned long c,
bt == VT_LDOUBLE || bt == VT_LDOUBLE ||
bt == VT_LLONG || bt == VT_LLONG ||
(bt == VT_INT && bit_size != 32))) (bt == VT_INT && bit_size != 32)))
error("initializer element is not computable at load time"); tcc_error("initializer element is not computable at load time");
switch(bt) { switch(bt) {
case VT_BOOL: case VT_BOOL:
vtop->c.i = (vtop->c.i != 0); vtop->c.i = (vtop->c.i != 0);
@ -4901,7 +4901,7 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c,
vstore(); vstore();
vpop(); vpop();
#else #else
error("variable length arrays unsupported for this target"); tcc_error("variable length arrays unsupported for this target");
#endif #endif
} else if (type->t & VT_ARRAY) { } else if (type->t & VT_ARRAY) {
s = type->ref; s = type->ref;
@ -4914,7 +4914,7 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c,
if ((first && tok != TOK_LSTR && tok != TOK_STR) || if ((first && tok != TOK_LSTR && tok != TOK_STR) ||
tok == '{') { tok == '{') {
if (tok != '{') if (tok != '{')
error("character array initializer must be a literal," tcc_error("character array initializer must be a literal,"
" optionally enclosed in braces"); " optionally enclosed in braces");
skip('{'); skip('{');
no_oblock = 0; no_oblock = 0;
@ -4945,7 +4945,7 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c,
nb = n - array_length; nb = n - array_length;
if (!size_only) { if (!size_only) {
if (cstr_len > nb) if (cstr_len > nb)
warning("initializer-string for array is too long"); tcc_warning("initializer-string for array is too long");
/* in order to go faster for common case (char /* in order to go faster for common case (char
string in global variable, we handle it string in global variable, we handle it
specifically */ specifically */
@ -4978,7 +4978,7 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c,
while (tok != '}') { while (tok != '}') {
decl_designator(type, sec, c, &index, NULL, size_only); decl_designator(type, sec, c, &index, NULL, size_only);
if (n >= 0 && index >= n) if (n >= 0 && index >= n)
error("index too large"); tcc_error("index too large");
/* must put zero in holes (note that doing it that way /* must put zero in holes (note that doing it that way
ensures that it even works with designators) */ ensures that it even works with designators) */
if (!size_only && array_length < index) { if (!size_only && array_length < index) {
@ -5034,7 +5034,7 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c,
type_decl(&type1, &ad1, &n, TYPE_ABSTRACT); type_decl(&type1, &ad1, &n, TYPE_ABSTRACT);
#if 0 #if 0
if (!is_assignable_types(type, &type1)) if (!is_assignable_types(type, &type1))
error("invalid type for cast"); tcc_error("invalid type for cast");
#endif #endif
skip(')'); skip(')');
} }
@ -5162,7 +5162,7 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r,
tok_str_new(&init_str); tok_str_new(&init_str);
if (size < 0 || (flexible_array && has_init)) { if (size < 0 || (flexible_array && has_init)) {
if (!has_init) if (!has_init)
error("unknown type size"); tcc_error("unknown type size");
/* get all init string */ /* get all init string */
if (has_init == 2) { if (has_init == 2) {
/* only get strings */ /* only get strings */
@ -5174,7 +5174,7 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r,
level = 0; level = 0;
while (level > 0 || (tok != ',' && tok != ';')) { while (level > 0 || (tok != ',' && tok != ';')) {
if (tok < 0) if (tok < 0)
error("unexpected end of file in initializer"); tcc_error("unexpected end of file in initializer");
tok_str_add_tok(&init_str); tok_str_add_tok(&init_str);
if (tok == '{') if (tok == '{')
level++; level++;
@ -5204,7 +5204,7 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r,
/* if still unknown size, error */ /* if still unknown size, error */
size = type_size(type, &align); size = type_size(type, &align);
if (size < 0) if (size < 0)
error("unknown type size"); tcc_error("unknown type size");
} }
if (flexible_array) if (flexible_array)
size += flexible_array->type.ref->c * pointed_size(&flexible_array->type); size += flexible_array->type.ref->c * pointed_size(&flexible_array->type);
@ -5254,7 +5254,7 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r,
sym = sym_find(v); sym = sym_find(v);
if (sym) { if (sym) {
if (!is_compatible_types(&sym->type, type)) if (!is_compatible_types(&sym->type, type))
error("incompatible types for redefinition of '%s'", tcc_error("incompatible types for redefinition of '%s'",
get_tok_str(v, NULL)); get_tok_str(v, NULL));
if (sym->type.t & VT_EXTERN) { if (sym->type.t & VT_EXTERN) {
/* if the variable is extern, it was not allocated */ /* if the variable is extern, it was not allocated */
@ -5413,12 +5413,12 @@ static void func_decl_list(Sym *func_sym)
goto found; goto found;
s = s->next; s = s->next;
} }
error("declaration for parameter '%s' but no such parameter", tcc_error("declaration for parameter '%s' but no such parameter",
get_tok_str(v, NULL)); get_tok_str(v, NULL));
found: found:
/* check that no storage specifier except 'register' was given */ /* check that no storage specifier except 'register' was given */
if (type.t & VT_STORAGE) if (type.t & VT_STORAGE)
error("storage class specified for '%s'", get_tok_str(v, NULL)); tcc_error("storage class specified for '%s'", get_tok_str(v, NULL));
convert_parameter_type(&type); convert_parameter_type(&type);
/* we can add the type (NOTE: it could be local to the function) */ /* we can add the type (NOTE: it could be local to the function) */
s->type = type; s->type = type;
@ -5567,7 +5567,7 @@ static int decl0(int l, int is_for_loop_init)
#endif #endif
if ((type.t & VT_BTYPE) == VT_FUNC) { if ((type.t & VT_BTYPE) == VT_FUNC) {
if ((type.t & VT_STATIC) && (l == VT_LOCAL)) { if ((type.t & VT_STATIC) && (l == VT_LOCAL)) {
error("function without file scope cannot be static"); tcc_error("function without file scope cannot be static");
} }
/* if old style function prototype, we accept a /* if old style function prototype, we accept a
declaration list */ declaration list */
@ -5598,7 +5598,7 @@ static int decl0(int l, int is_for_loop_init)
#endif #endif
if (tok == '{') { if (tok == '{') {
if (l == VT_LOCAL) if (l == VT_LOCAL)
error("cannot use local functions"); tcc_error("cannot use local functions");
if ((type.t & VT_BTYPE) != VT_FUNC) if ((type.t & VT_BTYPE) != VT_FUNC)
expect("function definition"); expect("function definition");
@ -5633,7 +5633,7 @@ static int decl0(int l, int is_for_loop_init)
if (!is_compatible_types(&sym->type, &type)) { if (!is_compatible_types(&sym->type, &type)) {
func_error1: func_error1:
error("incompatible types for redefinition of '%s'", tcc_error("incompatible types for redefinition of '%s'",
get_tok_str(v, NULL)); get_tok_str(v, NULL));
} }
/* if symbol is already defined, then put complete type */ /* if symbol is already defined, then put complete type */
@ -5660,7 +5660,7 @@ static int decl0(int l, int is_for_loop_init)
for(;;) { for(;;) {
int t; int t;
if (tok == TOK_EOF) if (tok == TOK_EOF)
error("unexpected end of file"); tcc_error("unexpected end of file");
tok_str_add_tok(&func_str); tok_str_add_tok(&func_str);
t = tok; t = tok;
next(); next();
@ -5708,7 +5708,7 @@ static int decl0(int l, int is_for_loop_init)
} }
has_init = (tok == '='); has_init = (tok == '=');
if (has_init && (type.t & VT_VLA)) if (has_init && (type.t & VT_VLA))
error("Variable length array cannot be initialized"); tcc_error("Variable length array cannot be initialized");
if ((btype.t & VT_EXTERN) || ((type.t & VT_BTYPE) == VT_FUNC) || if ((btype.t & VT_EXTERN) || ((type.t & VT_BTYPE) == VT_FUNC) ||
((type.t & VT_ARRAY) && (type.t & VT_STATIC) && ((type.t & VT_ARRAY) && (type.t & VT_STATIC) &&
!has_init && l == VT_CONST && type.ref->c < 0)) { !has_init && l == VT_CONST && type.ref->c < 0)) {
@ -5728,7 +5728,7 @@ static int decl0(int l, int is_for_loop_init)
alias_target = sym_find(ad.alias_target); alias_target = sym_find(ad.alias_target);
if (!alias_target || !alias_target->c) if (!alias_target || !alias_target->c)
error("unsupported forward __alias__ attribute"); tcc_error("unsupported forward __alias__ attribute");
esym = &((Elf32_Sym *)symtab_section->data)[alias_target->c]; esym = &((Elf32_Sym *)symtab_section->data)[alias_target->c];
tsec.sh_num = esym->st_shndx; tsec.sh_num = esym->st_shndx;
put_extern_sym2(sym, &tsec, esym->st_value, esym->st_size, 0); put_extern_sym2(sym, &tsec, esym->st_value, esym->st_size, 0);

12
tccpe.c
View File

@ -595,7 +595,7 @@ static int pe_write(struct pe_info *pe)
op = fopen(pe->filename, "wb"); op = fopen(pe->filename, "wb");
if (NULL == op) { if (NULL == op) {
error_noabort("could not write '%s': %s", pe->filename, strerror(errno)); tcc_error_noabort("could not write '%s': %s", pe->filename, strerror(errno));
return -1; return -1;
} }
@ -841,7 +841,7 @@ static void pe_build_imports(struct pe_info *pe)
v = (ADDR3264)GetProcAddress(dllref->handle, name); v = (ADDR3264)GetProcAddress(dllref->handle, name);
} }
if (!v) if (!v)
error_noabort("undefined symbol '%s'", name); tcc_error_noabort("undefined symbol '%s'", name);
} }
#endif #endif
} else { } else {
@ -941,7 +941,7 @@ static void pe_build_exports(struct pe_info *pe)
strcpy(tcc_fileextension(buf), ".def"); strcpy(tcc_fileextension(buf), ".def");
op = fopen(buf, "w"); op = fopen(buf, "w");
if (NULL == op) { if (NULL == op) {
error_noabort("could not create '%s': %s", buf, strerror(errno)); tcc_error_noabort("could not create '%s': %s", buf, strerror(errno));
} else { } else {
fprintf(op, "LIBRARY %s\n\nEXPORTS\n", dllname); fprintf(op, "LIBRARY %s\n\nEXPORTS\n", dllname);
if (pe->s1->verbose) if (pe->s1->verbose)
@ -1287,7 +1287,7 @@ static int pe_check_symbols(struct pe_info *pe)
} }
not_found: not_found:
error_noabort("undefined symbol '%s'", name); tcc_error_noabort("undefined symbol '%s'", name);
ret = -1; ret = -1;
} else if (pe->s1->rdynamic } else if (pe->s1->rdynamic
@ -1774,7 +1774,7 @@ static void pe_add_runtime_ex(TCCState *s1, struct pe_info *pe)
if (PE_DLL != pe_type && PE_GUI != pe_type) if (PE_DLL != pe_type && PE_GUI != pe_type)
break; break;
} else if (tcc_add_library(s1, p) < 0) } else if (tcc_add_library(s1, p) < 0)
error_noabort("cannot find library: %s", p); tcc_error_noabort("cannot find library: %s", p);
} }
} }
@ -1871,7 +1871,7 @@ ST_FUNC int pe_output_file(TCCState * s1, const char *filename)
tcc_free(pe.sec_info); tcc_free(pe.sec_info);
} else { } else {
#ifndef TCC_IS_NATIVE #ifndef TCC_IS_NATIVE
error_noabort("-run supported only on native platform"); tcc_error_noabort("-run supported only on native platform");
#endif #endif
pe.thunk = data_section; pe.thunk = data_section;
pe_build_imports(&pe); pe_build_imports(&pe);

96
tccpp.c
View File

@ -90,13 +90,13 @@ static void macro_subst(
ST_FUNC void skip(int c) ST_FUNC void skip(int c)
{ {
if (tok != c) if (tok != c)
error("'%c' expected (got \"%s\")", c, get_tok_str(tok, &tokc)); tcc_error("'%c' expected (got \"%s\")", c, get_tok_str(tok, &tokc));
next(); next();
} }
ST_FUNC void expect(const char *msg) ST_FUNC void expect(const char *msg)
{ {
error("%s expected", msg); tcc_error("%s expected", msg);
} }
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
@ -113,7 +113,7 @@ static void cstr_realloc(CString *cstr, int new_size)
size = size * 2; size = size * 2;
data = tcc_realloc(cstr->data_allocated, size); data = tcc_realloc(cstr->data_allocated, size);
if (!data) if (!data)
error("memory full"); tcc_error("memory full");
cstr->data_allocated = data; cstr->data_allocated = data;
cstr->size_allocated = size; cstr->size_allocated = size;
cstr->data = data; cstr->data = data;
@ -194,14 +194,14 @@ static TokenSym *tok_alloc_new(TokenSym **pts, const char *str, int len)
int i; int i;
if (tok_ident >= SYM_FIRST_ANOM) if (tok_ident >= SYM_FIRST_ANOM)
error("memory full"); tcc_error("memory full");
/* expand token table if needed */ /* expand token table if needed */
i = tok_ident - TOK_IDENT; i = tok_ident - TOK_IDENT;
if ((i % TOK_ALLOC_INCR) == 0) { if ((i % TOK_ALLOC_INCR) == 0) {
ptable = tcc_realloc(table_ident, (i + TOK_ALLOC_INCR) * sizeof(TokenSym *)); ptable = tcc_realloc(table_ident, (i + TOK_ALLOC_INCR) * sizeof(TokenSym *));
if (!ptable) if (!ptable)
error("memory full"); tcc_error("memory full");
table_ident = ptable; table_ident = ptable;
} }
@ -424,7 +424,7 @@ static int handle_stray_noerror(void)
static void handle_stray(void) static void handle_stray(void)
{ {
if (handle_stray_noerror()) if (handle_stray_noerror())
error("stray '\\' in program"); tcc_error("stray '\\' in program");
} }
/* skip the stray and handle the \\n case. Output an error if /* skip the stray and handle the \\n case. Output an error if
@ -584,7 +584,7 @@ ST_FUNC uint8_t *parse_comment(uint8_t *p)
c = handle_eob(); c = handle_eob();
p = file->buf_ptr; p = file->buf_ptr;
if (c == CH_EOF) { if (c == CH_EOF) {
error("unexpected end of file in comment"); tcc_error("unexpected end of file in comment");
} else if (c == '\\') { } else if (c == '\\') {
p++; p++;
} }
@ -631,7 +631,7 @@ static uint8_t *parse_pp_string(uint8_t *p,
if (c == CH_EOF) { if (c == CH_EOF) {
unterminated_string: unterminated_string:
/* XXX: indicate line number of start of string */ /* XXX: indicate line number of start of string */
error("missing terminating %c character", sep); tcc_error("missing terminating %c character", sep);
} else if (c == '\\') { } else if (c == '\\') {
/* escape : just skip \[\r]\n */ /* escape : just skip \[\r]\n */
PEEKC_EOB(c, p); PEEKC_EOB(c, p);
@ -806,7 +806,7 @@ static inline int tok_ext_size(int t)
case TOK_STR: case TOK_STR:
case TOK_LSTR: case TOK_LSTR:
case TOK_PPNUM: case TOK_PPNUM:
error("unsupported token"); tcc_error("unsupported token");
return 1; return 1;
case TOK_CDOUBLE: case TOK_CDOUBLE:
case TOK_CLLONG: case TOK_CLLONG:
@ -845,7 +845,7 @@ static int *tok_str_realloc(TokenString *s)
} }
str = tcc_realloc(s->str, len * sizeof(int)); str = tcc_realloc(s->str, len * sizeof(int));
if (!str) if (!str)
error("memory full"); tcc_error("memory full");
s->allocated_len = len; s->allocated_len = len;
s->str = str; s->str = str;
return str; return str;
@ -1019,7 +1019,7 @@ ST_INLN void define_push(int v, int macro_type, int *str, Sym *first_arg)
s = define_find(v); s = define_find(v);
if (s && !macro_is_equal(s->d, str)) if (s && !macro_is_equal(s->d, str))
warning("%s redefined", get_tok_str(v, NULL)); tcc_warning("%s redefined", get_tok_str(v, NULL));
s = sym_push2(&define_stack, v, macro_type, 0); s = sym_push2(&define_stack, v, macro_type, 0);
s->d = str; s->d = str;
@ -1100,9 +1100,9 @@ ST_FUNC void label_pop(Sym **ptop, Sym *slast)
for(s = *ptop; s != slast; s = s1) { for(s = *ptop; s != slast; s = s1) {
s1 = s->prev; s1 = s->prev;
if (s->r == LABEL_DECLARED) { if (s->r == LABEL_DECLARED) {
warning("label '%s' declared but not used", get_tok_str(s->v, NULL)); tcc_warning("label '%s' declared but not used", get_tok_str(s->v, NULL));
} else if (s->r == LABEL_FORWARD) { } else if (s->r == LABEL_FORWARD) {
error("label '%s' used but not defined", tcc_error("label '%s' used but not defined",
get_tok_str(s->v, NULL)); get_tok_str(s->v, NULL));
} else { } else {
if (s->c) { if (s->c) {
@ -1181,7 +1181,7 @@ ST_FUNC void parse_define(void)
v = tok; v = tok;
if (v < TOK_IDENT) if (v < TOK_IDENT)
error("invalid macro name '%s'", get_tok_str(tok, &tokc)); tcc_error("invalid macro name '%s'", get_tok_str(tok, &tokc));
/* XXX: should check if same macro (ANSI) */ /* XXX: should check if same macro (ANSI) */
first = NULL; first = NULL;
t = MACRO_OBJ; t = MACRO_OBJ;
@ -1202,7 +1202,7 @@ ST_FUNC void parse_define(void)
next_nomacro(); next_nomacro();
} }
if (varg < TOK_IDENT) if (varg < TOK_IDENT)
error("badly punctuated parameter list"); tcc_error("badly punctuated parameter list");
s = sym_push2(&define_stack, varg | SYM_FIELD, is_vaargs, 0); s = sym_push2(&define_stack, varg | SYM_FIELD, is_vaargs, 0);
*ps = s; *ps = s;
ps = &s->next; ps = &s->next;
@ -1320,7 +1320,7 @@ static void pragma_parse(TCCState *s1)
next(); next();
if (s1->pack_stack_ptr <= s1->pack_stack) { if (s1->pack_stack_ptr <= s1->pack_stack) {
stk_error: stk_error:
error("out of pack stack"); tcc_error("out of pack stack");
} }
s1->pack_stack_ptr--; s1->pack_stack_ptr--;
} else { } else {
@ -1335,7 +1335,7 @@ static void pragma_parse(TCCState *s1)
} }
if (tok != TOK_CINT) { if (tok != TOK_CINT) {
pack_error: pack_error:
error("invalid pack pragma"); tcc_error("invalid pack pragma");
} }
val = tokc.i; val = tokc.i;
if (val < 1 || val > 16 || (val & (val - 1)) != 0) if (val < 1 || val > 16 || (val & (val - 1)) != 0)
@ -1412,7 +1412,7 @@ ST_FUNC void preprocess(int is_bof)
while (tok != TOK_LINEFEED) { while (tok != TOK_LINEFEED) {
if (tok != TOK_STR) { if (tok != TOK_STR) {
include_syntax: include_syntax:
error("'#include' expects \"FILENAME\" or <FILENAME>"); tcc_error("'#include' expects \"FILENAME\" or <FILENAME>");
} }
pstrcat(buf, sizeof(buf), (char *)tokc.cstr->data); pstrcat(buf, sizeof(buf), (char *)tokc.cstr->data);
next(); next();
@ -1435,7 +1435,7 @@ ST_FUNC void preprocess(int is_bof)
} }
if (s1->include_stack_ptr >= s1->include_stack + INCLUDE_STACK_SIZE) if (s1->include_stack_ptr >= s1->include_stack + INCLUDE_STACK_SIZE)
error("#include recursion too deep"); tcc_error("#include recursion too deep");
n = s1->nb_include_paths + s1->nb_sysinclude_paths; n = s1->nb_include_paths + s1->nb_sysinclude_paths;
for (i = -2; i < n; ++i) { for (i = -2; i < n; ++i) {
@ -1512,7 +1512,7 @@ ST_FUNC void preprocess(int is_bof)
ch = file->buf_ptr[0]; ch = file->buf_ptr[0];
goto the_end; goto the_end;
} }
error("include file '%s' not found", buf); tcc_error("include file '%s' not found", buf);
include_done: include_done:
break; break;
case TOK_IFNDEF: case TOK_IFNDEF:
@ -1526,7 +1526,7 @@ include_done:
do_ifdef: do_ifdef:
next_nomacro(); next_nomacro();
if (tok < TOK_IDENT) if (tok < TOK_IDENT)
error("invalid argument for '#if%sdef'", c ? "n" : ""); tcc_error("invalid argument for '#if%sdef'", c ? "n" : "");
if (is_bof) { if (is_bof) {
if (c) { if (c) {
#ifdef INC_DEBUG #ifdef INC_DEBUG
@ -1538,22 +1538,22 @@ include_done:
c = (define_find(tok) != 0) ^ c; c = (define_find(tok) != 0) ^ c;
do_if: do_if:
if (s1->ifdef_stack_ptr >= s1->ifdef_stack + IFDEF_STACK_SIZE) if (s1->ifdef_stack_ptr >= s1->ifdef_stack + IFDEF_STACK_SIZE)
error("memory full"); tcc_error("memory full");
*s1->ifdef_stack_ptr++ = c; *s1->ifdef_stack_ptr++ = c;
goto test_skip; goto test_skip;
case TOK_ELSE: case TOK_ELSE:
if (s1->ifdef_stack_ptr == s1->ifdef_stack) if (s1->ifdef_stack_ptr == s1->ifdef_stack)
error("#else without matching #if"); tcc_error("#else without matching #if");
if (s1->ifdef_stack_ptr[-1] & 2) if (s1->ifdef_stack_ptr[-1] & 2)
error("#else after #else"); tcc_error("#else after #else");
c = (s1->ifdef_stack_ptr[-1] ^= 3); c = (s1->ifdef_stack_ptr[-1] ^= 3);
goto test_else; goto test_else;
case TOK_ELIF: case TOK_ELIF:
if (s1->ifdef_stack_ptr == s1->ifdef_stack) if (s1->ifdef_stack_ptr == s1->ifdef_stack)
error("#elif without matching #if"); tcc_error("#elif without matching #if");
c = s1->ifdef_stack_ptr[-1]; c = s1->ifdef_stack_ptr[-1];
if (c > 1) if (c > 1)
error("#elif after #else"); tcc_error("#elif after #else");
/* last #if/#elif expression was true: we skip */ /* last #if/#elif expression was true: we skip */
if (c == 1) if (c == 1)
goto skip; goto skip;
@ -1572,7 +1572,7 @@ include_done:
break; break;
case TOK_ENDIF: case TOK_ENDIF:
if (s1->ifdef_stack_ptr <= file->ifdef_stack_ptr) if (s1->ifdef_stack_ptr <= file->ifdef_stack_ptr)
error("#endif without matching #if"); tcc_error("#endif without matching #if");
s1->ifdef_stack_ptr--; s1->ifdef_stack_ptr--;
/* '#ifndef macro' was at the start of file. Now we check if /* '#ifndef macro' was at the start of file. Now we check if
an '#endif' is exactly at the end of file */ an '#endif' is exactly at the end of file */
@ -1591,12 +1591,12 @@ include_done:
case TOK_LINE: case TOK_LINE:
next(); next();
if (tok != TOK_CINT) if (tok != TOK_CINT)
error("#line"); tcc_error("#line");
file->line_num = tokc.i - 1; /* the line number will be incremented after */ file->line_num = tokc.i - 1; /* the line number will be incremented after */
next(); next();
if (tok != TOK_LINEFEED) { if (tok != TOK_LINEFEED) {
if (tok != TOK_STR) if (tok != TOK_STR)
error("#line"); tcc_error("#line");
pstrcpy(file->filename, sizeof(file->filename), pstrcpy(file->filename, sizeof(file->filename),
(char *)tokc.cstr->data); (char *)tokc.cstr->data);
} }
@ -1618,9 +1618,9 @@ include_done:
} }
*q = '\0'; *q = '\0';
if (c == TOK_ERROR) if (c == TOK_ERROR)
error("#error %s", buf); tcc_error("#error %s", buf);
else else
warning("#warning %s", buf); tcc_warning("#warning %s", buf);
break; break;
case TOK_PRAGMA: case TOK_PRAGMA:
pragma_parse(s1); pragma_parse(s1);
@ -1631,7 +1631,7 @@ include_done:
to emulate cpp behaviour */ to emulate cpp behaviour */
} else { } else {
if (!(saved_parse_flags & PARSE_FLAG_ASM_COMMENTS)) if (!(saved_parse_flags & PARSE_FLAG_ASM_COMMENTS))
warning("Ignoring unknown preprocessing directive #%s", get_tok_str(tok, &tokc)); tcc_warning("Ignoring unknown preprocessing directive #%s", get_tok_str(tok, &tokc));
else { else {
/* this is a gas line comment in an 'S' file. */ /* this is a gas line comment in an 'S' file. */
file->buf_ptr = parse_line_comment(file->buf_ptr); file->buf_ptr = parse_line_comment(file->buf_ptr);
@ -1734,9 +1734,9 @@ static void parse_escape_string(CString *outstr, const uint8_t *buf, int is_long
default: default:
invalid_escape: invalid_escape:
if (c >= '!' && c <= '~') if (c >= '!' && c <= '~')
warning("unknown escape sequence: \'\\%c\'", c); tcc_warning("unknown escape sequence: \'\\%c\'", c);
else else
warning("unknown escape sequence: \'\\x%x\'", c); tcc_warning("unknown escape sequence: \'\\x%x\'", c);
break; break;
} }
} }
@ -1821,7 +1821,7 @@ static void parse_number(const char *p)
break; break;
if (q >= token_buf + STRING_MAX_SIZE) { if (q >= token_buf + STRING_MAX_SIZE) {
num_too_long: num_too_long:
error("number too long"); tcc_error("number too long");
} }
*q++ = ch; *q++ = ch;
ch = *p++; ch = *p++;
@ -1870,7 +1870,7 @@ static void parse_number(const char *p)
break; break;
} }
if (t >= b) if (t >= b)
error("invalid digit"); tcc_error("invalid digit");
bn_lshift(bn, shift, t); bn_lshift(bn, shift, t);
frac_bits += shift; frac_bits += shift;
ch = *p++; ch = *p++;
@ -1999,14 +1999,14 @@ static void parse_number(const char *p)
} else { } else {
t = t - '0'; t = t - '0';
if (t >= b) if (t >= b)
error("invalid digit"); tcc_error("invalid digit");
} }
n1 = n; n1 = n;
n = n * b + t; n = n * b + t;
/* detect overflow */ /* detect overflow */
/* XXX: this test is not reliable */ /* XXX: this test is not reliable */
if (n < n1) if (n < n1)
error("integer constant overflow"); tcc_error("integer constant overflow");
} }
/* XXX: not exactly ANSI compliant */ /* XXX: not exactly ANSI compliant */
@ -2026,7 +2026,7 @@ static void parse_number(const char *p)
t = toup(ch); t = toup(ch);
if (t == 'L') { if (t == 'L') {
if (lcount >= 2) if (lcount >= 2)
error("three 'l's in integer constant"); tcc_error("three 'l's in integer constant");
lcount++; lcount++;
if (lcount == 2) { if (lcount == 2) {
if (tok == TOK_CINT) if (tok == TOK_CINT)
@ -2037,7 +2037,7 @@ static void parse_number(const char *p)
ch = *p++; ch = *p++;
} else if (t == 'U') { } else if (t == 'U') {
if (ucount >= 1) if (ucount >= 1)
error("two 'u's in integer constant"); tcc_error("two 'u's in integer constant");
ucount++; ucount++;
if (tok == TOK_CINT) if (tok == TOK_CINT)
tok = TOK_CUINT; tok = TOK_CUINT;
@ -2054,7 +2054,7 @@ static void parse_number(const char *p)
tokc.ull = n; tokc.ull = n;
} }
if (ch) if (ch)
error("invalid number\n"); tcc_error("invalid number\n");
} }
@ -2119,7 +2119,7 @@ static inline void next_nomacro1(void)
} else if (!(parse_flags & PARSE_FLAG_PREPROCESS)) { } else if (!(parse_flags & PARSE_FLAG_PREPROCESS)) {
tok = TOK_EOF; tok = TOK_EOF;
} else if (s1->ifdef_stack_ptr != file->ifdef_stack_ptr) { } else if (s1->ifdef_stack_ptr != file->ifdef_stack_ptr) {
error("missing #endif"); tcc_error("missing #endif");
} else if (s1->include_stack_ptr == s1->include_stack) { } else if (s1->include_stack_ptr == s1->include_stack) {
/* no include left : end of file. */ /* no include left : end of file. */
tok = TOK_EOF; tok = TOK_EOF;
@ -2333,9 +2333,9 @@ maybe_newline:
else else
char_size = sizeof(nwchar_t); char_size = sizeof(nwchar_t);
if (tokcstr.size <= char_size) if (tokcstr.size <= char_size)
error("empty character constant"); tcc_error("empty character constant");
if (tokcstr.size > 2 * char_size) if (tokcstr.size > 2 * char_size)
warning("multi-character character constant"); tcc_warning("multi-character character constant");
if (!is_long) { if (!is_long) {
tokc.i = *(int8_t *)tokcstr.data; tokc.i = *(int8_t *)tokcstr.data;
tok = TOK_CCHAR; tok = TOK_CCHAR;
@ -2488,7 +2488,7 @@ maybe_newline:
p++; p++;
break; break;
default: default:
error("unrecognized character \\x%02x", c); tcc_error("unrecognized character \\x%02x", c);
break; break;
} }
tok_flags = 0; tok_flags = 0;
@ -2719,7 +2719,7 @@ static int macro_subst_tok(TokenString *tok_str,
if (!args && !sa && tok == ')') if (!args && !sa && tok == ')')
break; break;
if (!sa) if (!sa)
error("macro '%s' used with too many args", tcc_error("macro '%s' used with too many args",
get_tok_str(s->v, 0)); get_tok_str(s->v, 0));
tok_str_new(&str); tok_str_new(&str);
parlevel = spc = 0; parlevel = spc = 0;
@ -2756,7 +2756,7 @@ static int macro_subst_tok(TokenString *tok_str,
next_nomacro(); next_nomacro();
} }
if (sa) { if (sa) {
error("macro '%s' used with too few args", tcc_error("macro '%s' used with too few args",
get_tok_str(s->v, 0)); get_tok_str(s->v, 0));
} }
@ -2843,7 +2843,7 @@ static inline int *macro_twosharps(const int *macro_str)
if (0 == *file->buf_ptr) if (0 == *file->buf_ptr)
break; break;
tok_str_add2(&macro_str1, tok, &tokc); tok_str_add2(&macro_str1, tok, &tokc);
warning("pasting \"%.*s\" and \"%s\" does not give a valid preprocessing token", tcc_warning("pasting \"%.*s\" and \"%s\" does not give a valid preprocessing token",
n, cstr.data, (char*)cstr.data + n); n, cstr.data, (char*)cstr.data + n);
} }
tcc_close(); tcc_close();

View File

@ -58,13 +58,13 @@ LIBTCCAPI int tcc_relocate(TCCState *s1)
s1->write_mem = mmap (NULL, ret, PROT_READ|PROT_WRITE, s1->write_mem = mmap (NULL, ret, PROT_READ|PROT_WRITE,
MAP_SHARED, fd, 0); MAP_SHARED, fd, 0);
if(s1->write_mem == MAP_FAILED){ if(s1->write_mem == MAP_FAILED){
error("/tmp not writeable"); tcc_error("/tmp not writeable");
return -1; return -1;
} }
s1->runtime_mem = mmap (NULL, ret, PROT_READ|PROT_EXEC, s1->runtime_mem = mmap (NULL, ret, PROT_READ|PROT_EXEC,
MAP_SHARED, fd, 0); MAP_SHARED, fd, 0);
if(s1->runtime_mem == MAP_FAILED){ if(s1->runtime_mem == MAP_FAILED){
error("/tmp not executable"); tcc_error("/tmp not executable");
return -1; return -1;
} }
ret = tcc_relocate_ex(s1, s1->write_mem); ret = tcc_relocate_ex(s1, s1->write_mem);