History

rename i386-tok.h i386-asm.c, add PRINTF_ASM_CODE

jiang committed 12 years ago

Commit 2b2e7f81 parent ba61fd97 files · +53 −52Browse files

Unified · Split

7 files
  1. Makefile +4 −4
  2. asmx86-tok.h +0 −0
  3. asmx86.c +35 −6
  4. libtcc.c +2 −2
  5. tcc.h +1 −0
  6. tccasm.c +10 −39
  7. tcctok.h +1 −1
Makefile+4−4
@@ -101,11 +101,11 @@ $(ARM_EABI_CROSS)_LINK = arm-eabi-tcc$(EXESUF) · 100 unmodified lines
101101
102102 CORE_FILES = tcc.c libtcc.c tccpp.c tccgen.c tccelf.c tccasm.c tccrun.c
103103 CORE_FILES += tcc.h config.h libtcc.h tcctok.h
104−I386_FILES = $(CORE_FILES) i386-gen.c i386-asm.c i386-asm.h i386-tok.h
105−WIN32_FILES = $(CORE_FILES) i386-gen.c i386-asm.c i386-asm.h i386-tok.h tccpe.c
106−WIN64_FILES = $(CORE_FILES) x86_64-gen.c i386-asm.c x86_64-asm.h tccpe.c
104+I386_FILES = $(CORE_FILES) i386-gen.c asmx86.c i386-asm.h asmx86-tok.h
105+WIN32_FILES = $(CORE_FILES) i386-gen.c asmx86.c i386-asm.h asmx86-tok.h tccpe.c
106+WIN64_FILES = $(CORE_FILES) x86_64-gen.c asmx86.c x86_64-asm.h tccpe.c
107107 WINCE_FILES = $(CORE_FILES) arm-gen.c tccpe.c
108−X86_64_FILES = $(CORE_FILES) x86_64-gen.c i386-asm.c x86_64-asm.h
108+X86_64_FILES = $(CORE_FILES) x86_64-gen.c asmx86.c x86_64-asm.h
109109 ARM_FILES = $(CORE_FILES) arm-gen.c
110110 C67_FILES = $(CORE_FILES) c67-gen.c tcccoff.c
111111
asmx86-tok.hrenamed from i386-tok.h+0−0

File renamed without changes.

