From 2b2e7f85d7119677f0ffdd4c1bde5d3095dead4e Mon Sep 17 00:00:00 2001 From: jiang <30155751@qq.com> Date: Wed, 30 Apr 2014 19:30:30 +0800 Subject: [PATCH] rename i386-tok.h i386-asm.c, add PRINTF_ASM_CODE --- Makefile | 8 +++---- i386-tok.h => asmx86-tok.h | 0 i386-asm.c => asmx86.c | 41 ++++++++++++++++++++++++++----- libtcc.c | 4 ++-- tcc.h | 1 + tccasm.c | 49 ++++++++------------------------------ tcctok.h | 2 +- 7 files changed, 53 insertions(+), 52 deletions(-) rename i386-tok.h => asmx86-tok.h (100%) rename i386-asm.c => asmx86.c (98%) diff --git a/Makefile b/Makefile index 3d28f3f..0f3002b 100644 --- a/Makefile +++ b/Makefile @@ -101,11 +101,11 @@ $(ARM_EABI_CROSS)_LINK = arm-eabi-tcc$(EXESUF) CORE_FILES = tcc.c libtcc.c tccpp.c tccgen.c tccelf.c tccasm.c tccrun.c CORE_FILES += tcc.h config.h libtcc.h tcctok.h -I386_FILES = $(CORE_FILES) i386-gen.c i386-asm.c i386-asm.h i386-tok.h -WIN32_FILES = $(CORE_FILES) i386-gen.c i386-asm.c i386-asm.h i386-tok.h tccpe.c -WIN64_FILES = $(CORE_FILES) x86_64-gen.c i386-asm.c x86_64-asm.h tccpe.c +I386_FILES = $(CORE_FILES) i386-gen.c asmx86.c i386-asm.h asmx86-tok.h +WIN32_FILES = $(CORE_FILES) i386-gen.c asmx86.c i386-asm.h asmx86-tok.h tccpe.c +WIN64_FILES = $(CORE_FILES) x86_64-gen.c asmx86.c x86_64-asm.h tccpe.c WINCE_FILES = $(CORE_FILES) arm-gen.c tccpe.c -X86_64_FILES = $(CORE_FILES) x86_64-gen.c i386-asm.c x86_64-asm.h +X86_64_FILES = $(CORE_FILES) x86_64-gen.c asmx86.c x86_64-asm.h ARM_FILES = $(CORE_FILES) arm-gen.c C67_FILES = $(CORE_FILES) c67-gen.c tcccoff.c diff --git a/i386-tok.h b/asmx86-tok.h similarity index 100% rename from i386-tok.h rename to asmx86-tok.h diff --git a/i386-asm.c b/asmx86.c similarity index 98% rename from i386-asm.c rename to asmx86.c index a524658..9010c03 100644 --- a/i386-asm.c +++ b/asmx86.c @@ -239,6 +239,36 @@ static const uint16_t op0_codes[] = { #endif }; +#ifdef PRINTF_ASM_CODE +void printf_asm_opcode(){ + const ASMInstr *pa; + int freq[4]; + int op_vals[500]; + int nb_op_vals, i, j; + nb_op_vals = 0; + memset(freq, 0, sizeof(freq)); + for(pa = asm_instrs; pa->sym != 0; pa++) { + freq[pa->nb_ops]++; + for(i=0;inb_ops;i++) { + for(j=0;jop_type[i] == op_vals[j]) + goto found; + } + op_vals[nb_op_vals++] = pa->op_type[i]; + found: ; + } + } + for(i=0;i> 8); g(b); return; - } else if (opcode <= TOK_ASM_alllast) { - tcc_error("bad operand with opcode '%s'", - get_tok_str(opcode, NULL)); + } else if (opcode <= TOK_ASM_alllast) { + tcc_error("bad operand with opcode '%s'", get_tok_str(opcode, NULL)); } else { tcc_error("unknown opcode '%s'", get_tok_str(opcode, NULL)); @@ -1069,7 +1098,7 @@ ST_FUNC void asm_compute_constraints(ASMOperand *operands, uint8_t regs_allocated[NB_ASM_REGS]; /* init fields */ - for(i=0;iinput_index = -1; op->ref_index = -1; @@ -1079,7 +1108,7 @@ ST_FUNC void asm_compute_constraints(ASMOperand *operands, } /* compute constraint priority and evaluate references to output constraints if input constraints */ - for(i=0;iconstraint; str = skip_constraint_modifiers(str); @@ -1499,4 +1528,4 @@ ST_FUNC void asm_clobber(uint8_t *clobber_regs, const char *str) tcc_error("invalid clobber register '%s'", str); } clobber_regs[reg] = 1; -} +} \ No newline at end of file diff --git a/libtcc.c b/libtcc.c index deda7e6..b9f5952 100644 --- a/libtcc.c +++ b/libtcc.c @@ -52,10 +52,10 @@ ST_DATA struct TCCState *tcc_state; #include "x86_64-gen.c" #endif #ifdef CONFIG_TCC_ASM -#include "tccasm.c" #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64 -#include "i386-asm.c" +#include "asmx86.c" #endif +#include "tccasm.c" #endif #ifdef TCC_TARGET_COFF #include "tcccoff.c" diff --git a/tcc.h b/tcc.h index b12a713..d114f53 100644 --- a/tcc.h +++ b/tcc.h @@ -147,6 +147,7 @@ /* #define MEM_DEBUG */ /* assembler debug */ /* #define ASM_DEBUG */ +/* #define PRINTF_ASM_CODE */ /* target selection */ /* #define TCC_TARGET_I386 *//* i386 code generator */ diff --git a/tccasm.c b/tccasm.c index 38efe1c..eec4208 100644 --- a/tccasm.c +++ b/tccasm.c @@ -20,7 +20,6 @@ #include "tcc.h" #ifdef CONFIG_TCC_ASM - ST_FUNC int asm_get_local_label_name(TCCState *s1, unsigned int n) { char buf[64]; @@ -483,7 +482,7 @@ static void asm_parse_directive(TCCState *s1) case TOK_ASM_globl: case TOK_ASM_global: case TOK_ASM_weak: - case TOK_ASM_hidden: + case TOK_ASM_hidden: tok1 = tok; do { Sym *sym; @@ -494,12 +493,12 @@ static void asm_parse_directive(TCCState *s1) sym = label_push(&s1->asm_labels, tok, 0); sym->type.t = VT_VOID; } - if (tok1 != TOK_ASM_hidden) + if (tok1 != TOK_ASM_hidden) sym->type.t &= ~VT_STATIC; if (tok1 == TOK_ASM_weak) sym->type.t |= VT_WEAK; - else if (tok1 == TOK_ASM_hidden) - sym->type.t |= STV_HIDDEN << VT_VIS_SHIFT; + else if (tok1 == TOK_ASM_hidden) + sym->type.t |= STV_HIDDEN << VT_VIS_SHIFT; next(); } while (tok == ','); break; @@ -697,42 +696,15 @@ static void asm_parse_directive(TCCState *s1) } } - /* assemble a file */ static int tcc_assemble_internal(TCCState *s1, int do_preprocess) { int opcode; -#if 0 +#ifdef PRINTF_ASM_CODE + ST_FUNC void printf_asm_opcode(); /* print stats about opcodes */ - { - const ASMInstr *pa; - int freq[4]; - int op_vals[500]; - int nb_op_vals, i, j; - - nb_op_vals = 0; - memset(freq, 0, sizeof(freq)); - for(pa = asm_instrs; pa->sym != 0; pa++) { - freq[pa->nb_ops]++; - for(i=0;inb_ops;i++) { - for(j=0;jop_type[i] == op_vals[j]) - goto found; - } - op_vals[nb_op_vals++] = pa->op_type[i]; - found: ; - } - } - for(i=0;ifilename); + put_elf_sym(symtab_section, 0, 0, ELFW(ST_INFO)(STB_LOCAL, STT_FILE), 0, + SHN_ABS, file->filename); ret = tcc_assemble_internal(s1, do_preprocess); @@ -1119,4 +1090,4 @@ ST_FUNC void asm_global_instr(void) cstr_free(&astr); } -#endif /* CONFIG_TCC_ASM */ +#endif /* CONFIG_TCC_ASM */ \ No newline at end of file diff --git a/tcctok.h b/tcctok.h index 735ccdd..6fc8308 100644 --- a/tcctok.h +++ b/tcctok.h @@ -285,5 +285,5 @@ #endif #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64 -#include "i386-tok.h" +#include "asmx86-tok.h" #endif