Revert "lotsa debug printing."

This reverts commit 09cecc93442f2f3b7dbd1bb5faf18b41f42103ff.
This commit is contained in:
Jan Nieuwenhuizen 2019-03-31 23:06:58 +02:00
parent 62be8c851b
commit c6e4c31e4a
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
11 changed files with 69 additions and 1975 deletions

View File

@ -225,20 +225,12 @@ void o(uint32_t i)
if (ind1 > cur_text_section->data_allocated)
section_realloc(cur_text_section, ind1);
cur_text_section->data[ind++] = i&255;
trace ("o "); eputs (itoa (i&255)); eputs ("\n");
trace ("o "); eputs (itoa (cur_text_section->data[ind-1])); eputs ("\n");
i>>=8;
cur_text_section->data[ind++] = i&255;
trace ("o "); eputs (itoa (i&255)); eputs ("\n");
trace ("o "); eputs (itoa (cur_text_section->data[ind-1])); eputs ("\n");
i>>=8;
cur_text_section->data[ind++] = i&255;
trace ("o "); eputs (itoa (i&255)); eputs ("\n");
trace ("o "); eputs (itoa (cur_text_section->data[ind-1])); eputs ("\n");
i>>=8;
cur_text_section->data[ind++] = i;
trace ("o "); eputs (itoa (i)); eputs ("\n");
trace ("o "); eputs (itoa (cur_text_section->data[ind-1])); eputs ("\n");
}
static uint32_t stuff_const(uint32_t op, uint32_t c)

View File

@ -691,7 +691,6 @@ ST_FUNC void asm_opcode(TCCState *s1, int opcode)
int rex64;
#endif
trace_enter ("asm_opcode");
maybe_print_stats();
/* force synthetic ';' after prefix instruction, so we can handle */
/* one-line things like "rep stosb" instead of only "rep\nstosb" */
@ -704,7 +703,6 @@ ST_FUNC void asm_opcode(TCCState *s1, int opcode)
seg_prefix = 0;
alltypes = 0;
for(;;) {
trace ("asm_opcode 10 tok="); eputc (tok); eputs (" ["); eputs (itoa (tok)); eputs ("]\n");
if (tok == ';' || tok == TOK_LINEFEED)
break;
if (nb_ops >= MAX_OPERANDS) {
@ -712,7 +710,6 @@ ST_FUNC void asm_opcode(TCCState *s1, int opcode)
}
parse_operand(s1, pop);
if (tok == ':') {
trace ("tcc_assemble_internal 15\n");
if (pop->type != OP_SEG || seg_prefix)
tcc_error("incorrect prefix");
seg_prefix = segment_prefixes[pop->reg];
@ -726,7 +723,6 @@ ST_FUNC void asm_opcode(TCCState *s1, int opcode)
nb_ops++;
if (tok != ',')
break;
trace ("tcc_assemble_internal 28\n");
next();
}
@ -736,9 +732,6 @@ ST_FUNC void asm_opcode(TCCState *s1, int opcode)
!) */
for(pa = asm_instrs; pa->sym != 0; pa++) {
int it = pa->instr_type & OPCT_MASK;
trace ("asm_opcode 30 pa->instr_type="); eputs (itoa (pa->instr_type)); eputs ("\n");
trace ("asm_opcode 30 OPCT_MASK="); eputs (itoa (OPCT_MASK)); eputs ("\n");
trace ("asm_opcode 30 it="); eputs (itoa (it)); eputs ("\n");
s = 0;
if (it == OPC_FARITH) {
v = opcode - pa->sym;
@ -840,7 +833,6 @@ ST_FUNC void asm_opcode(TCCState *s1, int opcode)
break;
next: ;
}
trace ("tcc_assemble_internal 80\n");
if (pa->sym == 0) {
if (opcode >= TOK_ASM_first && opcode <= TOK_ASM_last) {
int b;
@ -848,7 +840,6 @@ ST_FUNC void asm_opcode(TCCState *s1, int opcode)
if (b & 0xff00)
g(b >> 8);
g(b);
trace_exit ("asm_opcode");
return;
} else if (opcode <= TOK_ASM_alllast) {
tcc_error("bad operand with opcode '%s'",
@ -858,7 +849,6 @@ ST_FUNC void asm_opcode(TCCState *s1, int opcode)
get_tok_str(opcode, NULL));
}
}
trace ("tcc_assemble_internal 90\n");
/* if the size is unknown, then evaluate it (OPC_B or OPC_WL case) */
autosize = NBWLX-1;
#ifdef TCC_TARGET_X86_64
@ -888,7 +878,6 @@ ST_FUNC void asm_opcode(TCCState *s1, int opcode)
}
}
trace ("tcc_assemble_internal 100\n");
#ifdef TCC_TARGET_X86_64
/* Generate addr32 prefix if needed */
for(i = 0; i < nb_ops; i++) {
@ -911,7 +900,6 @@ ST_FUNC void asm_opcode(TCCState *s1, int opcode)
&& ops[i].type & OP_SSE)
p66 = 1;
}
trace ("tcc_assemble_internal 120\n");
if (p66)
g(0x66);
#ifdef TCC_TARGET_X86_64
@ -941,14 +929,12 @@ ST_FUNC void asm_opcode(TCCState *s1, int opcode)
}
#endif
trace ("tcc_assemble_internal 130\n");
/* now generates the operation */
if (OPCT_IS(pa->instr_type, OPC_FWAIT))
g(0x9b);
if (seg_prefix)
g(seg_prefix);
trace ("tcc_assemble_internal 135\n");
v = pa->opcode;
if (pa->instr_type & OPC_0F)
v = ((v & ~0xff) << 8) | 0x0f00 | (v & 0xff);
@ -976,7 +962,6 @@ ST_FUNC void asm_opcode(TCCState *s1, int opcode)
v += ((opcode - pa->sym) / 6) << 3;
}
trace ("tcc_assemble_internal 150\n");
/* search which operand will be used for modrm */
modrm_index = -1;
modreg_index = -1;
@ -1020,7 +1005,6 @@ ST_FUNC void asm_opcode(TCCState *s1, int opcode)
asm_rex (rex64, ops, nb_ops, op_type, modreg_index, modrm_index);
#endif
trace ("tcc_assemble_internal 160\n");
if (pa->instr_type & OPC_REG) {
/* mov $im, %reg case */
if (v == 0xb0 && s >= 1)
@ -1032,7 +1016,6 @@ ST_FUNC void asm_opcode(TCCState *s1, int opcode)
}
}
}
trace ("tcc_assemble_internal 170\n");
if (pa->instr_type & OPC_B)
v += s >= 1;
if (nb_ops == 1 && pa->op_type[0] == OPT_DISP8) {
@ -1063,7 +1046,6 @@ ST_FUNC void asm_opcode(TCCState *s1, int opcode)
tcc_error("invalid displacement");
}
}
trace ("tcc_assemble_internal 180\n");
if (OPCT_IS(pa->instr_type, OPC_TEST))
v += test_bits[opcode - pa->sym];
op1 = v >> 16;
@ -1104,7 +1086,6 @@ ST_FUNC void asm_opcode(TCCState *s1, int opcode)
if (ops[0].e.sym)
tcc_error("cannot relocate");
gen_le16(ops[0].e.v);
trace_exit ("asm_opcode");
return;
}
#endif
@ -1146,7 +1127,6 @@ ST_FUNC void asm_opcode(TCCState *s1, int opcode)
/* after immediate operands, adjust pc-relative address */
if (pc)
add32le(cur_text_section->data + pc - 4, pc - ind);
trace_exit ("asm_opcode");
}
/* return the constraint priority (we allocate first the lowest
@ -1610,7 +1590,6 @@ ST_FUNC void asm_gen_code(ASMOperand *operands, int nb_operands,
ASMOperand *op;
int i, reg;
trace_enter ("asm_gen_code");
/* Strictly speaking %Xbp and %Xsp should be included in the
call-preserved registers, but currently it doesn't matter. */
#ifdef TCC_TARGET_X86_64
@ -1704,7 +1683,6 @@ ST_FUNC void asm_gen_code(ASMOperand *operands, int nb_operands,
}
}
}
trace_exit ("asm_gen_code");
}
ST_FUNC void asm_clobber(uint8_t *clobber_regs, const char *str)

