#ifndef TCC_CC_H # define TCC_CC_H #include "tcc/state.h" # include /* ------------ tccpp.c ------------ */ extern struct BufferedFile *file; extern int tok; extern CValue tokc; extern const int *macro_ptr; extern int parse_flags; extern int tok_flags; extern CString tokcstr; /* current parsed string, if any */ /* display benchmark infos */ extern int tok_ident; extern TokenSym **table_ident; extern int pp_expr; #define TOK_FLAG_BOL 0x0001 /* beginning of line before */ #define TOK_FLAG_BOF 0x0002 /* beginning of file before */ #define TOK_FLAG_ENDIF 0x0004 /* a endif was found matching starting #ifdef */ #define PARSE_FLAG_PREPROCESS 0x0001 /* activate preprocessing */ #define PARSE_FLAG_TOK_NUM 0x0002 /* return numbers instead of TOK_PPNUM */ #define PARSE_FLAG_LINEFEED 0x0004 /* line feed is returned as a token. line feed is also returned at eof */ #define PARSE_FLAG_ASM_FILE 0x0008 /* we processing an asm file: '#' can be used for line comment, etc. */ #define PARSE_FLAG_SPACES 0x0010 /* next() returns space tokens (for -E) */ #define PARSE_FLAG_ACCEPT_STRAYS 0x0020 /* next() returns '\\' token */ #define PARSE_FLAG_TOK_STR 0x0040 /* return parsed strings instead of TOK_PPSTR */ /* isidnum_table flags: */ #define IS_SPC 1 #define IS_ID 2 #define IS_NUM 4 enum line_macro_output_format { LINE_MACRO_OUTPUT_FORMAT_GCC, LINE_MACRO_OUTPUT_FORMAT_NONE, LINE_MACRO_OUTPUT_FORMAT_STD, LINE_MACRO_OUTPUT_FORMAT_P10 = 11 }; TokenSym *tok_alloc(const char *str, int len); int tok_alloc_const(const char *str); const char *get_tok_str(int v, CValue *cv); void begin_macro(TokenString *str, int alloc); void end_macro(void); int set_idnum(int c, int val); void tok_str_new(TokenString *s); TokenString *tok_str_alloc(void); void tok_str_free(TokenString *s); void tok_str_free_str(int *str); void tok_str_add(TokenString *s, int t); void tok_str_add_tok(TokenString *s); void define_push(int v, int macro_type, int *str, Sym *first_arg); void define_undef(Sym *s); Sym *define_find(int v); void free_defines(Sym *b); void parse_define(void); void skip_to_eol(int warn); void preprocess(int is_bof); void next(void); void unget_tok(int last_tok); void preprocess_start(TCCState *s1, int filetype); void preprocess_end(TCCState *s1); void tccpp_new(TCCState *s); void tccpp_delete(TCCState *s); void tccpp_putfile(const char *filename); int tcc_preprocess(TCCState *s1); void skip(int c); __attribute__((noreturn)) void expect(const char *msg); void pp_error(CString *cs); /* space excluding newline */ static inline int is_space(int ch) { return ch == ' ' || ch == '\t' || ch == '\v' || ch == '\f' || ch == '\r'; } static inline int isid(int c) { return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_'; } static inline int isnum(int c) { return c >= '0' && c <= '9'; } static inline int isoct(int c) { return c >= '0' && c <= '7'; } /* ------------ tccgen.c ------------ */ #define SYM_POOL_NB (8192 / sizeof(Sym)) extern Sym *global_stack; extern Sym *local_stack; extern Sym *local_label_stack; extern Sym *global_label_stack; extern Sym *define_stack; extern CType int_type, func_old_type, char_pointer_type; extern SValue *vtop; extern int rsym, anon_sym, ind, loc; extern char debug_modes; extern int nocode_wanted; /* true if no code generation wanted for an expression */ extern int global_expr; /* true if compound literals must be allocated globally (used during initializers parsing */ extern CType func_vt; /* current function return type (used by return instruction) */ extern int func_var; /* true if current function is variadic */ extern int func_vc; extern int func_ind; extern const char *funcname; void tccgen_init(TCCState *s1); int tccgen_compile(TCCState *s1); void tccgen_finish(TCCState *s1); void check_vstack(void); int is_float(int t); int ieee_finite(double d); int exact_log2p1(int i); void test_lvalue(void); COFFSym *coffsym(Sym *); void update_storage(Sym *sym); void put_extern_sym2(Sym *sym, int sh_num, addr_t value, unsigned long size, int can_add_underscore); void put_extern_sym(Sym *sym, TCCSection *section, addr_t value, unsigned long size); void greloc(TCCSection *s, Sym *sym, unsigned long offset, int type); void greloca(TCCSection *s, Sym *sym, unsigned long offset, int type, addr_t addend); void sym_free(Sym *sym); Sym *sym_push(int v, CType *type, int r, int c); void sym_pop(Sym **ptop, Sym *b, int keep); Sym *sym_push2(Sym **ps, int v, int t, int c); Sym *sym_find2(Sym *s, int v); Sym *sym_find(int v); Sym *label_find(int v); Sym *label_push(Sym **ptop, int v, int flags); void label_pop(Sym **ptop, Sym *slast, int keep); Sym *struct_find(int v); Sym *global_identifier_push(int v, int t, int c); Sym *external_global_sym(int v, CType *type); Sym *external_helper_sym(int v); void vpush_helper_func(int v); void vset(CType *type, int r, int v); void vset_VT_CMP(int op); void vpushi(int v); void vpushv(SValue *v); void vpushsym(CType *type, Sym *sym); void vswap(void); void vrott(int n); void vrotb(int n); void vrev(int n); void vpop(void); void lexpand(void); void save_reg(int r); void save_reg_upstack(int r, int n); int get_reg(int rc); void save_regs(int n); void gaddrof(void); int gv(int rc); void gv2(int rc1, int rc2); void gen_op(int op); int type_size(CType *type, int *a); void mk_pointer(CType *type); void vstore(void); void inc(int post, int c); CString* parse_mult_str(const char *msg); CString* parse_asm_str(void); void indir(void); void unary(void); void gexpr(void); int expr_const(void); /* ------------ xxx-link.c ------------ */ #if !defined ELF_OBJ_ONLY #define NEED_RELOC_TYPE #endif /*void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val); */ /* ------------ xxx-gen.c ------------ */ extern const char * const target_machine_defs; extern const int reg_classes[NB_REGS]; void gsym_addr(int t, int a); void gsym(int t); void load(int r, SValue *sv); void store(int r, SValue *v); int gfunc_sret(CType *vt, int variadic, CType *ret, int *align, int *regsize); void gfunc_call(int nb_args); void gfunc_prolog(Sym *func_sym); void gfunc_epilog(void); void gen_fill_nops(int); int gjmp(int t); void gjmp_addr(int a); int gjmp_cond(int op, int t); int gjmp_append(int n, int t); void gen_opi(int op); void gen_opf(int op); void gen_cvt_ftoi(int t); void gen_cvt_itof(void); void gen_cvt_ftof(void); void ggoto(void); void o(unsigned int c); void gen_vla_sp_save(int addr); void gen_vla_sp_restore(int addr); void gen_vla_alloc(CType *type, int align); static inline uint16_t read16le(unsigned char *p) { return p[0] | (uint16_t)p[1] << 8; } static inline void write16le(unsigned char *p, uint16_t x) { p[0] = x & 255; p[1] = x >> 8 & 255; } static inline uint32_t read32le(unsigned char *p) { return read16le(p) | (uint32_t)read16le(p + 2) << 16; } static inline void write32le(unsigned char *p, uint32_t x) { write16le(p, x); write16le(p + 2, x >> 16); } static inline void add32le(unsigned char *p, int32_t x) { write32le(p, read32le(p) + x); } static inline uint64_t read64le(unsigned char *p) { return read32le(p) | (uint64_t)read32le(p + 4) << 32; } static inline void write64le(unsigned char *p, uint64_t x) { write32le(p, x); write32le(p + 4, x >> 32); } static inline void add64le(unsigned char *p, int64_t x) { write64le(p, read64le(p) + x); } /* ------------ i386-gen.c ------------ */ void g(int c); void gen_le16(int c); void gen_le32(int c); void gen_addr32(int r, Sym *sym, int c); void gen_addrpc32(int r, Sym *sym, int c); void gen_cvt_csti(int t); /* ------------ tccasm.c ------------ */ void asm_instr(TCCState *s1); void asm_global_instr(TCCState *s1); int tcc_assemble(TCCState *s1, int do_preprocess); int find_constraint(ASMOperand *operands, int nb_operands, const char *name, const char **pp); Sym* get_asm_sym(TCCState *s1, int name, Sym *csym); void asm_expr(TCCState *s1, ExprValue *pe); int asm_int_expr(TCCState *s1); /* ------------ i386-asm.c ------------ */ void gen_expr32(ExprValue *pe); void asm_opcode(TCCState *s1, int opcode); int asm_parse_regvar(int t); void asm_compute_constraints(ASMOperand *operands, int nb_operands, int nb_outputs, const uint8_t *clobber_regs, int *pout_reg); void subst_asm_operand(CString *add_str, SValue *sv, int modifier); void asm_gen_code(ASMOperand *operands, int nb_operands, int nb_outputs, int is_output, uint8_t *clobber_regs, int out_reg); void asm_clobber(uint8_t *clobber_regs, const char *str); /** XXX: fixme */ /* Symbol visibility specification encoded in the st_other field. */ #define STV_DEFAULT 0 /* Default symbol visibility rules */ #define STV_INTERNAL 1 /* Processor specific hidden class */ #define STV_HIDDEN 2 /* Sym unavailable in other modules */ #define STV_PROTECTED 3 /* Not preemptible, not exported */ #endif /* !TCC_CC_H */