static void make_global_instance(compile_t* c, gentype_t* g) { // Not a primitive type. if(g->underlying != TK_PRIMITIVE) return; // No instance for base types. if(g->primitive != NULL) return; // Check for an existing instance. const char* inst_name = genname_instance(g->type_name); g->instance = LLVMGetNamedGlobal(c->module, inst_name); if(g->instance != NULL) return; // Create a unique global instance. LLVMValueRef args[1]; args[0] = g->desc; LLVMValueRef value = LLVMConstNamedStruct(g->structure, args, 1); g->instance = LLVMAddGlobal(c->module, g->structure, inst_name); LLVMSetInitializer(g->instance, value); LLVMSetGlobalConstant(g->instance, true); LLVMSetLinkage(g->instance, LLVMInternalLinkage); }
static void make_global_instance(compile_t* c, reach_type_t* t) { // Not a primitive type. if(t->underlying != TK_PRIMITIVE) return; // No instance for machine word types. if(t->primitive != NULL) return; // Create a unique global instance. const char* inst_name = genname_instance(t->name); LLVMValueRef args[1]; args[0] = t->desc; LLVMValueRef value = LLVMConstNamedStruct(t->structure, args, 1); t->instance = LLVMAddGlobal(c->module, t->structure, inst_name); LLVMSetInitializer(t->instance, value); LLVMSetGlobalConstant(t->instance, true); LLVMSetLinkage(t->instance, LLVMPrivateLinkage); }