| @@ -341,6 +341,29 @@ typedef struct CachedInclude { · 340 unmodified lines |
| 341 | | 341 | |
| 342 | #define CACHED_INCLUDES_HASH_SIZE 512 | 342 | #define CACHED_INCLUDES_HASH_SIZE 512 |
| 343 | | 343 | |
| | 344 | #ifdef CONFIG_TCC_ASM |
| | 345 | typedef struct ExprValue { |
| | 346 | uint32_t v; |
| | 347 | Sym *sym; |
| | 348 | } ExprValue; |
| | 349 | |
| | 350 | #define MAX_ASM_OPERANDS 30 |
| | 351 | typedef struct ASMOperand { |
| | 352 | int id; /* GCC 3 optionnal identifier (0 if number only supported */ |
| | 353 | char *constraint; |
| | 354 | char asm_str[16]; /* computed asm string for operand */ |
| | 355 | SValue *vt; /* C value of the expression */ |
| | 356 | int ref_index; /* if >= 0, gives reference to a output constraint */ |
| | 357 | int input_index; /* if >= 0, gives reference to an input constraint */ |
| | 358 | int priority; /* priority, used to assign registers */ |
| | 359 | int reg; /* if >= 0, register number used for this operand */ |
| | 360 | int is_llong; /* true if double register value */ |
| | 361 | int is_memory; /* true if memory operand */ |
| | 362 | int is_rw; /* for '+' modifier */ |
| | 363 | } ASMOperand; |
| | 364 | |
| | 365 | #endif |
| | 366 | |
| 344 | struct TCCState { | 367 | struct TCCState { |
| 345 | int output_type; | 368 | int output_type; |
| 346 | | 369 | |
| @@ -700,155 +723,24 @@ extern long double strtold (const char *__nptr, char **__endptr); · 353 unmodified lines |
| 700 | #define PATHCMP strcmp | 723 | #define PATHCMP strcmp |
| 701 | #endif | 724 | #endif |
| 702 | | 725 | |
| 703 | static char *pstrcpy(char *buf, int buf_size, const char *s); | | |
| 704 | static char *pstrcat(char *buf, int buf_size, const char *s); | | |
| 705 | static char *tcc_basename(const char *name); | | |
| 706 | static char *tcc_fileextension (const char *p); | | |
| 707 | | | |
| 708 | static void next(void); | | |
| 709 | static void next_nomacro(void); | | |
| 710 | static void next_nomacro_spc(void); | | |
| 711 | static void parse_expr_type(CType *type); | | |
| 712 | static void expr_type(CType *type); | | |
| 713 | static void unary_type(CType *type); | | |
| 714 | static void block(int *bsym, int *csym, int *case_sym, int *def_sym, | | |
| 715 | int case_reg, int is_expr); | | |
| 716 | static int expr_const(void); | | |
| 717 | static void expr_eq(void); | | |
| 718 | static void gexpr(void); | | |
| 719 | static void gen_inline_functions(void); | | |
| 720 | static void decl(int l); | | |
| 721 | static void decl_initializer(CType *type, Section *sec, unsigned long c, | | |
| 722 | int first, int size_only); | | |
| 723 | static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, | | |
| 724 | int has_init, int v, int scope); | | |
| 725 | int gv(int rc); | | |
| 726 | void gv2(int rc1, int rc2); | | |
| 727 | void move_reg(int r, int s); | | |
| 728 | void save_regs(int n); | | |
| 729 | void save_reg(int r); | | |
| 730 | void vpop(void); | | |
| 731 | void vswap(void); | | |
| 732 | void vdup(void); | | |
| 733 | int get_reg(int rc); | | |
| 734 | int get_reg_ex(int rc,int rc2); | | |
| 735 | | | |
| 736 | struct macro_level { | | |
| 737 | struct macro_level *prev; | | |
| 738 | int *p; | | |
| 739 | }; | | |
| 740 | | | |
| 741 | static void macro_subst(TokenString *tok_str, Sym **nested_list, | | |
| 742 | const int *macro_str, struct macro_level **can_read_stream); | | |
| 743 | void gen_op(int op); | | |
| 744 | void force_charshort_cast(int t); | | |
| 745 | static void gen_cast(CType *type); | | |
| 746 | void vstore(void); | | |
| 747 | static Sym *sym_find(int v); | | |
| 748 | static Sym *sym_push(int v, CType *type, int r, int c); | | |
| 749 | | | |
| 750 | /* type handling */ | | |
| 751 | static int type_size(CType *type, int *a); | | |
| 752 | static inline CType *pointed_type(CType *type); | | |
| 753 | static int pointed_size(CType *type); | | |
| 754 | static int lvalue_type(int t); | | |
| 755 | static int parse_btype(CType *type, AttributeDef *ad); | | |
| 756 | static void type_decl(CType *type, AttributeDef *ad, int *v, int td); | | |
| 757 | static int compare_types(CType *type1, CType *type2, int unqualified); | | |
| 758 | static int is_compatible_types(CType *type1, CType *type2); | | |
| 759 | static int is_compatible_parameter_types(CType *type1, CType *type2); | | |
| 760 | | | |
| 761 | int ieee_finite(double d); | | |
| 762 | void error(const char *fmt, ...); | 726 | void error(const char *fmt, ...); |
| 763 | void vpushi(int v); | 727 | void warning(const char *fmt, ...); |
| 764 | void vpushll(long long v); | 728 | void tcc_set_lib_path_w32(TCCState *s); |
| 765 | void vrott(int n); | 729 | int tcc_set_flag(TCCState *s, const char *flag_name, int value); |
| 766 | void vnrott(int n); | 730 | void tcc_print_stats(TCCState *s, int64_t total_time); |
| 767 | void lexpand_nr(void); | | |
| 768 | static void vpush_global_sym(CType *type, int v); | | |
| 769 | void vset(CType *type, int r, int v); | | |
| 770 | void type_to_str(char *buf, int buf_size, | | |
| 771 | CType *type, const char *varstr); | | |
| 772 | char *get_tok_str(int v, CValue *cv); | | |
| 773 | static Sym *get_sym_ref(CType *type, Section *sec, | | |
| 774 | unsigned long offset, unsigned long size); | | |
| 775 | static Sym *external_global_sym(int v, CType *type, int r); | | |
| 776 | | | |
| 777 | /* section generation */ | | |
| 778 | static void section_realloc(Section *sec, unsigned long new_size); | | |
| 779 | static void *section_ptr_add(Section *sec, unsigned long size); | | |
| 780 | static void put_extern_sym(Sym *sym, Section *section, | | |
| 781 | unsigned long value, unsigned long size); | | |
| 782 | static void greloc(Section *s, Sym *sym, unsigned long addr, int type); | | |
| 783 | static int put_elf_str(Section *s, const char *sym); | | |
| 784 | static int put_elf_sym(Section *s, | | |
| 785 | unsigned long value, unsigned long size, | | |
| 786 | int info, int other, int shndx, const char *name); | | |
| 787 | static int add_elf_sym(Section *s, unsigned long value, unsigned long size, | | |
| 788 | int info, int other, int sh_num, const char *name); | | |
| 789 | static void put_elf_reloc(Section *symtab, Section *s, unsigned long offset, | | |
| 790 | int type, int symbol); | | |
| 791 | static void put_stabs(const char *str, int type, int other, int desc, | | |
| 792 | unsigned long value); | | |
| 793 | static void put_stabs_r(const char *str, int type, int other, int desc, | | |
| 794 | unsigned long value, Section *sec, int sym_index); | | |
| 795 | static void put_stabn(int type, int other, int desc, int value); | | |
| 796 | static void put_stabd(int type, int other, int desc); | | |
| 797 | static int tcc_add_dll(TCCState *s, const char *filename, int flags); | | |
| 798 | | | |
| 799 | #define AFF_PRINT_ERROR 0x0001 /* print error if file not found */ | | |
| 800 | #define AFF_REFERENCED_DLL 0x0002 /* load a referenced dll from another dll */ | | |
| 801 | #define AFF_PREPROCESS 0x0004 /* preprocess file */ | | |
| 802 | static int tcc_add_file_internal(TCCState *s, const char *filename, int flags); | | |
| 803 | | | |
| 804 | /* tcccoff.c */ | | |
| 805 | int tcc_output_coff(TCCState *s1, FILE *f); | | |
| 806 | | | |
| 807 | /* tccpe.c */ | | |
| 808 | void *resolve_sym(TCCState *s1, const char *sym, int type); | | |
| 809 | int pe_load_def_file(struct TCCState *s1, int fd); | | |
| 810 | int pe_test_res_file(void *v, int size); | | |
| 811 | int pe_load_res_file(struct TCCState *s1, int fd); | | |
| 812 | void pe_add_runtime(struct TCCState *s1); | | |
| 813 | void pe_guess_outfile(char *objfilename, int output_type); | | |
| 814 | int pe_output_file(struct TCCState *s1, const char *filename); | | |
| 815 | | | |
| 816 | /* tccasm.c */ | | |
| 817 | | | |
| 818 | #ifdef CONFIG_TCC_ASM | | |
| 819 | | 731 | |
| 820 | typedef struct ExprValue { | 732 | static void tcc_free(void *ptr); |
| 821 | uint32_t v; | 733 | static void *tcc_malloc(unsigned long size); |
| 822 | Sym *sym; | 734 | static void *tcc_mallocz(unsigned long size); |
| 823 | } ExprValue; | 735 | static void *tcc_realloc(void *ptr, unsigned long size); |
| 824 | | 736 | static char *tcc_strdup(const char *str); |
| 825 | #define MAX_ASM_OPERANDS 30 | | |
| 826 | | | |
| 827 | typedef struct ASMOperand { | | |
| 828 | int id; /* GCC 3 optionnal identifier (0 if number only supported */ | | |
| 829 | char *constraint; | | |
| 830 | char asm_str[16]; /* computed asm string for operand */ | | |
| 831 | SValue *vt; /* C value of the expression */ | | |
| 832 | int ref_index; /* if >= 0, gives reference to a output constraint */ | | |
| 833 | int input_index; /* if >= 0, gives reference to an input constraint */ | | |
| 834 | int priority; /* priority, used to assign registers */ | | |
| 835 | int reg; /* if >= 0, register number used for this operand */ | | |
| 836 | int is_llong; /* true if double register value */ | | |
| 837 | int is_memory; /* true if memory operand */ | | |
| 838 | int is_rw; /* for '+' modifier */ | | |
| 839 | } ASMOperand; | | |
| 840 | | | |
| 841 | static void asm_expr(TCCState *s1, ExprValue *pe); | | |
| 842 | static int asm_int_expr(TCCState *s1); | | |
| 843 | static int find_constraint(ASMOperand *operands, int nb_operands, | | |
| 844 | const char *name, const char **pp); | | |
| 845 | | 737 | |
| 846 | static int tcc_assemble(TCCState *s1, int do_preprocess); | 738 | static char *tcc_basename(const char *name); |
| 847 | | 739 | static char *tcc_fileextension (const char *name); |
| 848 | #endif | 740 | static char *pstrcpy(char *buf, int buf_size, const char *s); |
| 849 | | 741 | static char *pstrcat(char *buf, int buf_size, const char *s); |
| 850 | static void asm_instr(void); | 742 | static void dynarray_add(void ***ptab, int *nb_ptr, void *data); |
| 851 | static void asm_global_instr(void); | 743 | static void dynarray_reset(void *pp, int *n); |
| 852 | | 744 | |
| 853 | #ifdef CONFIG_TCC_BACKTRACE | 745 | #ifdef CONFIG_TCC_BACKTRACE |
| 854 | extern int num_callers; | 746 | extern int num_callers; |
| @@ -863,3 +755,9 @@ static inline int is_float(int t) · 8 unmodified lines |
| 863 | return bt == VT_LDOUBLE || bt == VT_DOUBLE || bt == VT_FLOAT; | 755 | return bt == VT_LDOUBLE || bt == VT_DOUBLE || bt == VT_FLOAT; |
| 864 | } | 756 | } |
| 865 | | 757 | |
| | 758 | /* space exlcuding newline */ |
| | 759 | static inline int is_space(int ch) |
| | 760 | { |
| | 761 | return ch == ' ' || ch == '\t' || ch == '\v' || ch == '\f' || ch == '\r'; |
| | 762 | } |
| | 763 | |