Unified · Split
| @@ -101,11 +101,11 @@ $(ARM_EABI_CROSS)_LINK = arm-eabi-tcc$(EXESUF) · 100 unmodified lines | ||
| 101 | 101 | |
| 102 | 102 | CORE_FILES = tcc.c libtcc.c tccpp.c tccgen.c tccelf.c tccasm.c tccrun.c |
| 103 | 103 | 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 | |
| 107 | 107 | 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 | |
| 109 | 109 | ARM_FILES = $(CORE_FILES) arm-gen.c |
| 110 | 110 | C67_FILES = $(CORE_FILES) c67-gen.c tcccoff.c |
| 111 | 111 | |
File renamed without changes.
| @@ -239,6 +239,36 @@ static const uint16_t op0_codes[] = { · 238 unmodified lines | ||
| 239 | 239 | #endif |
| 240 | 240 | }; |
| 241 | 241 | |
| 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 | + | |
| 242 | 272 | static inline int get_reg_shift(TCCState *s1) |
| 243 | 273 | { |
| 244 | 274 | int shift, v; |
| @@ -716,9 +746,8 @@ ST_FUNC void asm_opcode(TCCState *s1, int opcode) · 471 unmodified lines | ||
| 716 | 746 | g(b >> 8); |
| 717 | 747 | g(b); |
| 718 | 748 | 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)); | |
| 722 | 751 | } else { |
| 723 | 752 | tcc_error("unknown opcode '%s'", |
| 724 | 753 | get_tok_str(opcode, NULL)); |
| @@ -1069,7 +1098,7 @@ ST_FUNC void asm_compute_constraints(ASMOperand *operands, · 344 unmodified lines | ||
| 1069 | 1098 | uint8_t regs_allocated[NB_ASM_REGS]; |
| 1070 | 1099 | |
| 1071 | 1100 | /* init fields */ |
| 1072 | − for(i=0;i<nb_operands;i++) { | |
| 1101 | + for(i=0; i<nb_operands; i++) { | |
| 1073 | 1102 | op = &operands[i]; |
| 1074 | 1103 | op->input_index = -1; |
| 1075 | 1104 | op->ref_index = -1; |
| @@ -1079,7 +1108,7 @@ ST_FUNC void asm_compute_constraints(ASMOperand *operands, · 3 unmodified lines | ||
| 1079 | 1108 | } |
| 1080 | 1109 | /* compute constraint priority and evaluate references to output |
| 1081 | 1110 | constraints if input constraints */ |
| 1082 | − for(i=0;i<nb_operands;i++) { | |
| 1111 | + for(i=0; i<nb_operands; i++) { | |
| 1083 | 1112 | op = &operands[i]; |
| 1084 | 1113 | str = op->constraint; |
| 1085 | 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 | 1528 | tcc_error("invalid clobber register '%s'", str); |
| 1500 | 1529 | } |
| 1501 | 1530 | clobber_regs[reg] = 1; |
| 1502 | −} | |
| 1531 | +} | |
| @@ -52,10 +52,10 @@ ST_DATA struct TCCState *tcc_state; · 51 unmodified lines | ||
| 52 | 52 | #include "x86_64-gen.c" |
| 53 | 53 | #endif |
| 54 | 54 | #ifdef CONFIG_TCC_ASM |
| 55 | −#include "tccasm.c" | |
| 56 | 55 | #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64 |
| 57 | −#include "i386-asm.c" | |
| 56 | +#include "asmx86.c" | |
| 58 | 57 | #endif |
| 58 | +#include "tccasm.c" | |
| 59 | 59 | #endif |
| 60 | 60 | #ifdef TCC_TARGET_COFF |
| 61 | 61 | #include "tcccoff.c" |
| @@ -147,6 +147,7 @@ · 146 unmodified lines | ||
| 147 | 147 | /* #define MEM_DEBUG */ |
| 148 | 148 | /* assembler debug */ |
| 149 | 149 | /* #define ASM_DEBUG */ |
| 150 | +/* #define PRINTF_ASM_CODE */ | |
| 150 | 151 | |
| 151 | 152 | /* target selection */ |
| 152 | 153 | /* #define TCC_TARGET_I386 *//* i386 code generator */ |
| @@ -20,7 +20,6 @@ · 19 unmodified lines | ||
| 20 | 20 | |
| 21 | 21 | #include "tcc.h" |
| 22 | 22 | #ifdef CONFIG_TCC_ASM |
| 23 | − | |
| 24 | 23 | ST_FUNC int asm_get_local_label_name(TCCState *s1, unsigned int n) |
| 25 | 24 | { |
| 26 | 25 | char buf[64]; |
| @@ -483,7 +482,7 @@ static void asm_parse_directive(TCCState *s1) · 456 unmodified lines | ||
| 483 | 482 | case TOK_ASM_globl: |
| 484 | 483 | case TOK_ASM_global: |
| 485 | 484 | case TOK_ASM_weak: |
| 486 | − case TOK_ASM_hidden: | |
| 485 | + case TOK_ASM_hidden: | |
| 487 | 486 | tok1 = tok; |
| 488 | 487 | do { |
| 489 | 488 | Sym *sym; |
| @@ -494,12 +493,12 @@ static void asm_parse_directive(TCCState *s1) · 4 unmodified lines | ||
| 494 | 493 | sym = label_push(&s1->asm_labels, tok, 0); |
| 495 | 494 | sym->type.t = VT_VOID; |
| 496 | 495 | } |
| 497 | − if (tok1 != TOK_ASM_hidden) | |
| 496 | + if (tok1 != TOK_ASM_hidden) | |
| 498 | 497 | sym->type.t &= ~VT_STATIC; |
| 499 | 498 | if (tok1 == TOK_ASM_weak) |
| 500 | 499 | 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; | |
| 503 | 502 | next(); |
| 504 | 503 | } while (tok == ','); |
| 505 | 504 | break; |
| @@ -697,42 +696,15 @@ static void asm_parse_directive(TCCState *s1) · 191 unmodified lines | ||
| 697 | 696 | } |
| 698 | 697 | } |
| 699 | 698 | |
| 700 | − | |
| 701 | 699 | /* assemble a file */ |
| 702 | 700 | static int tcc_assemble_internal(TCCState *s1, int do_preprocess) |
| 703 | 701 | { |
| 704 | 702 | int opcode; |
| 705 | 703 | |
| 706 | −#if 0 | |
| 704 | +#ifdef PRINTF_ASM_CODE | |
| 705 | + ST_FUNC void printf_asm_opcode(); | |
| 707 | 706 | /* 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(); | |
| 736 | 708 | #endif |
| 737 | 709 | |
| 738 | 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 | 787 | /* an elf symbol of type STT_FILE must be put so that STB_LOCAL |
| 816 | 788 | 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); | |
| 820 | 791 | |
| 821 | 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 | 1091 | cstr_free(&astr); |
| 1121 | 1092 | } |
| 1122 | −#endif /* CONFIG_TCC_ASM */ | |
| 1093 | +#endif /* CONFIG_TCC_ASM */ | |
| @@ -285,5 +285,5 @@ · 284 unmodified lines | ||
| 285 | 285 | #endif |
| 286 | 286 | |
| 287 | 287 | #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64 |
| 288 | −#include "i386-tok.h" | |
| 288 | +#include "asmx86-tok.h" | |
| 289 | 289 | #endif |