asmx86.crenamed from i386-asm.c+35−6
@@ -239,6 +239,36 @@ static const uint16_t op0_codes[] = { · 238 unmodified lines
239239 #endif
240240 };
241241
242+#ifdef PRINTF_ASM_CODE
243+void printf_asm_opcode(){
244+ const ASMInstr *pa;
245+ int freq[4];
246+ int op_vals[500];
247+ int nb_op_vals, i, j;
248+ nb_op_vals = 0;
249+ memset(freq, 0, sizeof(freq));
250+ for(pa = asm_instrs; pa->sym != 0; pa++) {
251+ freq[pa->nb_ops]++;
252+ for(i=0;i<pa->nb_ops;i++) {
253+ for(j=0;j<nb_op_vals;j++) {
254+ if (pa->op_type[i] == op_vals[j])
255+ goto found;
256+ }
257+ op_vals[nb_op_vals++] = pa->op_type[i];
258+ found: ;
259+ }
260+ }
261+ for(i=0;i<nb_op_vals;i++) {
262+ int v = op_vals[i];
263+ if ((v & (v - 1)) != 0)
264+ printf("%3d: %08x\n", i, v);
265+ }
266+ printf("size=%d nb=%d f0=%d f1=%d f2=%d f3=%d\n",
267+ (int)sizeof(asm_instrs), (int)sizeof(asm_instrs) / sizeof(ASMInstr),
268+ freq[0], freq[1], freq[2], freq[3]);
269+}
270+#endif
271+
242272 static inline int get_reg_shift(TCCState *s1)
243273 {
244274 int shift, v;
@@ -716,9 +746,8 @@ ST_FUNC void asm_opcode(TCCState *s1, int opcode) · 471 unmodified lines
716746 g(b >> 8);
717747 g(b);
718748 return;
719− } else if (opcode <= TOK_ASM_alllast) {
720− tcc_error("bad operand with opcode '%s'",
721− get_tok_str(opcode, NULL));
749+ } else if (opcode <= TOK_ASM_alllast) {
750+ tcc_error("bad operand with opcode '%s'", get_tok_str(opcode, NULL));
722751 } else {
723752 tcc_error("unknown opcode '%s'",
724753 get_tok_str(opcode, NULL));
@@ -1069,7 +1098,7 @@ ST_FUNC void asm_compute_constraints(ASMOperand *operands, · 344 unmodified lines
10691098 uint8_t regs_allocated[NB_ASM_REGS];
10701099
10711100 /* init fields */
1072− for(i=0;i<nb_operands;i++) {
1101+ for(i=0; i<nb_operands; i++) {
10731102 op = &operands[i];
10741103 op->input_index = -1;
10751104 op->ref_index = -1;
@@ -1079,7 +1108,7 @@ ST_FUNC void asm_compute_constraints(ASMOperand *operands, · 3 unmodified lines
10791108 }
10801109 /* compute constraint priority and evaluate references to output
10811110 constraints if input constraints */
1082− for(i=0;i<nb_operands;i++) {
1111+ for(i=0; i<nb_operands; i++) {
10831112 op = &operands[i];
10841113 str = op->constraint;
10851114 str = skip_constraint_modifiers(str);
@@ -1499,4 +1528,4 @@ ST_FUNC void asm_clobber(uint8_t *clobber_regs, const char *str) · 413 unmodified lines
14991528 tcc_error("invalid clobber register '%s'", str);
15001529 }
15011530 clobber_regs[reg] = 1;
1502−}
1531+}
libtcc.c+2−2
@@ -52,10 +52,10 @@ ST_DATA struct TCCState *tcc_state; · 51 unmodified lines
5252 #include "x86_64-gen.c"
5353 #endif
5454 #ifdef CONFIG_TCC_ASM
55−#include "tccasm.c"
5655 #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
57−#include "i386-asm.c"
56+#include "asmx86.c"
5857 #endif
58+#include "tccasm.c"
5959 #endif
6060 #ifdef TCC_TARGET_COFF
6161 #include "tcccoff.c"
tcc.h+1−0
@@ -147,6 +147,7 @@ · 146 unmodified lines
147147 /* #define MEM_DEBUG */
148148 /* assembler debug */
149149 /* #define ASM_DEBUG */
150+/* #define PRINTF_ASM_CODE */
150151
151152 /* target selection */
152153 /* #define TCC_TARGET_I386 *//* i386 code generator */
tccasm.c+10−39
@@ -20,7 +20,6 @@ · 19 unmodified lines
2020
2121 #include "tcc.h"
2222 #ifdef CONFIG_TCC_ASM
23−
2423 ST_FUNC int asm_get_local_label_name(TCCState *s1, unsigned int n)
2524 {
2625 char buf[64];
@@ -483,7 +482,7 @@ static void asm_parse_directive(TCCState *s1) · 456 unmodified lines
483482 case TOK_ASM_globl:
484483 case TOK_ASM_global:
485484 case TOK_ASM_weak:
486− case TOK_ASM_hidden:
485+ case TOK_ASM_hidden:
487486 tok1 = tok;
488487 do {
489488 Sym *sym;
@@ -494,12 +493,12 @@ static void asm_parse_directive(TCCState *s1) · 4 unmodified lines
494493 sym = label_push(&s1->asm_labels, tok, 0);
495494 sym->type.t = VT_VOID;
496495 }
497− if (tok1 != TOK_ASM_hidden)
496+ if (tok1 != TOK_ASM_hidden)
498497 sym->type.t &= ~VT_STATIC;
499498 if (tok1 == TOK_ASM_weak)
500499 sym->type.t |= VT_WEAK;
501− else if (tok1 == TOK_ASM_hidden)
502− sym->type.t |= STV_HIDDEN << VT_VIS_SHIFT;
500+ else if (tok1 == TOK_ASM_hidden)
501+ sym->type.t |= STV_HIDDEN << VT_VIS_SHIFT;
503502 next();
504503 } while (tok == ',');
505504 break;
@@ -697,42 +696,15 @@ static void asm_parse_directive(TCCState *s1) · 191 unmodified lines
697696 }
698697 }
699698
700−
701699 /* assemble a file */
702700 static int tcc_assemble_internal(TCCState *s1, int do_preprocess)
703701 {
704702 int opcode;
705703
706−#if 0
704+#ifdef PRINTF_ASM_CODE
705+ ST_FUNC void printf_asm_opcode();
707706 /* print stats about opcodes */
708− {
709− const ASMInstr *pa;
710− int freq[4];
711− int op_vals[500];
712− int nb_op_vals, i, j;
713−
714− nb_op_vals = 0;
715− memset(freq, 0, sizeof(freq));
716− for(pa = asm_instrs; pa->sym != 0; pa++) {
717− freq[pa->nb_ops]++;
718− for(i=0;i<pa->nb_ops;i++) {
719− for(j=0;j<nb_op_vals;j++) {
720− if (pa->op_type[i] == op_vals[j])
721− goto found;
722− }
723− op_vals[nb_op_vals++] = pa->op_type[i];
724− found: ;
725− }
726− }
727− for(i=0;i<nb_op_vals;i++) {
728− int v = op_vals[i];
729− if ((v & (v - 1)) != 0)
730− printf("%3d: %08x\n", i, v);
731− }
732− printf("size=%d nb=%d f0=%d f1=%d f2=%d f3=%d\n",
733− sizeof(asm_instrs), sizeof(asm_instrs) / sizeof(ASMInstr),
734− freq[0], freq[1], freq[2], freq[3]);
735− }
707+ printf_asm_opcode();
736708 #endif
737709
738710 /* XXX: undefine C labels */
@@ -814,9 +786,8 @@ ST_FUNC int tcc_assemble(TCCState *s1, int do_preprocess) · 75 unmodified lines
814786
815787 /* an elf symbol of type STT_FILE must be put so that STB_LOCAL
816788 symbols can be safely used */
817− put_elf_sym(symtab_section, 0, 0,
818− ELFW(ST_INFO)(STB_LOCAL, STT_FILE), 0,
819− SHN_ABS, file->filename);
789+ put_elf_sym(symtab_section, 0, 0, ELFW(ST_INFO)(STB_LOCAL, STT_FILE), 0,
790+ SHN_ABS, file->filename);
820791
821792 ret = tcc_assemble_internal(s1, do_preprocess);
822793
@@ -1119,4 +1090,4 @@ ST_FUNC void asm_global_instr(void) · 296 unmodified lines
11191090
11201091 cstr_free(&astr);
11211092 }
1122−#endif /* CONFIG_TCC_ASM */
1093+#endif /* CONFIG_TCC_ASM */
tcctok.h+1−1
@@ -285,5 +285,5 @@ · 284 unmodified lines
285285 #endif
286286
287287 #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
288−#include "i386-tok.h"
288+#include "asmx86-tok.h"
289289 #endif