rename i386-tok.h i386-asm.c, add PRINTF_ASM_CODE
This commit is contained in:
		
							parent
							
								
									ba61fd9cd1
								
							
						
					
					
						commit
						2b2e7f85d7
					
				
					 7 changed files with 53 additions and 52 deletions
				
			
		
							
								
								
									
										8
									
								
								Makefile
									
										
									
									
									
								
							
							
						
						
									
										8
									
								
								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.c libtcc.c tccpp.c tccgen.c tccelf.c tccasm.c tccrun.c
 | 
				
			||||||
CORE_FILES += tcc.h config.h libtcc.h tcctok.h
 | 
					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
 | 
					I386_FILES = $(CORE_FILES) i386-gen.c asmx86.c i386-asm.h asmx86-tok.h
 | 
				
			||||||
WIN32_FILES = $(CORE_FILES) i386-gen.c i386-asm.c i386-asm.h i386-tok.h tccpe.c
 | 
					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 i386-asm.c x86_64-asm.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
 | 
					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
 | 
					ARM_FILES = $(CORE_FILES) arm-gen.c
 | 
				
			||||||
C67_FILES = $(CORE_FILES) c67-gen.c tcccoff.c
 | 
					C67_FILES = $(CORE_FILES) c67-gen.c tcccoff.c
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -239,6 +239,36 @@ static const uint16_t op0_codes[] = {
 | 
				
			||||||
#endif
 | 
					#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;i<pa->nb_ops;i++) {
 | 
				
			||||||
 | 
								for(j=0;j<nb_op_vals;j++) {
 | 
				
			||||||
 | 
									if (pa->op_type[i] == op_vals[j])
 | 
				
			||||||
 | 
										goto found;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								op_vals[nb_op_vals++] = pa->op_type[i];
 | 
				
			||||||
 | 
							found: ;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						for(i=0;i<nb_op_vals;i++) {
 | 
				
			||||||
 | 
							int v = op_vals[i];
 | 
				
			||||||
 | 
							if ((v & (v - 1)) != 0)
 | 
				
			||||||
 | 
								printf("%3d: %08x\n", i, v);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						printf("size=%d nb=%d f0=%d f1=%d f2=%d f3=%d\n",
 | 
				
			||||||
 | 
							(int)sizeof(asm_instrs), (int)sizeof(asm_instrs) / sizeof(ASMInstr),
 | 
				
			||||||
 | 
							freq[0], freq[1], freq[2], freq[3]);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static inline int get_reg_shift(TCCState *s1)
 | 
					static inline int get_reg_shift(TCCState *s1)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    int shift, v;
 | 
					    int shift, v;
 | 
				
			||||||
| 
						 | 
					@ -716,9 +746,8 @@ ST_FUNC void asm_opcode(TCCState *s1, int opcode)
 | 
				
			||||||
                g(b >> 8);
 | 
					                g(b >> 8);
 | 
				
			||||||
            g(b);
 | 
					            g(b);
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        } else if (opcode <= TOK_ASM_alllast) {
 | 
							} else if (opcode <= TOK_ASM_alllast) {
 | 
				
			||||||
            tcc_error("bad operand with opcode '%s'",
 | 
					            tcc_error("bad operand with opcode '%s'", get_tok_str(opcode, NULL));
 | 
				
			||||||
                  get_tok_str(opcode, NULL));
 | 
					 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            tcc_error("unknown opcode '%s'",
 | 
					            tcc_error("unknown opcode '%s'",
 | 
				
			||||||
                  get_tok_str(opcode, NULL));
 | 
					                  get_tok_str(opcode, NULL));
 | 
				
			||||||
| 
						 | 
					@ -1069,7 +1098,7 @@ ST_FUNC void asm_compute_constraints(ASMOperand *operands,
 | 
				
			||||||
    uint8_t regs_allocated[NB_ASM_REGS];
 | 
					    uint8_t regs_allocated[NB_ASM_REGS];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* init fields */
 | 
					    /* init fields */
 | 
				
			||||||
    for(i=0;i<nb_operands;i++) {
 | 
					    for(i=0; i<nb_operands; i++) {
 | 
				
			||||||
        op = &operands[i];
 | 
					        op = &operands[i];
 | 
				
			||||||
        op->input_index = -1;
 | 
					        op->input_index = -1;
 | 
				
			||||||
        op->ref_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
 | 
					    /* compute constraint priority and evaluate references to output
 | 
				
			||||||
       constraints if input constraints */
 | 
					       constraints if input constraints */
 | 
				
			||||||
    for(i=0;i<nb_operands;i++) {
 | 
					    for(i=0; i<nb_operands; i++) {
 | 
				
			||||||
        op = &operands[i];
 | 
					        op = &operands[i];
 | 
				
			||||||
        str = op->constraint;
 | 
					        str = op->constraint;
 | 
				
			||||||
        str = skip_constraint_modifiers(str);
 | 
					        str = skip_constraint_modifiers(str);
 | 
				
			||||||
							
								
								
									
										4
									
								
								libtcc.c
									
										
									
									
									
								
							
							
						
						
									
										4
									
								
								libtcc.c
									
										
									
									
									
								
							| 
						 | 
					@ -52,10 +52,10 @@ ST_DATA struct TCCState *tcc_state;
 | 
				
			||||||
#include "x86_64-gen.c"
 | 
					#include "x86_64-gen.c"
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
#ifdef CONFIG_TCC_ASM
 | 
					#ifdef CONFIG_TCC_ASM
 | 
				
			||||||
#include "tccasm.c"
 | 
					 | 
				
			||||||
#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
 | 
					#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
 | 
				
			||||||
#include "i386-asm.c"
 | 
					#include "asmx86.c"
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					#include "tccasm.c"
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
#ifdef TCC_TARGET_COFF
 | 
					#ifdef TCC_TARGET_COFF
 | 
				
			||||||
#include "tcccoff.c"
 | 
					#include "tcccoff.c"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										1
									
								
								tcc.h
									
										
									
									
									
								
							
							
						
						
									
										1
									
								
								tcc.h
									
										
									
									
									
								
							| 
						 | 
					@ -147,6 +147,7 @@
 | 
				
			||||||
/* #define MEM_DEBUG */
 | 
					/* #define MEM_DEBUG */
 | 
				
			||||||
/* assembler debug */
 | 
					/* assembler debug */
 | 
				
			||||||
/* #define ASM_DEBUG */
 | 
					/* #define ASM_DEBUG */
 | 
				
			||||||
 | 
					/* #define PRINTF_ASM_CODE */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* target selection */
 | 
					/* target selection */
 | 
				
			||||||
/* #define TCC_TARGET_I386   *//* i386 code generator */
 | 
					/* #define TCC_TARGET_I386   *//* i386 code generator */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										47
									
								
								tccasm.c
									
										
									
									
									
								
							
							
						
						
									
										47
									
								
								tccasm.c
									
										
									
									
									
								
							| 
						 | 
					@ -20,7 +20,6 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "tcc.h"
 | 
					#include "tcc.h"
 | 
				
			||||||
#ifdef CONFIG_TCC_ASM
 | 
					#ifdef CONFIG_TCC_ASM
 | 
				
			||||||
 | 
					 | 
				
			||||||
ST_FUNC int asm_get_local_label_name(TCCState *s1, unsigned int n)
 | 
					ST_FUNC int asm_get_local_label_name(TCCState *s1, unsigned int n)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    char buf[64];
 | 
					    char buf[64];
 | 
				
			||||||
| 
						 | 
					@ -483,7 +482,7 @@ static void asm_parse_directive(TCCState *s1)
 | 
				
			||||||
    case TOK_ASM_globl:
 | 
					    case TOK_ASM_globl:
 | 
				
			||||||
    case TOK_ASM_global:
 | 
					    case TOK_ASM_global:
 | 
				
			||||||
    case TOK_ASM_weak:
 | 
					    case TOK_ASM_weak:
 | 
				
			||||||
    case TOK_ASM_hidden:
 | 
						case TOK_ASM_hidden:
 | 
				
			||||||
    tok1 = tok;
 | 
					    tok1 = tok;
 | 
				
			||||||
	do { 
 | 
						do { 
 | 
				
			||||||
            Sym *sym;
 | 
					            Sym *sym;
 | 
				
			||||||
| 
						 | 
					@ -494,12 +493,12 @@ static void asm_parse_directive(TCCState *s1)
 | 
				
			||||||
                sym = label_push(&s1->asm_labels, tok, 0);
 | 
					                sym = label_push(&s1->asm_labels, tok, 0);
 | 
				
			||||||
                sym->type.t = VT_VOID;
 | 
					                sym->type.t = VT_VOID;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
	    if (tok1 != TOK_ASM_hidden)
 | 
					            if (tok1 != TOK_ASM_hidden)
 | 
				
			||||||
                sym->type.t &= ~VT_STATIC;
 | 
					                sym->type.t &= ~VT_STATIC;
 | 
				
			||||||
            if (tok1 == TOK_ASM_weak)
 | 
					            if (tok1 == TOK_ASM_weak)
 | 
				
			||||||
                sym->type.t |= VT_WEAK;
 | 
					                sym->type.t |= VT_WEAK;
 | 
				
			||||||
	    else if (tok1 == TOK_ASM_hidden)
 | 
								else if (tok1 == TOK_ASM_hidden)
 | 
				
			||||||
	        sym->type.t |= STV_HIDDEN << VT_VIS_SHIFT;
 | 
									sym->type.t |= STV_HIDDEN << VT_VIS_SHIFT;
 | 
				
			||||||
            next();
 | 
					            next();
 | 
				
			||||||
	} while (tok == ',');
 | 
						} while (tok == ',');
 | 
				
			||||||
	break;
 | 
						break;
 | 
				
			||||||
| 
						 | 
					@ -697,42 +696,15 @@ static void asm_parse_directive(TCCState *s1)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
/* assemble a file */
 | 
					/* assemble a file */
 | 
				
			||||||
static int tcc_assemble_internal(TCCState *s1, int do_preprocess)
 | 
					static int tcc_assemble_internal(TCCState *s1, int do_preprocess)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    int opcode;
 | 
					    int opcode;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if 0
 | 
					#ifdef PRINTF_ASM_CODE
 | 
				
			||||||
 | 
						ST_FUNC void printf_asm_opcode();
 | 
				
			||||||
    /* print stats about opcodes */
 | 
					    /* print stats about opcodes */
 | 
				
			||||||
    {
 | 
						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;i<pa->nb_ops;i++) {
 | 
					 | 
				
			||||||
                for(j=0;j<nb_op_vals;j++) {
 | 
					 | 
				
			||||||
                    if (pa->op_type[i] == op_vals[j])
 | 
					 | 
				
			||||||
                        goto found;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                op_vals[nb_op_vals++] = pa->op_type[i];
 | 
					 | 
				
			||||||
            found: ;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        for(i=0;i<nb_op_vals;i++) {
 | 
					 | 
				
			||||||
            int v = op_vals[i];
 | 
					 | 
				
			||||||
            if ((v & (v - 1)) != 0)
 | 
					 | 
				
			||||||
                printf("%3d: %08x\n", i, v);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        printf("size=%d nb=%d f0=%d f1=%d f2=%d f3=%d\n",
 | 
					 | 
				
			||||||
               sizeof(asm_instrs), sizeof(asm_instrs) / sizeof(ASMInstr),
 | 
					 | 
				
			||||||
               freq[0], freq[1], freq[2], freq[3]);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* XXX: undefine C labels */
 | 
					    /* XXX: undefine C labels */
 | 
				
			||||||
| 
						 | 
					@ -814,9 +786,8 @@ ST_FUNC int tcc_assemble(TCCState *s1, int do_preprocess)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* an elf symbol of type STT_FILE must be put so that STB_LOCAL
 | 
					    /* an elf symbol of type STT_FILE must be put so that STB_LOCAL
 | 
				
			||||||
       symbols can be safely used */
 | 
					       symbols can be safely used */
 | 
				
			||||||
    put_elf_sym(symtab_section, 0, 0,
 | 
					    put_elf_sym(symtab_section, 0, 0, ELFW(ST_INFO)(STB_LOCAL, STT_FILE), 0,
 | 
				
			||||||
                ELFW(ST_INFO)(STB_LOCAL, STT_FILE), 0,
 | 
							SHN_ABS, file->filename);
 | 
				
			||||||
                SHN_ABS, file->filename);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ret = tcc_assemble_internal(s1, do_preprocess);
 | 
					    ret = tcc_assemble_internal(s1, do_preprocess);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										2
									
								
								tcctok.h
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								tcctok.h
									
										
									
									
									
								
							| 
						 | 
					@ -285,5 +285,5 @@
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
 | 
					#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
 | 
				
			||||||
#include "i386-tok.h"
 | 
					#include "asmx86-tok.h"
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue