Mercurial > hg > qcc
changeset 585:7fc19a001568
Rename global gen.c variable ind to gen_ind.
author | Rob Landley <rob@landley.net> |
---|---|
date | Thu, 03 Apr 2008 22:54:56 -0500 |
parents | 29c7cb849479 |
children | df36eb4661a5 |
files | arm/gen.c i386/asm.c i386/gen.c tcc.c tccasm.c |
diffstat | 5 files changed, 90 insertions(+), 96 deletions(-) [+] |
line wrap: on
line diff
--- a/arm/gen.c Thu Apr 03 22:53:32 2008 -0500 +++ b/arm/gen.c Thu Apr 03 22:54:56 2008 -0500 @@ -154,19 +154,19 @@ /* this is a good place to start adding big-endian support*/ int ind1; - ind1 = ind + 4; + ind1 = gen_ind + 4; if (!cur_text_section) error("compiler error! This happens f.ex. if the compiler\n" "can't evaluate constant expressions outside of a function."); if (ind1 > cur_text_section->data_allocated) section_realloc(cur_text_section, ind1); - cur_text_section->data[ind++] = i&255; + cur_text_section->data[gen_ind++] = i&255; i>>=8; - cur_text_section->data[ind++] = i&255; + cur_text_section->data[gen_ind++] = i&255; i>>=8; - cur_text_section->data[ind++] = i&255; + cur_text_section->data[gen_ind++] = i&255; i>>=8; - cur_text_section->data[ind++] = i; + cur_text_section->data[gen_ind++] = i; } static unsigned long stuff_const(unsigned long op,unsigned long c) @@ -319,7 +319,7 @@ void gsym(int t) { - gsym_addr(t, ind); + gsym_addr(t, gen_ind); } #ifdef TCC_ARM_VFP @@ -535,7 +535,7 @@ gen_multibyte(0xE59F0000|(intr(r)<<12)); gen_multibyte(0xEA000000); if(fr & VT_SYM) - greloc(cur_text_section, sv->sym, ind, R_ARM_ABS32); + greloc(cur_text_section, sv->sym, gen_ind, R_ARM_ABS32); gen_multibyte(sv->c.ul); } else gen_multibyte(op); @@ -546,7 +546,7 @@ gen_multibyte(0xE59F0000|(intr(r)<<12)); gen_multibyte(0xEA000000); if(fr & VT_SYM) // needed ? - greloc(cur_text_section, sv->sym, ind, R_ARM_ABS32); + greloc(cur_text_section, sv->sym, gen_ind, R_ARM_ABS32); gen_multibyte(sv->c.ul); gen_multibyte(0xE08B0000|(intr(r)<<12)|intr(r)); } else @@ -672,20 +672,20 @@ if ((vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST) { unsigned long x; /* constant case */ - x=encbranch(ind,ind+vtop->c.ul,0); + x=encbranch(gen_ind,gen_ind+vtop->c.ul,0); if(x) { if (vtop->r & VT_SYM) { /* relocation case */ - greloc(cur_text_section, vtop->sym, ind, R_ARM_PC24); + greloc(cur_text_section, vtop->sym, gen_ind, R_ARM_PC24); } else - put_elf_reloc(symtab_section, cur_text_section, ind, R_ARM_PC24, 0); + put_elf_reloc(symtab_section, cur_text_section, gen_ind, R_ARM_PC24, 0); gen_multibyte(x|(is_jmp?0xE0000000:0xE1000000)); } else { if(!is_jmp) gen_multibyte(0xE28FE004); // add lr,pc,#4 gen_multibyte(0xE51FF004); // ldr pc,[pc,#-4] if (vtop->r & VT_SYM) - greloc(cur_text_section, vtop->sym, ind, R_ARM_ABS32); + greloc(cur_text_section, vtop->sym, gen_ind, R_ARM_ABS32); gen_multibyte(vtop->c.ul); } } else { @@ -933,7 +933,7 @@ } gen_multibyte(0xE92D5800); /* save fp, ip, lr */ gen_multibyte(0xE28DB00C); /* add fp, sp, #12 */ - func_sub_sp_offset = ind; + func_sub_sp_offset = gen_ind; gen_multibyte(0xE1A00000); /* nop, leave space for stack adjustment */ while ((sym = sym->next)) { CType *type; @@ -978,7 +978,7 @@ *(unsigned long *)(cur_text_section->data + func_sub_sp_offset) = x; else { unsigned long addr; - addr=ind; + addr=gen_ind; gen_multibyte(0xE59FC004); /* ldr ip,[pc+4] */ gen_multibyte(0xE04BD00C); /* sub sp,fp,ip */ gen_multibyte(0xE1A0F00E); /* mov pc,lr */ @@ -992,7 +992,7 @@ int gjmp(int t) { int r; - r=ind; + r=gen_ind; gen_multibyte(0xE0000000|encbranch(r,t,1)); return r; } @@ -1009,7 +1009,7 @@ int v, r; unsigned long op; v = vtop->r & VT_VALMASK; - r=ind; + r=gen_ind; if (v == VT_CMP) { op=mapcc(inv?negcc(vtop->c.i):vtop->c.i); op|=encbranch(r,t,1); @@ -1555,7 +1555,7 @@ gen_multibyte(0xE3500000|(r<<12)); r=fpr(get_reg(RC_FLOAT)); if(last_itod_magic) { - off=ind+8-last_itod_magic; + off=gen_ind+8-last_itod_magic; off/=4; if(off>255) off=0; @@ -1563,7 +1563,7 @@ gen_multibyte(0xBD1F8100|(r<<12)|off); if(!off) { gen_multibyte(0xEA000001); - last_itod_magic=ind; + last_itod_magic=gen_ind; gen_multibyte(0x41F00000); gen_multibyte(0); }
--- a/i386/asm.c Thu Apr 03 22:53:32 2008 -0500 +++ b/i386/asm.c Thu Apr 03 22:54:56 2008 -0500 @@ -325,7 +325,7 @@ static void gen_expr32(ExprValue *pe) { if (pe->sym) - greloc(cur_text_section, pe->sym, ind, R_386_32); + greloc(cur_text_section, pe->sym, gen_ind, R_386_32); gen_le32(pe->v); } @@ -340,15 +340,15 @@ that the TCC compiler behaves differently here because it always outputs a relocation to ease (future) code elimination in the linker */ - gen_le32(pe->v + (long)sym->next - ind - 4); + gen_le32(pe->v + (long)sym->next - gen_ind - 4); } else { - greloc(cur_text_section, sym, ind, R_386_PC32); + greloc(cur_text_section, sym, gen_ind, R_386_PC32); gen_le32(pe->v - 4); } } else { /* put an empty PC32 relocation */ put_elf_reloc(symtab_section, cur_text_section, - ind, R_386_PC32, 0); + gen_ind, R_386_PC32, 0); gen_le32(pe->v - 4); } } @@ -604,7 +604,7 @@ goto no_short_jump; if (sym->r != cur_text_section->sh_num) goto no_short_jump; - jmp_disp = ops[0].e.v + (long)sym->next - ind - 2; + jmp_disp = ops[0].e.v + (long)sym->next - gen_ind - 2; if (jmp_disp == (int8_t)jmp_disp) { /* OK to generate jump */ is_short_jmp = 1;
--- a/i386/gen.c Thu Apr 03 22:53:32 2008 -0500 +++ b/i386/gen.c Thu Apr 03 22:54:56 2008 -0500 @@ -83,11 +83,11 @@ int ind1; if (!cur_text_section) return; - ind1 = ind + 1; + ind1 = gen_ind + 1; if (ind1 > cur_text_section->data_allocated) section_realloc(cur_text_section, ind1); - cur_text_section->data[ind] = c; - ind = ind1; + cur_text_section->data[gen_ind] = c; + gen_ind = ind1; } // Output a variable number of bytes, little endian, ignoring high zero bytes. @@ -123,26 +123,26 @@ void gsym(int t) { - gsym_addr(t, ind); + gsym_addr(t, gen_ind); } /* psym is used to put an instruction with a data field which is a reference to a symbol. It is in fact the same as oad ! */ #define psym oad -/* instruction + 4 bytes data. Return the address of the data */ +/* Output instruction + 4 bytes data. Return the address of the data */ static int oad(int c, int s) { int ind1; if (!cur_text_section) return 0; gen_multibyte(c); - ind1 = ind + 4; + ind1 = gen_ind + 4; if (ind1 > cur_text_section->data_allocated) section_realloc(cur_text_section, ind1); - *(int *)(cur_text_section->data + ind) = s; - s = ind; - ind = ind1; + *(int *)(cur_text_section->data + gen_ind) = s; + s = gen_ind; + gen_ind = ind1; return s; } @@ -150,7 +150,7 @@ static void gen_addr32(int r, Sym *sym, int c) { if (r & VT_SYM) - greloc(cur_text_section, sym, ind, R_386_32); + greloc(cur_text_section, sym, gen_ind, R_386_32); gen_le32(c); } @@ -296,11 +296,11 @@ if (vtop->r & VT_SYM) { /* relocation case */ greloc(cur_text_section, vtop->sym, - ind + 1, R_386_PC32); + gen_ind + 1, R_386_PC32); } else { /* put an empty PC32 relocation */ put_elf_reloc(symtab_section, cur_text_section, - ind + 1, R_386_PC32, 0); + gen_ind + 1, R_386_PC32, 0); } oad(0xe8 + is_jmp, vtop->c.ul - 4); /* call/jmp im */ } else { @@ -418,8 +418,8 @@ } param_index = 0; - ind += FUNC_PROLOG_SIZE; - func_sub_sp_offset = ind; + gen_ind += FUNC_PROLOG_SIZE; + func_sub_sp_offset = gen_ind; /* if the function returns a structure, then add an implicit pointer parameter */ func_vt = sym->type; @@ -481,26 +481,26 @@ bounds_ptr = section_ptr_add(lbounds_section, sizeof(int)); *bounds_ptr = 0; /* generate bound local allocation */ - saved_ind = ind; - ind = func_sub_sp_offset; + saved_ind = gen_ind; + gen_ind = func_sub_sp_offset; sym_data = get_sym_ref(&char_pointer_type, lbounds_section, func_bound_offset, lbounds_section->data_offset); greloc(cur_text_section, sym_data, - ind + 1, R_386_32); + gen_ind + 1, R_386_32); oad(0xb8, 0); /* mov %eax, xxx */ sym = external_global_sym(TOK___bound_local_new, &func_old_type, 0); greloc(cur_text_section, sym, - ind + 1, R_386_PC32); + gen_ind + 1, R_386_PC32); oad(0xe8, -4); - ind = saved_ind; + gen_ind = saved_ind; /* generate bound check local freeing */ gen_multibyte(0x5250); /* save returned value, if any */ greloc(cur_text_section, sym_data, - ind + 1, R_386_32); + gen_ind + 1, R_386_32); oad(0xb8, 0); /* mov %eax, xxx */ sym = external_global_sym(TOK___bound_local_delete, &func_old_type, 0); greloc(cur_text_section, sym, - ind + 1, R_386_PC32); + gen_ind + 1, R_386_PC32); oad(0xe8, -4); gen_multibyte(0x585a); /* restore returned value, if any */ } @@ -516,13 +516,13 @@ /* align local size to word & save local variables */ v = (-loc + 3) & -4; - saved_ind = ind; - ind = func_sub_sp_offset - FUNC_PROLOG_SIZE; + saved_ind = gen_ind; + gen_ind = func_sub_sp_offset - FUNC_PROLOG_SIZE; #ifdef TINYCC_TARGET_PE if (v >= 4096) { Sym *sym = external_global_sym(TOK___chkstk, &func_old_type, 0); oad(0xe8, -4); /* call __chkstk, (does the stackframe too) */ - greloc(cur_text_section, sym, ind-4, R_386_PC32); + greloc(cur_text_section, sym, gen_ind-4, R_386_PC32); } else #endif { @@ -530,7 +530,7 @@ gen_multibyte(0xec81); /* sub esp, stacksize */ } gen_le32(v); - ind = saved_ind; + gen_ind = saved_ind; } /* generate a jump to a label */ @@ -543,12 +543,12 @@ void gjmp_addr(int a) { int r; - r = a - ind - 2; + r = a - gen_ind - 2; if (r == (char)r) { gen_byte(0xeb); gen_byte(r); } else { - oad(0xe9, a - ind - 5); + oad(0xe9, a - gen_ind - 5); } } @@ -887,8 +887,7 @@ gen_multibyte(0x2dd9); /* ldcw xxx */ sym = external_global_sym(TOK___tcc_int_fpu_control, &ushort_type, VT_LVAL); - greloc(cur_text_section, sym, - ind, R_386_32); + greloc(cur_text_section, sym, gen_ind, R_386_32); gen_le32(0); oad(0xec81, size); /* sub $xxx, %esp */ @@ -898,8 +897,7 @@ gen_multibyte(0x2dd9); /* ldcw xxx */ sym = external_global_sym(TOK___tcc_fpu_control, &ushort_type, VT_LVAL); - greloc(cur_text_section, sym, - ind, R_386_32); + greloc(cur_text_section, sym, gen_ind, R_386_32); gen_le32(0); r = get_reg(RC_INT); @@ -944,8 +942,7 @@ save_regs(0); /* do a fast function call */ sym = external_global_sym(TOK___bound_ptr_add, &func_old_type, 0); - greloc(cur_text_section, sym, - ind + 1, R_386_PC32); + greloc(cur_text_section, sym, gen_ind + 1, R_386_PC32); oad(0xe8, -4); /* returned pointer is in eax */ vtop++;
--- a/tcc.c Thu Apr 03 22:53:32 2008 -0500 +++ b/tcc.c Thu Apr 03 22:54:56 2008 -0500 @@ -12,7 +12,7 @@ // This stuff is used by the code generation backend. -static int ind; /* output code index */ +static int gen_ind; /* output code index */ static int loc; /* local variable index */ static Section *cur_text_section; /* current section where function code is generated */ static SValue *vtop; @@ -4389,8 +4389,8 @@ #if defined(TINYCC_TARGET_I386) b = psym(0x850f, 0); #elif defined(TINYCC_TARGET_ARM) - b = ind; - gen_multibyte(0x1A000000 | encbranch(ind, 0, 1)); + b = gen_ind; + gen_multibyte(0x1A000000 | encbranch(gen_ind, 0, 1)); #elif defined(TINYCC_TARGET_C67) error("not implemented"); #else @@ -7095,9 +7095,9 @@ /* generate line number info */ if (do_debug && - (last_line_num != file->line_num || last_ind != ind)) { - put_stabn(N_SLINE, 0, file->line_num, ind - func_ind); - last_ind = ind; + (last_line_num != file->line_num || last_ind != gen_ind)) { + put_stabn(N_SLINE, 0, file->line_num, gen_ind - func_ind); + last_ind = gen_ind; last_line_num = file->line_num; } @@ -7125,7 +7125,7 @@ gsym(a); } else if (tok == TOK_WHILE) { next(); - d = ind; + d = gen_ind; skip('('); gexpr(); skip(')'); @@ -7242,10 +7242,8 @@ vpop(); } skip(';'); - d = ind; - c = ind; - a = 0; - b = 0; + d = c = gen_ind; + a = b = 0; if (tok != ';') { gexpr(); a = gtst(1, 0); @@ -7253,7 +7251,7 @@ skip(';'); if (tok != ')') { e = gjmp(0); - c = ind; + c = gen_ind; gexpr(); vpop(); gjmp_addr(d); @@ -7267,9 +7265,8 @@ } else if (tok == TOK_DO) { next(); - a = 0; - b = 0; - d = ind; + a = b = 0; + d = gen_ind; block(&a, &b, case_sym, def_sym, case_reg, 0); skip(TOK_WHILE); skip('('); @@ -7295,7 +7292,7 @@ block(&a, csym, &b, &c, case_reg, 0); /* if no default, jmp after switch */ if (c == 0) - c = ind; + c = gen_ind; /* default label */ gsym_addr(b, c); /* break label */ @@ -7347,7 +7344,7 @@ expect("switch"); if (*def_sym) error("too many 'default'"); - *def_sym = ind; + *def_sym = gen_ind; is_expr = 0; goto block_after_label; } else @@ -7394,7 +7391,7 @@ } else { s = label_push(&global_label_stack, b, LABEL_DEFINED); } - s->next = (void *)ind; + s->next = (void *)gen_ind; /* we accept this, but it is a mistake */ block_after_label: if (tok == '}') { @@ -8132,11 +8129,11 @@ 'cur_text_section' */ static void gen_function(Sym *sym) { - ind = cur_text_section->data_offset; + gen_ind = cur_text_section->data_offset; /* NOTE: we patch the symbol size later */ - put_extern_sym(sym, cur_text_section, ind, 0); + put_extern_sym(sym, cur_text_section, gen_ind, 0); funcname = get_tok_str(sym->token, NULL); - func_ind = ind; + func_ind = gen_ind; /* put debug symbol */ if (do_debug) put_func_debug(sym); @@ -8147,19 +8144,19 @@ block(NULL, NULL, NULL, NULL, 0, 0); gsym(rsym); gfunc_epilog(); - cur_text_section->data_offset = ind; + cur_text_section->data_offset = gen_ind; label_pop(&global_label_stack, NULL); sym_pop(&local_stack, NULL); /* reset local stack */ /* end of function */ /* patch symbol size */ ((Elf32_Sym *)symtab_section->data)[sym->c].st_size = - ind - func_ind; + gen_ind - func_ind; if (do_debug) { - put_stabn(N_FUN, 0, 0, ind - func_ind); + put_stabn(N_FUN, 0, 0, gen_ind - func_ind); } funcname = ""; /* for safety */ func_vt.t = VT_VOID; /* for safety */ - ind = 0; /* for safety */ + gen_ind = 0; /* for safety */ } static void gen_inline_functions(void)
--- a/tccasm.c Thu Apr 03 22:53:32 2008 -0500 +++ b/tccasm.c Thu Apr 03 22:54:56 2008 -0500 @@ -270,7 +270,7 @@ static void asm_new_label(TCCState *s1, int label, int is_local) { - asm_new_label1(s1, label, is_local, cur_text_section->sh_num, ind); + asm_new_label1(s1, label, is_local, cur_text_section->sh_num, gen_ind); } static void asm_free_labels(TCCState *st) @@ -295,9 +295,9 @@ static void use_section1(TCCState *s1, Section *sec) { - cur_text_section->data_offset = ind; + cur_text_section->data_offset = gen_ind; cur_text_section = sec; - ind = cur_text_section->data_offset; + gen_ind = cur_text_section->data_offset; } static void use_section(TCCState *s1, char *name) @@ -326,8 +326,8 @@ if (tok1 == TOK_ASM_align) { if (n < 0 || (n & (n-1)) != 0) error("alignment must be a positive power of two"); - offset = (ind + n - 1) & -n; - size = offset - ind; + offset = (gen_ind + n - 1) & -n; + size = offset - gen_ind; /* the section must have a compatible alignment */ if (sec->sh_addralign < n) sec->sh_addralign = n; @@ -341,11 +341,11 @@ } zero_pad: if (sec->sh_type != SHT_NOBITS) { - sec->data_offset = ind; + sec->data_offset = gen_ind; ptr = section_ptr_add(sec, size); memset(ptr, v, size); } - ind += size; + gen_ind += size; break; case TOK_ASM_quad: next(); @@ -367,7 +367,7 @@ gen_le32(vl); gen_le32(vl >> 32); } else { - ind += 8; + gen_ind += 8; } if (tok != ',') break; @@ -401,7 +401,7 @@ gen_le16(e.v); } } else { - ind += size; + gen_ind += size; } if (tok != ',') break; @@ -456,10 +456,10 @@ next(); /* XXX: handle section symbols too */ n = asm_int_expr(s1); - if (n < ind) + if (n < gen_ind) error("attempt to .org backwards"); v = 0; - size = n - ind; + size = n - gen_ind; goto zero_pad; } break; @@ -674,13 +674,13 @@ /* default section is text */ cur_text_section = text_section; - ind = cur_text_section->data_offset; + gen_ind = cur_text_section->data_offset; define_start = define_stack; ret = tcc_assemble_internal(s1, do_preprocess); - cur_text_section->data_offset = ind; + cur_text_section->data_offset = gen_ind; free_defines(define_start); @@ -992,12 +992,12 @@ printf("asm_global: \"%s\"\n", (char *)astr.data); #endif cur_text_section = text_section; - ind = cur_text_section->data_offset; + gen_ind = cur_text_section->data_offset; /* assemble the string with tcc internal assembler */ tcc_assemble_inline(tcc_state, astr.data, astr.size - 1); - cur_text_section->data_offset = ind; + cur_text_section->data_offset = gen_ind; /* restore the current C token */ next();