diff options
Diffstat (limited to 'semantics.h')
-rw-r--r-- | semantics.h | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/semantics.h b/semantics.h index b3d2942..1ec4c21 100644 --- a/semantics.h +++ b/semantics.h @@ -1,28 +1,33 @@ #ifndef SEMANTICS_H #define SEMANTICS_H - +#include "ast.h" #define MAX_TABLE_SIZE 1021 +#define CIBIC_DEBUG struct CTable; +struct CType; typedef struct CVar{ - char *name; + const char *name; struct CVar *next; /* next in the linked list */ struct CType *type; int offset; } CVar; +typedef CVar *CVar_t; +CVar_t cvar_create(const char *name, struct CType *type); + typedef struct CType { enum { - INT, - CHAR, - VOID, - STRUCT, - UNION, - ARR, - PTR + CINT, + CCHAR, + CVOID, + CSTRUCT, + CUNION, + CARR, + CPTR } type; - char *name; + const char *name; struct CType *next; union { struct CType *fields; /* for a struct or union */ @@ -35,7 +40,13 @@ typedef struct CType { int size; /* memory footprint */ } CType; +typedef CType *CType_t; +CType_t ctype_create(const char *name, int type); + typedef unsigned int (*Hashfunc_t) (const char *); +#ifdef CIBIC_DEBUG +typedef const char *(*Printfunc_t) (void *); +#endif typedef struct CTable *CTable_t; typedef struct CTNode { @@ -48,13 +59,21 @@ typedef struct CTNode { typedef struct CTable { struct CTNode *head[MAX_TABLE_SIZE]; Hashfunc_t hfunc; +#ifdef CIBIC_DEBUG + Printfunc_t pfunc; +#endif } CTable; +#ifdef CIBIC_DEBUG +CTable_t ctable_create(Hashfunc_t hfunc, Printfunc_t pfunc); +#else CTable_t ctable_create(Hashfunc_t hfunc); +#endif void *ctable_lookup(CTable_t ct, const char *key); void ctable_insert(CTable_t ct, const char *key, void *val, int lvl); void ctable_clip(CTable_t ct, unsigned int hv, int max_lvl); +void ctable_debug_print(CTable_t ct); typedef struct CSNode { struct CVar *vhead; @@ -77,6 +96,9 @@ void cscope_push_var(CScope_t cs, CVar *var); void cscope_push_type(CScope_t cs, CType *type); void cscope_enter(CScope_t cs); void cscope_exit(CScope_t cs); +void cscope_debug_print(CScope_t cs); unsigned int bkdr_hash(const char *str); +const char *cvar_print(void *var); +const char *ctype_print(void *type); #endif |