void ty_add_struct_def(char *name, Arraylist *names, Arraylist *types) { Arraylist *copy = malloc(sizeof(Arraylist)); memcpy(copy, names, sizeof(Arraylist)); hst_put(&struct_table, name, copy, NULL, NULL); copy = malloc(sizeof(Arraylist)); memcpy(copy, types, sizeof(Arraylist)); hst_put(&types_table, name, copy, NULL, NULL); }
void ty_add_method(char *name, char *method, EagleComplexType *ty) { Hashtable *lst = hst_get(&method_table, name, NULL, NULL); if(!lst) { lst = malloc(sizeof(Hashtable)); *lst = hst_create(); lst->duplicate_keys = 1; hst_put(&method_table, name, lst, NULL, NULL); } hst_put(lst, method, ty, NULL, NULL); }
void ty_add_enum_item(char *name, char *item, long val) { Hashtable *en = hst_get(&enum_table, name, NULL, NULL); if(!en) die(__LINE__, "Internal compiler error declaring enum item %s.%s", name, item); hst_put(en, item, PTR(val), NULL, NULL); }
VarBundle *vs_put_in_module(VarScopeStack *vs, char *ident, char *module, LLVMValueRef val, EagleComplexType *type) { VarBundle *vb = vs_create(ident, module, type, val, -1); Hashtable *mod = hst_get(&vs->modules, module, NULL, NULL); if(!mod) { mod = malloc(sizeof(Hashtable)); *mod = hst_create(); mod->duplicate_keys = 1; hst_put(&vs->modules, module, mod, NULL, NULL); } hst_put(mod, ident, vb, NULL, NULL); pool_add(&vs->pool, vb); return vb; }
VarBundle *vs_put(VarScopeStack *vs, char *ident, LLVMValueRef val, EagleComplexType *type, int lineno) { VarBundle *vb = vs_create(ident, NULL, type, val, lineno); VarScope *s = vs->scope; hst_put(&s->table, ident, vb, NULL, NULL); pool_add(&vs->pool, vb); return vb; }
void ty_register_class(char *name) { Hashtable *lst = hst_get(&method_table, name, NULL, NULL); if(lst) die(-1, "Redeclaring class with name: %s", name); lst = malloc(sizeof(Hashtable)); *lst = hst_create(); lst->duplicate_keys = 1; hst_put(&method_table, name, lst, NULL, NULL); }
void ty_register_enum(char *name) { Hashtable *en = hst_get(&enum_table, name, NULL, NULL); if(en) die(-1, "Redeclaring enum with name: %s", name); en = malloc(sizeof(*en)); *en = hst_create(); en->duplicate_keys = 1; hst_put(&enum_table, name, en, NULL, NULL); }
void ty_register_interface(char *name) { if(hst_get(&interface_table, name, NULL, NULL)) die(-1, "Redeclaring interface with name: %s", name); if(hst_get(&method_table, name, NULL, NULL)) die(-1, "Interface declaration %s clashes with previously named class.", name); Arraylist *list = malloc(sizeof(Arraylist)); *list = arr_create(10); hst_put(&interface_table, name, list, NULL, NULL); }
EagleComplexType *ett_generic_type(char *ident) { EagleComplexType *ty = hst_get(&generic_ident_table, ident, NULL, NULL); if(ty) return ty; ty = calloc(ty_type_max_size(), 1); ty->type = ETGeneric; ((EagleGenericType *)ty)->ident = ident; hst_put(&generic_ident_table, ident, ty, NULL, NULL); pool_add(&type_mempool, ty); return ty; }
EagleComplexType *ett_class_type(char *name) { EagleComplexType *et = hst_get(&type_named_table, name, NULL, NULL); if(et) return et; EagleStructType *ett = malloc(sizeof(EagleStructType)); ett->type = ETClass; ett->types = arr_create(10); ett->names = arr_create(10); ett->name = name; hst_put(&type_named_table, name, ett, NULL, NULL); pool_add(&type_mempool, ett); pool_add(&list_mempool, &ett->types); pool_add(&list_mempool, &ett->names); return (EagleComplexType *)ett; }
LLVMTypeRef ty_get_counted(LLVMTypeRef in) { char *translated = LLVMPrintTypeToString(in); LLVMTypeRef ref = hst_get(&counted_table, translated, NULL, NULL); if(!ref) { ref = LLVMStructCreateNamed(utl_get_current_context(), ""); LLVMTypeRef tys[6]; LLVMGetStructElementTypes(in, tys); LLVMStructSetBody(ref, tys, 6, 0); hst_put(&counted_table, translated, ref, NULL, NULL); } LLVMDisposeMessage(translated); return ref; }
EagleComplexType *ett_enum_type(char *name) { EagleComplexType *et = hst_get(&enum_named_table, name, NULL, NULL); if(et) return et; char *anam = hst_retrieve_duped_key(&enum_table, name); if(!anam) die(__LINE__, "Internal compiler error: no such enum %s", name); EagleEnumType *en = malloc(sizeof(*en)); en->type = ETEnum; en->name = anam; pool_add(&type_mempool, en); hst_put(&enum_named_table, name, en, NULL, NULL); return (EagleComplexType *)en; }
void ty_add_name(char *name) { hst_put(&name_table, name, PLACEHOLDER, NULL, NULL); }
void ty_add_init(char *name, EagleComplexType *ty) { hst_put(&init_table, name, ty, NULL, NULL); }
void ty_register_typedef(char *name) { void *tag = malloc(ty_type_max_size()); hst_put(&typedef_table, name, tag, NULL, NULL); }