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
101 101
102CORE_FILES = tcc.c libtcc.c tccpp.c tccgen.c tccelf.c tccasm.c tccrun.c102CORE_FILES = tcc.c libtcc.c tccpp.c tccgen.c tccelf.c tccasm.c tccrun.c
103CORE_FILES += tcc.h config.h libtcc.h tcctok.h103CORE_FILES += tcc.h config.h libtcc.h tcctok.h
104I386_FILES = $(CORE_FILES) i386-gen.c i386-asm.c i386-asm.h i386-tok.h104I386_FILES = $(CORE_FILES) i386-gen.c asmx86.c i386-asm.h asmx86-tok.h
105WIN32_FILES = $(CORE_FILES) i386-gen.c i386-asm.c i386-asm.h i386-tok.h tccpe.c105WIN32_FILES = $(CORE_FILES) i386-gen.c asmx86.c i386-asm.h asmx86-tok.h tccpe.c
106WIN64_FILES = $(CORE_FILES) x86_64-gen.c i386-asm.c x86_64-asm.h tccpe.c106WIN64_FILES = $(CORE_FILES) x86_64-gen.c asmx86.c x86_64-asm.h tccpe.c
107WINCE_FILES = $(CORE_FILES) arm-gen.c tccpe.c107WINCE_FILES = $(CORE_FILES) arm-gen.c tccpe.c
108X86_64_FILES = $(CORE_FILES) x86_64-gen.c i386-asm.c x86_64-asm.h108X86_64_FILES = $(CORE_FILES) x86_64-gen.c asmx86.c x86_64-asm.h
109ARM_FILES = $(CORE_FILES) arm-gen.c109ARM_FILES = $(CORE_FILES) arm-gen.c
110C67_FILES = $(CORE_FILES) c67-gen.c tcccoff.c110C67_FILES = $(CORE_FILES) c67-gen.c tcccoff.c
111 111
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
239#endif239#endif
240};240};
241 241
242#ifdef PRINTF_ASM_CODE
243void 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
242static inline int get_reg_shift(TCCState *s1)272static inline int get_reg_shift(TCCState *s1)
243{273{
244 int shift, v;274 int shift, v;
@@ -716,9 +746,8 @@ ST_FUNC void asm_opcode(TCCState *s1, int opcode) · 471 unmodified lines
716 g(b >> 8);746 g(b >> 8);
717 g(b);747 g(b);
718 return;748 return;
719 } else if (opcode <= TOK_ASM_alllast) {749 } else if (opcode <= TOK_ASM_alllast) {
720 tcc_error("bad operand with opcode '%s'",750 tcc_error("bad operand with opcode '%s'", get_tok_str(opcode, NULL));
721 get_tok_str(opcode, NULL));
722 } else {751 } else {
723 tcc_error("unknown opcode '%s'",752 tcc_error("unknown opcode '%s'",
724 get_tok_str(opcode, NULL));753 get_tok_str(opcode, NULL));
@@ -1069,7 +1098,7 @@ ST_FUNC void asm_compute_constraints(ASMOperand *operands, · 344 unmodified lines
1069 uint8_t regs_allocated[NB_ASM_REGS];1098 uint8_t regs_allocated[NB_ASM_REGS];
1070 1099
1071 /* init fields */1100 /* init fields */
1072 for(i=0;i<nb_operands;i++) {1101 for(i=0; i<nb_operands; i++) {
1073 op = &operands[i];1102 op = &operands[i];
1074 op->input_index = -1;1103 op->input_index = -1;
1075 op->ref_index = -1;1104 op->ref_index = -1;
@@ -1079,7 +1108,7 @@ ST_FUNC void asm_compute_constraints(ASMOperand *operands, · 3 unmodified lines
1079 }1108 }
1080 /* compute constraint priority and evaluate references to output1109 /* compute constraint priority and evaluate references to output
1081 constraints if input constraints */1110 constraints if input constraints */
1082 for(i=0;i<nb_operands;i++) {1111 for(i=0; i<nb_operands; i++) {
1083 op = &operands[i];1112 op = &operands[i];
1084 str = op->constraint;1113 str = op->constraint;
1085 str = skip_constraint_modifiers(str);1114 str = skip_constraint_modifiers(str);
@@ -1499,4 +1528,4 @@ ST_FUNC void asm_clobber(uint8_t *clobber_regs, const char *str) · 413 unmodified lines
1499 tcc_error("invalid clobber register '%s'", str);1528 tcc_error("invalid clobber register '%s'", str);
1500 }1529 }
1501 clobber_regs[reg] = 1;1530 clobber_regs[reg] = 1;
1502}1531}
libtcc.c+2−2
@@ -52,10 +52,10 @@ ST_DATA struct TCCState *tcc_state; · 51 unmodified lines
52#include "x86_64-gen.c"52#include "x86_64-gen.c"
53#endif53#endif
54#ifdef CONFIG_TCC_ASM54#ifdef CONFIG_TCC_ASM
55#include "tccasm.c"
56#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_6455#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
57#include "i386-asm.c"56#include "asmx86.c"
58#endif57#endif
58#include "tccasm.c"
59#endif59#endif
60#ifdef TCC_TARGET_COFF60#ifdef TCC_TARGET_COFF
61#include "tcccoff.c"61#include "tcccoff.c"
tcc.h+1−0
@@ -147,6 +147,7 @@ · 146 unmodified lines
147/* #define MEM_DEBUG */147/* #define MEM_DEBUG */
148/* assembler debug */148/* assembler debug */
149/* #define ASM_DEBUG */149/* #define ASM_DEBUG */
150/* #define PRINTF_ASM_CODE */
150 151
151/* target selection */152/* target selection */
152/* #define TCC_TARGET_I386 *//* i386 code generator */153/* #define TCC_TARGET_I386 *//* i386 code generator */
tccasm.c+10−39
@@ -20,7 +20,6 @@ · 19 unmodified lines
20 20
21#include "tcc.h"21#include "tcc.h"
22#ifdef CONFIG_TCC_ASM22#ifdef CONFIG_TCC_ASM
23
24ST_FUNC int asm_get_local_label_name(TCCState *s1, unsigned int n)23ST_FUNC int asm_get_local_label_name(TCCState *s1, unsigned int n)
25{24{
26 char buf[64];25 char buf[64];
@@ -483,7 +482,7 @@ static void asm_parse_directive(TCCState *s1) · 456 unmodified lines
483 case TOK_ASM_globl:482 case TOK_ASM_globl:
484 case TOK_ASM_global:483 case TOK_ASM_global:
485 case TOK_ASM_weak:484 case TOK_ASM_weak:
486 case TOK_ASM_hidden:485 case TOK_ASM_hidden:
487 tok1 = tok;486 tok1 = tok;
488 do { 487 do {
489 Sym *sym;488 Sym *sym;
@@ -494,12 +493,12 @@ static void asm_parse_directive(TCCState *s1) · 4 unmodified lines
494 sym = label_push(&s1->asm_labels, tok, 0);493 sym = label_push(&s1->asm_labels, tok, 0);
495 sym->type.t = VT_VOID;494 sym->type.t = VT_VOID;
496 }495 }
497 if (tok1 != TOK_ASM_hidden)496 if (tok1 != TOK_ASM_hidden)
498 sym->type.t &= ~VT_STATIC;497 sym->type.t &= ~VT_STATIC;
499 if (tok1 == TOK_ASM_weak)498 if (tok1 == TOK_ASM_weak)
500 sym->type.t |= VT_WEAK;499 sym->type.t |= VT_WEAK;
501 else if (tok1 == TOK_ASM_hidden)500 else if (tok1 == TOK_ASM_hidden)
502 sym->type.t |= STV_HIDDEN << VT_VIS_SHIFT;501 sym->type.t |= STV_HIDDEN << VT_VIS_SHIFT;
503 next();502 next();
504 } while (tok == ',');503 } while (tok == ',');
505 break;504 break;
@@ -697,42 +696,15 @@ static void asm_parse_directive(TCCState *s1) · 191 unmodified lines
697 }696 }
698}697}
699 698
700
701/* assemble a file */699/* assemble a file */
702static int tcc_assemble_internal(TCCState *s1, int do_preprocess)700static int tcc_assemble_internal(TCCState *s1, int do_preprocess)
703{701{
704 int opcode;702 int opcode;
705 703
706#if 0704#ifdef PRINTF_ASM_CODE
705 ST_FUNC void printf_asm_opcode();
707 /* print stats about opcodes */706 /* print stats about opcodes */
708 {707 printf_asm_opcode();
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 }
736#endif708#endif
737 709
738 /* XXX: undefine C labels */710 /* XXX: undefine C labels */
@@ -814,9 +786,8 @@ ST_FUNC int tcc_assemble(TCCState *s1, int do_preprocess) · 75 unmodified lines
814 786
815 /* an elf symbol of type STT_FILE must be put so that STB_LOCAL787 /* an elf symbol of type STT_FILE must be put so that STB_LOCAL
816 symbols can be safely used */788 symbols can be safely used */
817 put_elf_sym(symtab_section, 0, 0,789 put_elf_sym(symtab_section, 0, 0, ELFW(ST_INFO)(STB_LOCAL, STT_FILE), 0,
818 ELFW(ST_INFO)(STB_LOCAL, STT_FILE), 0,790 SHN_ABS, file->filename);
819 SHN_ABS, file->filename);
820 791
821 ret = tcc_assemble_internal(s1, do_preprocess);792 ret = tcc_assemble_internal(s1, do_preprocess);
822 793
@@ -1119,4 +1090,4 @@ ST_FUNC void asm_global_instr(void) · 296 unmodified lines
1119 1090
1120 cstr_free(&astr);1091 cstr_free(&astr);
1121}1092}
1122#endif /* CONFIG_TCC_ASM */1093#endif /* CONFIG_TCC_ASM */
tcctok.h+1−1
@@ -285,5 +285,5 @@ · 284 unmodified lines
285#endif285#endif
286 286
287#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64287#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
288#include "i386-tok.h"288#include "asmx86-tok.h"
289#endif289#endif