View File

@ -99,8 +99,6 @@ static unsigned long func_bound_ind;
/* XXX: make it faster ? */
ST_FUNC void g(int c)
{
trace_enter ("g");
//trace ("gen o c="); eputs (itoab (c, 16)); eputs ("\n");
int ind1;
if (nocode_wanted)
return;
@ -108,9 +106,7 @@ ST_FUNC void g(int c)
if (ind1 > cur_text_section->data_allocated)
section_realloc(cur_text_section, ind1);
cur_text_section->data[ind] = c;
//trace ("gen o data="); eputs (itoab (cur_text_section->data[ind], 16)); eputs ("\n");
ind = ind1;
trace_exit ("g");
}
ST_FUNC void o(unsigned int c)
@ -210,7 +206,6 @@ ST_FUNC void load(int r, SValue *sv)
int v, t, ft, fc, fr;
SValue v1;
trace_enter ("load");
#ifdef TCC_TARGET_PE
SValue v2;
sv = pe_getimport(sv, &v2);
@ -282,7 +277,6 @@ ST_FUNC void load(int r, SValue *sv)
o(0xc0 + r + v * 8); /* mov v, r */
}
}
trace_exit ("load");
}
/* store register 'r' in lvalue 'v' */
@ -290,7 +284,6 @@ ST_FUNC void store(int r, SValue *v)
{
int fr, bt, ft, fc;
trace_enter ("store");
#ifdef TCC_TARGET_PE
SValue v2;
v = pe_getimport(v, &v2);
@ -327,7 +320,6 @@ ST_FUNC void store(int r, SValue *v)
} else if (fr != r) {
o(0xc0 + fr + r * 8); /* mov r, fr */
}
trace_exit ("store");
}
static void gadd_sp(int val)
@ -438,7 +430,6 @@ ST_FUNC void gfunc_call(int nb_args)
int size, align, r, args_size, i, func_call;
Sym *func_sym;
trace_enter ("gfunc_call");
args_size = 0;
for(i = 0;i < nb_args; i++) {
if ((vtop->type.t & VT_BTYPE) == VT_STRUCT) {
@ -518,7 +509,6 @@ ST_FUNC void gfunc_call(int nb_args)
if (args_size && func_call != FUNC_STDCALL)
gadd_sp(args_size);
vtop--;
trace_exit ("gfunc_call");
}
#ifdef TCC_TARGET_PE
@ -536,40 +526,30 @@ ST_FUNC void gfunc_prolog(CType *func_type)
Sym *sym;
CType *type;
trace_enter ("gfunc_prolog");
sym = func_type->ref;
func_call = sym->a.func_call;
addr = 8;
loc = 0;
func_vc = 0;
trace ("gfunc_prolog 10\n");
if (func_call >= FUNC_FASTCALL1 && func_call <= FUNC_FASTCALL3) {
trace ("gfunc_prolog 11\n");
fastcall_nb_regs = func_call - FUNC_FASTCALL1 + 1;
fastcall_regs_ptr = fastcall_regs;
} else if (func_call == FUNC_FASTCALLW) {
trace ("gfunc_prolog 15\n");
fastcall_nb_regs = 2;
fastcall_regs_ptr = fastcallw_regs;
} else {
trace ("gfunc_prolog 18\n");
fastcall_nb_regs = 0;
fastcall_regs_ptr = NULL;
}
param_index = 0;
trace ("gfunc_prolog 20\n");
ind += FUNC_PROLOG_SIZE;
trace ("gfunc_prolog 21\n");
func_sub_sp_offset = ind;
trace ("gfunc_prolog 22\n");
/* if the function returns a structure, then add an
implicit pointer parameter */
func_vt = sym->type;
trace ("gfunc_prolog 23\n");
func_var = (sym->c == FUNC_ELLIPSIS);
trace ("gfunc_prolog 24\n");
#ifdef TCC_TARGET_PE
size = type_size(&func_vt,&align);
if (((func_vt.t & VT_BTYPE) == VT_STRUCT)
@ -577,35 +557,29 @@ ST_FUNC void gfunc_prolog(CType *func_type)
#else
if ((func_vt.t & VT_BTYPE) == VT_STRUCT) {
#endif
trace ("gfunc_prolog 25\n");
/* XXX: fastcall case ? */
func_vc = addr;
addr += 4;
param_index++;
}
trace ("gfunc_prolog 30\n");
/* define parameters */
while ((sym = sym->next) != NULL) {
trace ("gfunc_prolog 31 param_index="); eputs (itoa (param_index)); eputs ("\n");
type = &sym->type;
size = type_size(type, &align);
size = (size + 3) & ~3;
#ifdef FUNC_STRUCT_PARAM_AS_PTR
/* structs are passed as pointer */
if ((type->t & VT_BTYPE) == VT_STRUCT) {
trace ("gfunc_prolog 36\n");
size = 4;
}
#endif
if (param_index < fastcall_nb_regs) {
trace ("gfunc_prolog 38\n");
/* save FASTCALL register */
loc -= 4;
o(0x89); /* movl */
gen_modrm(fastcall_regs_ptr[param_index], VT_LOCAL, NULL, loc);
param_addr = loc;
} else {
trace ("gfunc_prolog 39\n");
param_addr = addr;
addr += size;
}
@ -614,7 +588,6 @@ ST_FUNC void gfunc_prolog(CType *func_type)
param_index++;
}
func_ret_sub = 0;
trace ("gfunc_prolog 50\n");
/* pascal type call ? */
if (func_call == FUNC_STDCALL)
func_ret_sub = addr - 8;
@ -623,18 +596,15 @@ ST_FUNC void gfunc_prolog(CType *func_type)
func_ret_sub = 4;
#endif
trace ("gfunc_prolog 60\n");
#ifdef CONFIG_TCC_BCHECK
/* leave some room for bound checking code */
if (tcc_state->do_bounds_check) {
trace ("gfunc_prolog 61\n");
func_bound_offset = lbounds_section->data_offset;
func_bound_ind = ind;
oad(0xb8, 0); /* lbound section pointer */
oad(0xb8, 0); /* call to function */
}
#endif
trace_exit ("gfunc_prolog");
}
/* generate function epilog */
@ -642,11 +612,9 @@ ST_FUNC void gfunc_epilog(void)
{
addr_t v, saved_ind;
trace ("gfunc_epilog\n");
#ifdef CONFIG_TCC_BCHECK
if (tcc_state->do_bounds_check
&& func_bound_offset != lbounds_section->data_offset) {
trace ("gfunc_epilog 01\n");
addr_t saved_ind;
addr_t *bounds_ptr;
Sym *sym_data;
@ -675,22 +643,18 @@ ST_FUNC void gfunc_epilog(void)
}
#endif
trace ("gfunc_epilog 20\n");
/* align local size to word & save local variables */
v = (-loc + 3) & -4;
#if USE_EBX
trace ("gfunc_epilog 21\n");
o(0x8b);
gen_modrm(TREG_EBX, VT_LOCAL, NULL, -(v+4));
#endif
o(0xc9); /* leave */
if (func_ret_sub == 0) {
trace ("gfunc_epilog 23\n");
o(0xc3); /* ret */
} else {
trace ("gfunc_epilog 24\n");
o(0xc2); /* ret n */
g(func_ret_sub);
g(func_ret_sub >> 8);
@ -704,7 +668,6 @@ ST_FUNC void gfunc_epilog(void)
} else
#endif
{
trace ("gfunc_epilog 30\n");
o(0xe58955); /* push %ebp, mov %esp, %ebp */
o(0xec81); /* sub esp, stacksize */
gen_le32(v);
@ -796,8 +759,6 @@ ST_FUNC void gen_opi(int op)
{
int r, fr, opc, c;
trace_enter ("gen_opi");
trace ("gen_opi op="); eputs (itoa (op)); eputs ("\n");
switch(op) {
case '+':
case TOK_ADDC1: /* add with carry generation */
@ -821,7 +782,6 @@ ST_FUNC void gen_opi(int op)
g(c);
}
} else {
trace ("gen_opi 20\n");
o(0x81);
oad(0xc0 | (opc << 3) | r, c);
}

View File

@ -162,90 +162,29 @@ void relocate_init(Section *sr)
qrel = (ElfW_Rel *) sr->data;
}
uint16_t my_read16le(unsigned char *p) {
trace_enter ("my_read16le");
//return p[0] | (uint16_t)p[1] << 8;
trace ("p="); eputs (itoa (p)); eputs ("\n");
trace ("*p="); eputc (*p); eputs ("\n");
trace ("p[0]="); eputs (itoa (p[0])); eputs ("\n");
uint16_t i = p[0];
trace ("my_read16le 00\n");
//uint16_t j = (uint16_t)p[1] << 8;
trace ("p[1]="); eputs (itoa (p[1])); eputs ("\n");
uint16_t j = (uint16_t)p[1];
trace ("my_read16le 01\n");
j <<= 8;
trace ("my_read16le 02\n");
uint16_t r = i | j;
trace_exit ("my_read16le");
return r;
}
uint32_t my_read32le(unsigned char *p) {
//return read16le(p) | (uint32_t)read16le(p + 2) << 16;
//return read16le(p) | (uint32_t)read16le(p + 2) << 16;
trace_enter ("my_read32le");
uint32_t r16 = my_read16le(p);
uint32_t r162 = (uint32_t)my_read16le(p + 2) << 16;
uint32_t r32 = r16 | r162;
trace_exit ("my_read32le");
return r32;
}
void my_write32le(unsigned char *p, uint32_t x) {
trace_enter ("my_write32le");
write16le(p, x), write16le(p + 2, x >> 16);
trace_exit ("my_write32le");
}
void my_add32le(unsigned char *p, int32_t x) {
trace_enter ("my_add32le");
//write32le(p, read32le(p) + x);
int32_t r32 = my_read32le(p);
r32 += x;
my_write32le(p, r32);
trace_exit ("my_add32le");
}
void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
{
trace_enter ("relocate");
int sym_index, esym_index;
sym_index = ELFW(R_SYM)(rel->r_info);
trace ("relocate type="); eputs (itoa (type)); eputs ("\n");
switch (type) {
case R_386_32:
trace ("relocate 10\n");
if (s1->output_type == TCC_OUTPUT_DLL) {
trace ("relocate 11\n");
esym_index = s1->sym_attrs[sym_index].dyn_index;
trace ("relocate 12\n");
qrel->r_offset = rel->r_offset;
trace ("relocate 13\n");
if (esym_index) {
trace ("relocate 14\n");
qrel->r_info = ELFW(R_INFO)(esym_index, R_386_32);
trace ("relocate 14.2\n");
qrel++;
trace ("relocate 15\n");
trace_exit ("relocate 16");
return;
} else {
trace ("relocate 17\n");
qrel->r_info = ELFW(R_INFO)(0, R_386_RELATIVE);
trace ("relocate 17.2\n");
qrel++;
}
}
trace ("relocate 18\n");
my_add32le(ptr, val);
trace ("relocate 19\n");
trace_exit ("relocate");
add32le(ptr, val);
return;
case R_386_PC32:
trace ("relocate 20\n");
if (s1->output_type == TCC_OUTPUT_DLL) {
/* DLL relocation */
esym_index = s1->sym_attrs[sym_index].dyn_index;
@ -253,83 +192,53 @@ void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t
qrel->r_offset = rel->r_offset;
qrel->r_info = ELFW(R_INFO)(esym_index, R_386_PC32);
qrel++;
trace ("relocate 25\n");
trace_exit ("relocate");
return;
}
}
add32le(ptr, val - addr);
trace ("relocate 29\n");
trace_exit ("relocate");
return;
case R_386_PLT32:
trace ("relocate 30\n");
add32le(ptr, val - addr);
trace ("relocate 35\n");
trace_exit ("relocate");
return;
case R_386_GLOB_DAT:
case R_386_JMP_SLOT:
trace ("relocate 40\n");
write32le(ptr, val);
trace ("relocate 41\n");
trace_exit ("relocate");
return;
case R_386_GOTPC:
trace ("relocate 45\n");
add32le(ptr, s1->got->sh_addr - addr);
return;
trace ("relocate 49\n");
trace_exit ("relocate");
case R_386_GOTOFF:
add32le(ptr, val - s1->got->sh_addr);
trace ("relocate 50\n");
trace_exit ("relocate");
return;
case R_386_GOT32:
case R_386_GOT32X:
trace ("relocate 55\n");
/* we load the got offset */
add32le(ptr, s1->sym_attrs[sym_index].got_offset);
trace ("relocate 59\n");
trace_exit ("relocate");
return;
case R_386_16:
trace ("relocate 60\n");
if (s1->output_format != TCC_OUTPUT_FORMAT_BINARY) {
output_file:
tcc_error("can only produce 16-bit binary files");
}
write16le(ptr, read16le(ptr) + val);
trace ("relocate 63\n");
trace_exit ("relocate");
return;
case R_386_PC16:
trace ("relocate 65\n");
if (s1->output_format != TCC_OUTPUT_FORMAT_BINARY)
goto output_file;
write16le(ptr, read16le(ptr) + val - addr);
trace ("relocate 66\n");
trace_exit ("relocate");
return;
case R_386_RELATIVE:
/* do nothing */
trace ("relocate 70\n");
trace_exit ("relocate");
return;
case R_386_COPY:
/* This relocation must copy initialized data from the library
to the program .bss segment. Currently made like for ARM
(to remove noise of default case). Is this true?
*/
trace ("relocate 75\n");
trace_exit ("relocate");
return;
default:
fprintf(stderr,"FIXME: handle reloc type %d at %x [%p] to %x\n",
type, (unsigned)addr, ptr, (unsigned)val);
trace ("relocate 80\n");
trace_exit ("relocate");
return;
}
}

197
libtcc.c
View File

@ -226,14 +226,10 @@ PUB_FUNC void *tcc_mallocz(unsigned long size)
PUB_FUNC void *tcc_realloc(void *ptr, unsigned long size)
{
trace_enter ("tcc_realloc");
trace ("tcc_realloc size="); eputs (itoa (size)); eputs ("\n");
void *ptr1;
ptr1 = realloc(ptr, size);
if (!ptr1 && size)
tcc_error("memory full (realloc)");
trace_exit ("tcc_realloc");
return ptr1;
}
@ -443,17 +439,11 @@ ST_FUNC void dynarray_reset(void *pp, int *n)
static void tcc_split_path(TCCState *s, void *p_ary, int *p_nb_ary, const char *in)
{
const char *p;
//eputs ("sp in="); //eputs (in); //eputs ("\n");
do {
int c;
CString str;
//eputs ("sp in="); //eputs (in); //eputs ("\n");
//if (s->nb_files) {struct filespec *f = s->files[0]; //eputs ("sp 01 file[0]="); //eputs (f->name); //eputs ("\n");}
cstr_new(&str);
//if (s->nb_files) {struct filespec *f = s->files[0]; //eputs ("sp 02 file[0]="); //eputs (f->name); //eputs ("\n");}
for (p = in; c = *p, c != '\0' && c != PATHSEP; ++p) {
if (c == '{' && p[1] && p[2] == '}') {
c = p[1], p += 2;
@ -465,15 +455,11 @@ static void tcc_split_path(TCCState *s, void *p_ary, int *p_nb_ary, const char *
}
if (str.size) {
cstr_ccat(&str, '\0');
//if (s->nb_files) {struct filespec *f = s->files[0]; //eputs ("sp 14 file[0]="); //eputs (f->name); //eputs ("\n");}
dynarray_add(p_ary, p_nb_ary, tcc_strdup(str.data));
}
//if (s->nb_files) {struct filespec *f = s->files[0]; //eputs ("sp 15 file[0]="); //eputs (f->name); //eputs ("\n");}
cstr_free(&str);
//if (s->nb_files) {struct filespec *f = s->files[0]; //eputs ("sp 16 file[0]="); //eputs (f->name); //eputs ("\n");}
in = p+1;
} while (*p);
//eputs ("sp 99\n");
}
/********************************************************/
@ -589,77 +575,51 @@ PUB_FUNC void tcc_warning(const char *fmt, ...)
ST_FUNC void tcc_open_bf(TCCState *s1, const char *filename, int initlen)
{
trace_enter ("tcc_open_bf");
BufferedFile *bf;
int buflen = initlen ? initlen : IO_BUF_SIZE;
bf = tcc_mallocz(sizeof(BufferedFile) + buflen);
trace ("tcc_open_bf buflen="); eputs (itoa (buflen)); eputs ("\n");
//eputs ("tcc_open_bf bf size="); //eputs (itoa (sizeof (BufferedFile) + buflen)); //eputs ("\n");
trace ("tcc_open_bf 10\n");
bf->buf_ptr = bf->buffer;
trace ("tcc_open_bf 11\n");
bf->buf_end = bf->buffer + initlen;
trace ("tcc_open_bf 12\n");
bf->buf_end[0] = CH_EOB; /* put eob symbol */
trace ("tcc_open_bf 13\n");
pstrcpy(bf->filename, sizeof(bf->filename), filename);
trace ("tcc_open_bf 14\n");
pstrcpy(bf->filename2, sizeof(bf->filename2), filename);
trace ("tcc_open_bf 15\n");
#ifdef _WIN32
normalize_slashes(bf->filename);
#endif
trace ("tcc_open_bf 20\n");
bf->line_num = 1;
bf->ifdef_stack_ptr = s1->ifdef_stack_ptr;
bf->fd = -1;
bf->prev = file;
file = bf;
trace_exit ("tcc_open_bf");
}
ST_FUNC void tcc_close(void)
{
trace_enter ("tcc_close");
BufferedFile *bf = file;
//eputs ("tcc_close file:"); //eputs (itoa (file)); //eputs ("\n");
//eputs ("tcc_close bf->fd:"); //eputs (itoa (bf->fd)); //eputs ("\n");
//eputs ("tcc_close bf->prev:"); //eputs (itoa (bf->prev)); //eputs ("\n");
if (bf->fd > 0) {
//eputs ("tcc_close bf->filename:"); //eputs (bf->filename); //eputs ("\n");
close(bf->fd);
total_lines += bf->line_num;
}
//trace ("tcc_close file->buf_ptr="); eputs (file->buf_ptr); eputs ("\n");
file = bf->prev;
tcc_free(bf);
trace_exit ("tcc_close");
}
ST_FUNC int tcc_open(TCCState *s1, const char *filename)
{
int fd;
trace_enter ("tcc_open");
trace ("tcc_open file-name="); eputs (filename); eputs ("\n");
if (strcmp(filename, "-") == 0)
fd = 0, filename = "<stdin>";
else
fd = open(filename, O_RDONLY | O_BINARY);
trace ("tcc_open fd="); eputs (itoa (fd)); eputs ("\n");
if ((s1->verbose == 2 && fd >= 0) || s1->verbose == 3)
printf("%s %*s%s\n", fd < 0 ? "nf":"->",
(int)(s1->include_stack_ptr - s1->include_stack), "", filename);
if (fd < 0) {
trace_exit ("tcc_open");
if (fd < 0)
return -1;
}
eputs ("tcc_open 10\n");
tcc_open_bf(s1, filename, 0);
eputs ("tcc_open 11\n");
file->fd = fd;
trace_exit ("tcc_open");
return fd;
}
@ -668,42 +628,30 @@ static int tcc_compile(TCCState *s1)
{
Sym *define_start;
trace_enter ("tcc_compile");
define_start = define_stack;
if (setjmp(s1->error_jmp_buf) == 0) {
s1->nb_errors = 0;
s1->error_set_jmp_enabled = 1;
trace ("tcc_compile 05 nb_errors="); eputs (itoa (s1->nb_errors)); eputs ("\n");
preprocess_start(s1);
trace ("tcc_compile 06 nb_errors="); eputs (itoa (s1->nb_errors)); eputs ("\n");
tccgen_start(s1);
trace ("tcc_compile 07 nb_errors="); eputs (itoa (s1->nb_errors)); eputs ("\n");
#ifdef INC_DEBUG
printf("%s: **** new file\n", file->filename);
#endif
ch = file->buf_ptr[0];
trace ("tcc_compile 08 nb_errors="); eputs (itoa (s1->nb_errors)); eputs ("\n");
tok_flags = TOK_FLAG_BOL | TOK_FLAG_BOF;
parse_flags = PARSE_FLAG_PREPROCESS | PARSE_FLAG_TOK_NUM | PARSE_FLAG_TOK_STR;
trace ("tcc_compile 10 nb_errors="); eputs (itoa (s1->nb_errors)); eputs ("\n");
next();
trace ("tcc_compile 11 nb_errors="); eputs (itoa (s1->nb_errors)); eputs ("\n");
decl(VT_CONST);
trace ("tcc_compile 12 nb_errors="); eputs (itoa (s1->nb_errors)); eputs ("\n");
if (tok != TOK_EOF)
expect("declaration");
/* free defines here already on behalf of of M.M.'s possibly existing
experimental preprocessor implementation. The normal call below
is still there to free after error-longjmp */
trace ("tcc_compile 13 nb_errors="); eputs (itoa (s1->nb_errors)); eputs ("\n");
free_defines(define_start);
trace ("tcc_compile 14 nb_errors="); eputs (itoa (s1->nb_errors)); eputs ("\n");
tccgen_end(s1);
trace ("tcc_compile 15 nb_errors="); eputs (itoa (s1->nb_errors)); eputs ("\n");
}
s1->error_set_jmp_enabled = 0;
@ -712,7 +660,6 @@ static int tcc_compile(TCCState *s1)
free_defines(define_start);
sym_pop(&global_stack, NULL, 0);
sym_pop(&local_stack, NULL, 0);
trace_exit ("tcc_compile");
return s1->nb_errors != 0 ? -1 : 0;
}
@ -731,37 +678,25 @@ LIBTCCAPI int tcc_compile_string(TCCState *s, const char *str)
/* define a preprocessor symbol. A value can also be provided with the '=' operator */
LIBTCCAPI void tcc_define_symbol(TCCState *s1, const char *sym, const char *value)
{
trace_enter ("tcc_define_symbol");
trace ("tcc_define_symbol value="); eputs (sym); eputs ("\n");
int len1, len2;
/* default value */
if (!value)
value = "1";
trace ("tcc_define_symbol 01\n");
len1 = strlen(sym);
trace ("tcc_define_symbol 02\n");
len2 = strlen(value);
trace ("tcc_define_symbol 03\n");
/* init file structure */
tcc_open_bf(s1, "<define>", len1 + len2 + 1);
trace ("tcc_define_symbol 04\n");
memcpy(file->buffer, sym, len1);
file->buffer[len1] = ' ';
memcpy(file->buffer + len1 + 1, value, len2);
trace ("tcc_define_symbol X="); //eputs (file->buffer); //eputs ("\n");
/* parse with define parser */
ch = file->buf_ptr[0];
trace ("tcc_define_symbol 08\n");
next_nomacro();
trace ("tcc_define_symbol 09\n");
parse_define();
trace ("tcc_define_symbol 10\n");
tcc_close();
trace_exit ("tcc_define_symbol");
}
/* undefine a preprocessor symbol */
@ -779,15 +714,12 @@ LIBTCCAPI void tcc_undefine_symbol(TCCState *s1, const char *sym)
/* cleanup all static data used during compilation */
static void tcc_cleanup(void)
{
if (NULL == tcc_state)
return;
tccpp_delete(tcc_state);
//eputs ("tcc_cleanup01\n");
tcc_state = NULL;
/* free sym_pools */
dynarray_reset(&sym_pools, &nb_sym_pools);
//eputs ("tcc_cleanup02\n");
/* reset symbol stack */
sym_free_first = NULL;
}
@ -796,15 +728,9 @@ LIBTCCAPI TCCState *tcc_new(void)
{
TCCState *s;
//eputs ("tcc_new\n");
tcc_cleanup();
//eputs ("tcc_new01\n");
s = tcc_mallocz(sizeof(TCCState));
//eputs ("size:"); //eputs (itoa (sizeof(TCCState))); //eputs ("\n");
//eputs ("tcc_new02\n");
//eputs ("s="); //eputs (itoa (s)); //eputs ("\n");
if (!s)
return NULL;
tcc_state = s;
@ -964,8 +890,6 @@ LIBTCCAPI TCCState *tcc_new(void)
/* Some GCC builtins that are simple to express as macros. */
tcc_define_symbol(s, "__builtin_extract_return_addr(x)", "x");
#endif /* ndef TCC_TARGET_PE */
//eputs ("tcc_new99\n");
return s;
}
@ -1071,34 +995,10 @@ LIBTCCAPI int tcc_add_sysinclude_path(TCCState *s, const char *pathname)
return 0;
}
#if !__x86_64__
#undef eputs
#endif
#if !BOOTSTRAP // MESC
#define for_each_elem(sec, startoff, elem, type) \
for (elem = (type *) sec->data + startoff; \
elem < (type *) (sec->data + sec->data_offset); elem++)
#else
#define for_each_elem(sec, startoff, elem, type) \
elem = sec->data + sizeof (type) * startoff; \
for (;elem < ((type *) (sec->data + sec->data_offset)); elem++)
#endif
ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags)
{
int ret, filetype;
trace_enter ("tcc_add_file_internal");
char *name;
ElfW(Sym) *esym;
for_each_elem(symtab_section, 1, esym, ElfW(Sym)) {
trace ("tcc_add_file_internal num="); eputs (itoa (esym->st_shndx)); eputs ("\n");
name = (char *) strtab_section->data + esym->st_name;
trace ("tcc_add_file_internal name="); eputs (name); eputs ("\n");
}
trace ("tcc_add_file_internal file-name="); eputs (filename); eputs ("\n");
filetype = flags & 0x0F;
if (filetype == 0) {
/* use a file extension to detect a filetype */
@ -1119,16 +1019,7 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags)
}
/* open the file */
trace ("tcc_add_file_internal filename="); eputs (filename); eputs ("\n");
ret = tcc_open(s1, filename);
trace ("tcc_add_file_internal 20 ret="); eputs (itoa (ret));; eputs ("\n");
for_each_elem(symtab_section, 1, esym, ElfW(Sym)) {
trace ("tcc_add_file_internal num="); eputs (itoa (esym->st_shndx)); eputs ("\n");
name = (char *) strtab_section->data + esym->st_name;
trace ("tcc_add_file_internal name="); eputs (name); eputs ("\n");
}
if (ret < 0) {
if (flags & AFF_PRINT_ERROR)
tcc_error_noabort("file '%s' not found", filename);
@ -1139,13 +1030,6 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags)
dynarray_add(&s1->target_deps, &s1->nb_target_deps,
tcc_strdup(filename));
trace ("tcc_add_file_internal 21\n");
for_each_elem(symtab_section, 1, esym, ElfW(Sym)) {
trace ("tcc_add_file_internal num="); eputs (itoa (esym->st_shndx)); eputs ("\n");
name = (char *) strtab_section->data + esym->st_name;
trace ("tcc_add_file_internal name="); eputs (name); eputs ("\n");
}
parse_flags = 0;
/* if .S file, define __ASSEMBLER__ like gcc does */
if (filetype == AFF_TYPE_ASM || filetype == AFF_TYPE_ASMPP) {
@ -1153,41 +1037,24 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags)
parse_flags = PARSE_FLAG_ASM_FILE;
}
trace ("tcc_add_file_internal 22\n");
for_each_elem(symtab_section, 1, esym, ElfW(Sym)) {
trace ("tcc_add_file_internal num="); eputs (itoa (esym->st_shndx)); eputs ("\n");
name = (char *) strtab_section->data + esym->st_name;
trace ("tcc_add_file_internal name="); eputs (name); eputs ("\n");
}
if (flags & AFF_PREPROCESS) {
ret = tcc_preprocess(s1);
trace ("tcc_add_file_internal 31 ret="); eputs (itoa (ret));; eputs ("\n");
} else if (filetype == AFF_TYPE_C) {
ret = tcc_compile(s1);
trace ("tcc_add_file_internal 32 ret="); eputs (itoa (ret));; eputs ("\n");
for_each_elem(symtab_section, 1, esym, ElfW(Sym)) {
trace ("tcc_add_file_internal num="); eputs (itoa (esym->st_shndx)); eputs ("\n");
name = (char *) strtab_section->data + esym->st_name;
trace ("tcc_add_file_internal name="); eputs (name); eputs ("\n");
}
#ifdef CONFIG_TCC_ASM
} else if (filetype == AFF_TYPE_ASMPP) {
/* non preprocessed assembler */
ret = tcc_assemble(s1, 1);
trace ("tcc_add_file_internal 33 ret="); eputs (itoa (ret));; eputs ("\n");
} else if (filetype == AFF_TYPE_ASM) {
/* preprocessed assembler */
ret = tcc_assemble(s1, 0);
#endif
trace ("tcc_add_file_internal 34 ret="); eputs (itoa (ret));; eputs ("\n");
} else {
ElfW(Ehdr) ehdr;
int fd, obj_type;
fd = file->fd;
obj_type = tcc_object_type(fd, &ehdr);
trace ("tcc_add_file_internal 36 obj_type="); eputs (itoa (obj_type));; eputs ("\n");
lseek(fd, 0, SEEK_SET);
/* do not display line number if error */
@ -1200,60 +1067,43 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags)
switch (obj_type) {
case AFF_BINTYPE_REL:
{
ret = tcc_load_object_file(s1, fd, 0);
trace ("tcc_add_file_internal 41 ret="); eputs (itoa (ret));; eputs ("\n");
break;
}
#ifndef TCC_TARGET_PE
case AFF_BINTYPE_DYN:
{
if (s1->output_type == TCC_OUTPUT_MEMORY) {
ret = 0;
#ifdef TCC_IS_NATIVE
if (NULL == dlopen(filename, RTLD_GLOBAL | RTLD_LAZY))
ret = -1;
#endif
trace ("tcc_add_file_internal 42 ret="); eputs (itoa (ret));; eputs ("\n");
} else {
ret = tcc_load_dll(s1, fd, filename,
(flags & AFF_REFERENCED_DLL) != 0);
trace ("tcc_add_file_internal 43 ret="); eputs (itoa (ret));; eputs ("\n");
}
break;
#endif
}
case AFF_BINTYPE_AR:
{
ret = tcc_load_archive(s1, fd);
trace ("tcc_add_file_internal 51 ret="); eputs (itoa (ret));; eputs ("\n");
break;
}
#ifdef TCC_TARGET_COFF
case AFF_BINTYPE_C67:
ret = tcc_load_coff(s1, fd);
trace ("tcc_add_file_internal 52 ret="); eputs (itoa (ret));; eputs ("\n");
break;
#endif
default:
{
#ifdef TCC_TARGET_PE
ret = pe_load_file(s1, filename, fd);
#else
/* as GNU ld, consider it is an ld script if not recognized */
ret = tcc_load_ldscript(s1);
trace ("tcc_add_file_internal 61 ret="); eputs (itoa (ret));; eputs ("\n");
#endif
if (ret < 0)
tcc_error_noabort("unrecognized file type");
break;
}
}
}
trace ("tcc_add_file_internal 90\n");
tcc_close();
trace_exit ("tcc_add_file_internal");
return ret;
}
@ -1267,11 +1117,7 @@ LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename)
LIBTCCAPI int tcc_add_library_path(TCCState *s, const char *pathname)
{
trace ("tcc_add_library_path path="); eputs (pathname); eputs ("\n");
tcc_split_path(s, &s->library_paths, &s->nb_library_paths, pathname);
for(int i = 0; i < s->nb_library_paths; i++) {
trace ("tcc_add_library_path dir="); eputs (s->library_paths[i]); eputs ("\n");
}
return 0;
}
@ -1281,11 +1127,8 @@ static int tcc_add_library_internal(TCCState *s, const char *fmt,
char buf[1024];
int i;
trace ("tcc_add_library_internal file-name="); eputs (filename); eputs ("\n");
trace ("tcc_add_library_internal nb_paths="); eputs (itoa (nb_paths)); eputs ("\n");
for(i = 0; i < nb_paths; i++) {
snprintf(buf, sizeof(buf), fmt, paths[i], filename);
trace ("tcc_add_library_internal buf="); eputs (buf); eputs ("\n");
if (tcc_add_file_internal(s, buf, flags | AFF_TYPE_BIN) == 0)
return 0;
}
@ -1302,7 +1145,6 @@ ST_FUNC int tcc_add_dll(TCCState *s, const char *filename, int flags)
ST_FUNC int tcc_add_crt(TCCState *s, const char *filename)
{
trace ("tcc_add_crt file name="); eputs (filename); eputs ("\n");
if (-1 == tcc_add_library_internal(s, "%s/%s",
filename, 0, s->crt_paths, s->nb_crt_paths))
tcc_error_noabort("file '%s' not found", filename);
@ -1333,7 +1175,6 @@ LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname)
PUB_FUNC int tcc_add_library_err(TCCState *s, const char *libname)
{
trace ("tcc_add_library_err libname="); eputs (libname); eputs ("\n");
int ret = tcc_add_library(s, libname);
if (ret < 0)
tcc_error_noabort("library '%s' not found", libname);
@ -1355,7 +1196,6 @@ LIBTCCAPI int tcc_add_symbol(TCCState *s, const char *name, const void *val)
So it is handled here as if it were in a DLL. */
pe_putimport(s, 0, name, (uintptr_t)val);
#else
trace ("tcc_add_symbol name="); eputs (name); eputs ("\n");
set_elf_sym(symtab_section, (uintptr_t)val, 0,
ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
SHN_ABS, name);
@ -1420,13 +1260,10 @@ ST_FUNC int set_flag(TCCState *s, const FlagDef *flags, const char *name)
static int strstart(const char *val, const char **str)
{
//eputs ("strstart val:"); //eputs (val); //eputs ("\n");
//eputs ("strstart *str:"); //eputs (*str); //eputs ("\n");
const char *p, *q;
p = *str;
q = val;
while (*q) {
//eputs ("*q:"); //eputc (*q); //eputs ("\n");
if (*p != *q)
return 0;
p++;
@ -1781,16 +1618,10 @@ static void parse_option_D(TCCState *s1, const char *optarg)
static void args_parser_add_file(TCCState *s, const char* filename, int filetype)
{
struct filespec *f = tcc_malloc(sizeof *f + strlen(filename));
trace ("arg_parser_add file name="); eputs (filename); eputs ("\n");
f->type = filetype;
f->alacarte = s->alacarte_link;
strcpy(f->name, filename);
trace ("arg_parser_add file f->name="); //eputs (f->name); //eputs ("\n");
trace ("arg_parser_add nb_files="); //eputs (itoa (s->nb_files)); //eputs ("\n");
dynarray_add(&s->files, &s->nb_files, f);
//struct filespec *= s->files[s->nb_files - 1];
struct filespec * fs = s->files[0];
//eputs ("arg_parser_add file fs->name="); //eputs (fs->name); //eputs ("\n");
}
static int args_parser_make_argv(const char *r, int *argc, char ***argv)
@ -1835,7 +1666,6 @@ static void args_parser_listfile(TCCState *s,
int argc = 0;
char **argv = NULL;
trace ("arg_parser_listfile filename="); eputs (filename); eputs ("\n");
fd = open(filename, O_RDONLY | O_BINARY);
if (fd < 0)
tcc_error("listfile '%s' not found", filename);
@ -1857,35 +1687,21 @@ static void args_parser_listfile(TCCState *s,
PUB_FUNC int tcc_parse_args(TCCState *s, int *pargc, char ***pargv, int optind)
{
trace ("tcc_parse_args\n");
const TCCOption *popt;
const char *optarg, *r;
const char *run = NULL;
int last_o = -1;
int x;
trace ("tcc_parse_args 005\n");
CString linker_arg; /* collect -Wl options */
trace ("tcc_parse_args 006\n");
char buf[1024];
trace ("tcc_parse_args 007\n");
int tool = 0, arg_start = 0, noaction = optind;
trace ("tcc_parse_args 008\n");
char **argv = *pargv;
trace ("tcc_parse_args 009\n");
int argc = *pargc;
trace ("tcc_parse_args 01 argc:"); eputs (itoa (argc)); eputs ("\n");
cstr_new(&linker_arg);
trace ("tcc_parse_args 01 optind:"); eputs (itoa (optind)); eputs ("\n");
while (optind < argc) {
trace ("tcc_parse_args 02 arg:"); eputs (itoa (optind)); eputs ("\n");
r = argv[optind];
trace ("tcc_parse_args 03 r:"); eputs (r); eputs ("\n");
if (r[0] == '@' && r[1] != '\0') {
args_parser_listfile(s, r + 1, optind, &argc, &argv);
continue;
@ -1908,17 +1724,10 @@ reparse:
continue;
}
trace ("tcc_parse_args 20\n");
trace ("tcc_parse_args 20 opt0="); eputs (tcc_options[0].name); eputs ("\n");
trace ("tcc_parse_args 20 opt1="); eputs (tcc_options[1].name); eputs ("\n");
/* find option in table */
for(popt = tcc_options; ; ++popt) {
trace ("tcc_parse_args 21\n");
trace ("tcc_parse_args 22 popt:"); eputs (popt->name); eputs ("\n");
const char *p1 = popt->name;
const char *r1 = r + 1;
trace ("tcc_parse_args 23 r1:"); eputs (r1); eputs ("\n");
if (p1 == NULL)
tcc_error("invalid option -- '%s'", r);
if (!strstart(p1, &r1))
@ -1936,8 +1745,6 @@ reparse:
break;
}
trace ("pars_arg 2\n");
switch(popt->index) {
case TCC_OPTION_HELP:
return OPT_HELP;

33
tcc.c
View File

@ -25,8 +25,6 @@
#endif
#include "tcctools.c"
int trace_p = 1;
static const char help[] =
"Tiny C Compiler "TCC_VERSION" - Copyright (C) 2001-2006 Fabrice Bellard\n"
"Usage: tcc [options...] [-o outfile] [-c] infile(s)...\n"
@ -253,21 +251,9 @@ int main(int argc, char **argv)
unsigned start_time = 0;
const char *first_file;
trace_enter ("main");
redo:
trace ("main 01\n");
s = tcc_new();
trace ("main 02\n");
opt = tcc_parse_args(s, &argc, &argv, 1);
trace ("main 03\n");
if (s->nb_files) {
struct filespec *f = s->files[0];
trace ("main 05 file[0]="); eputs (f->name); eputs ("\n");
}
trace ("main 06\n");
if (n == 0) {
if (opt == OPT_HELP)
@ -319,28 +305,19 @@ redo:
start_time = getclock_ms();
}
trace ("main 20\n");
set_environment(s);
trace ("main 21\n");
if (s->output_type == 0)
s->output_type = TCC_OUTPUT_EXE;
tcc_set_output_type(s, s->output_type);
trace ("main 23\n");
/* compile or add each files or library */
for (first_file = NULL, ret = 0;;) {
trace ("main 24 nb-files="); eputs (itoa (s->nb_files)); eputs ("\n");
trace ("main 24 n="); eputs (itoa (n)); eputs ("\n");
struct filespec *f = s->files[s->nb_files - n];
trace ("for f->name="); eputs (f->name); eputs ("\n");
s->filetype = f->type;
s->alacarte_link = f->alacarte;
if (f->type == AFF_TYPE_LIB) {
if (tcc_add_library_err(s, f->name) < 0)
ret = 1;
trace ("main 32 ret="); eputs (itoa (ret)); eputs ("\n");
} else {
if (1 == s->verbose)
printf("-> %s\n", f->name);
@ -348,9 +325,7 @@ redo:
first_file = f->name;
if (tcc_add_file(s, f->name) < 0)
ret = 1;
trace ("main 33 ret="); eputs (itoa (ret)); eputs ("\n");
}
trace ("ret="); eputs (itoa (ret)); eputs ("\n");
s->filetype = 0;
s->alacarte_link = 1;
if (ret || --n == 0
@ -358,24 +333,17 @@ redo:
break;
}
trace ("main 40\n");
if (s->output_type == TCC_OUTPUT_PREPROCESS) {
trace ("main 41\n");
if (s->outfile)
fclose(s->ppfp);
} else if (0 == ret) {
trace ("main 42 ret == 0\n");
if (s->output_type == TCC_OUTPUT_MEMORY) {
trace ("main RUN\n");
#ifdef TCC_IS_NATIVE
ret = tcc_run(s, argc, argv);
#endif
} else {
trace ("main 44 gonna output_file\n");
if (!s->outfile)
s->outfile = default_outputfile(s, first_file);
trace ("main 45 output_file\n");
if (tcc_output_file(s, s->outfile))
ret = 1;
else if (s->gen_deps)
@ -388,6 +356,5 @@ redo:
tcc_delete(s);
if (ret == 0 && n)
goto redo; /* compile more files with -c */
trace_exit ("main");
return ret;
}

22
tcc.h
View File

@ -24,28 +24,6 @@
#define _GNU_SOURCE
#include "config.h"
extern int trace_p;
/* #define eputc(x) */
/* #define eputs(x) */
/* #define trace(x) */
/* #define trace_enter(x) */
/* #define trace_exit(x) */
#if !BOOTSTRAP
#define eputs(s)
#define eputc(c)
#define trace_enter(s)
#define trace_exit(s)
#define trace(s)
#else /* BOOTSTRAP */
#include <mes/lib.h>
int trace_index = 0;
char *trace_buffer = " ";
#define trace_enter(s) {if (trace_p) {trace_index++;eputs (trace_buffer+40-trace_index);eputs (s);eputs (" enter{\n");}}
#define trace_exit(s) {if (trace_p) {eputs (trace_buffer+40-trace_index);eputs (s);eputs (" exit}\n");trace_index--;}}
#define trace(s) {if (trace_p) {eputs (trace_buffer+40-trace_index);eputs (s);}}
#endif
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>

View File

@ -923,7 +923,6 @@ static int tcc_assemble_internal(TCCState *s1, int do_preprocess, int global)
/* XXX: undefine C labels */
trace_enter ("tcc_assemble_internal");
ch = file->buf_ptr[0];
tok_flags = TOK_FLAG_BOL | TOK_FLAG_BOF;
parse_flags = PARSE_FLAG_ASM_FILE | PARSE_FLAG_TOK_STR;
@ -932,7 +931,6 @@ static int tcc_assemble_internal(TCCState *s1, int do_preprocess, int global)
parse_flags |= PARSE_FLAG_PREPROCESS;
for(;;) {
next();
trace ("tcc_assemble_internal tok="); eputc (tok); eputs (" ["); eputs (itoa (tok)); eputs ("]\n");
if (tok == TOK_EOF)
break;
/* generate line number info */
@ -941,15 +939,12 @@ static int tcc_assemble_internal(TCCState *s1, int do_preprocess, int global)
parse_flags |= PARSE_FLAG_LINEFEED; /* XXX: suppress that hack */
redo:
if (tok == '#') {
trace ("tcc_assemble_internal 25\n");
/* horrible gas comment */
while (tok != TOK_LINEFEED)
next();
} else if (tok >= TOK_ASMDIR_FIRST && tok <= TOK_ASMDIR_LAST) {
trace ("tcc_assemble_internal 30\n");
asm_parse_directive(s1, global);
} else if (tok == TOK_PPNUM) {
trace ("tcc_assemble_internal 35\n");
Sym *sym;
const char *p;
int n;
@ -965,11 +960,9 @@ static int tcc_assemble_internal(TCCState *s1, int do_preprocess, int global)
skip(':');
goto redo;
} else if (tok >= TOK_IDENT) {
trace ("tcc_assemble_internal 50\n");
/* instruction or label */
opcode = tok;
next();
trace ("tcc_assemble_internal 51 tok="); eputc (tok); eputs (" ["); eputs (itoa (tok)); eputs ("]\n");
if (tok == ':') {
/* handle "extern void vide(void); __asm__("vide: ret");" as
"__asm__("globl vide\nvide: ret");" */
@ -987,15 +980,12 @@ static int tcc_assemble_internal(TCCState *s1, int do_preprocess, int global)
next();
goto redo;
} else if (tok == '=') {
trace ("tcc_assemble_internal 60\n");
set_symbol(s1, opcode);
goto redo;
} else {
trace ("tcc_assemble_internal 65\n");
asm_opcode(s1, opcode);
}
}
trace ("tcc_assemble_internal 70\n");
/* end of line */
if (tok != ';' && tok != TOK_LINEFEED)
expect("end of line");
@ -1003,7 +993,6 @@ static int tcc_assemble_internal(TCCState *s1, int do_preprocess, int global)
}
asm_free_labels(s1);
trace_exit ("tcc_assemble_internal");
return 0;
}
@ -1042,7 +1031,6 @@ static void tcc_assemble_inline(TCCState *s1, char *str, int len, int global)
int saved_parse_flags;
const int *saved_macro_ptr;
trace_enter ("tcc_assemble_inline");
saved_parse_flags = parse_flags;
saved_macro_ptr = macro_ptr;
@ -1056,7 +1044,6 @@ static void tcc_assemble_inline(TCCState *s1, char *str, int len, int global)
parse_flags = saved_parse_flags;
set_idnum('.', (parse_flags & PARSE_FLAG_ASM_FILE) ? IS_ID : 0);
macro_ptr = saved_macro_ptr;
trace_exit ("tcc_assemble_inline");
}
/* find a constraint by its number or id (gcc 3 extended
@ -1168,12 +1155,9 @@ static void parse_asm_operands(ASMOperand *operands, int *nb_operands_ptr,
next();
skip(']');
}
parse_mult_str(&astr, "parse_asm_operands string constant");
trace ("parse arm_operands tokc.str.data="); eputs (tokc.str.data); eputs ("\n");
parse_mult_str(&astr, "string constant");
op->constraint = tcc_malloc(astr.size);
trace ("parse arm_operands tokc.str.data="); eputs (tokc.str.data); eputs ("\n");
strcpy(op->constraint, astr.data);
trace ("parse arm_operands tokc.str.data="); eputs (tokc.str.data); eputs ("\n");
cstr_free(&astr);
skip('(');
gexpr();
@ -1212,17 +1196,13 @@ ST_FUNC void asm_instr(void)
int nb_outputs, nb_operands, i, must_subst, out_reg;
uint8_t clobber_regs[NB_ASM_REGS];
trace_enter ("asm_instr");
next();
trace ("asm_instr 01\n");
/* since we always generate the asm() instruction, we can ignore
volatile */
if (tok == TOK_VOLATILE1 || tok == TOK_VOLATILE2 || tok == TOK_VOLATILE3) {
next();
}
trace ("asm_instr 02\n");
parse_asm_str(&astr);
trace ("asm_instr astr.data="); eputs (astr.data); eputs ("\n");
nb_operands = 0;
nb_outputs = 0;
must_subst = 0;
@ -1275,7 +1255,6 @@ ST_FUNC void asm_instr(void)
#ifdef ASM_DEBUG
printf("asm: \"%s\"\n", (char *)astr.data);
#endif
trace ("asm_instr asm:"); eputs (astr.data); eputs ("\n");
if (must_subst) {
subst_asm_operands(operands, nb_operands, &astr1, &astr);
cstr_free(&astr);
@ -1285,7 +1264,6 @@ ST_FUNC void asm_instr(void)
#ifdef ASM_DEBUG
printf("subst_asm: \"%s\"\n", (char *)astr1.data);
#endif
trace ("asm_instr subst:"); eputs (astr1.data); eputs ("\n");
/* generate loads */
asm_gen_code(operands, nb_operands, nb_outputs, 0,
@ -1309,7 +1287,6 @@ ST_FUNC void asm_instr(void)
vpop();
}
cstr_free(&astr1);
trace_exit ("asm_instr");
}
ST_FUNC void asm_global_instr(void)

451
tccelf.c

File diff suppressed because it is too large Load Diff

682
tccgen.c

File diff suppressed because it is too large Load Diff

471
tccpp.c

File diff suppressed because it is too large Load Diff