symbol.h


    1 #ifndef XCC_SYMBOL_H
    2 #define XCC_SYMBOL_H
    3 enum NameLevel {
    4 	NL_GLOBAL,
    5 	NL_LOCAL,
    6 	NL_ARG,
    7 	NL_LABEL
    8 };
    9 
   10 enum { MAX_BLOCK_DEPTH = 128 };
   11 
   12 struct Symbol {
   13 	char *name;
   14 	struct Type *type;
   15 	struct AST *ast;
   16 	int offset;
   17 	enum NameLevel level;
   18 	struct Symbol *next;
   19 };
   20 
   21 struct String {
   22 	char *data;
   23 	char *label;
   24 	struct String *next;
   25 };
   26 
   27 struct SymbolTable {
   28 	struct Symbol *global;
   29 	struct Symbol *arg;
   30 	struct Symbol *label;
   31 	struct String *string;
   32 	int local_index;
   33 	struct Symbol *local[MAX_BLOCK_DEPTH];
   34 };
   35 
   36 struct Symbol *symbol_lookup(char *name);
   37 struct Symbol *symbol_lookup_label(char *name);
   38 struct String *string_lookup(char *data);
   39 void symbol_entry(struct AST *ast);
   40 void string_entry(char *data);
   41 void symbol_backpatch(struct AST *ast, struct Type *type);
   42 void symbol_begin_function(void);
   43 void symbol_end_function(struct AST *ast);
   44 void symbol_begin_block(void);
   45 void symbol_middle_block(void);
   46 void symbol_end_block(struct AST *ast);
   47 void symbol_entry_param(struct Type *func_type);
   48 struct Symbol *symbol_check_var_decl(struct AST *ast);
   49 void symbol_table_dump(void);
   50 extern int total_arg_size;
   51 extern struct SymbolTable symbol_table;
   52 #endif /* XCC_SYMBOL_H */