Skip to content

Instantly share code, notes, and snippets.

@jeremytregunna
Created July 30, 2011 05:41
Show Gist options
  • Select an option

  • Save jeremytregunna/1115240 to your computer and use it in GitHub Desktop.

Select an option

Save jeremytregunna/1115240 to your computer and use it in GitHub Desktop.
LLVMTypeRef obj_llvm_type(void)
{
LLVMTypeRef slotsType = LLVMPointerType(sarray_llvm_type(), 0);
LLVMTypeRef pType = LLVMPointerType(LLVMVoidType(), 0);
LLVMTypeRef cenvType = LLVMPointerType(cenv_llvm_type(), 0);
LLVMTypeRef elementTypes[] = { slotsType, pTy, cenvType };
LLVMTypeRef structType = LLVMStructType(elementTypes, sizeof(elementTypes), 0);
return structType;
}
obj_t* obj_add_func(obj_t* self, const char* name, LLVMTypeRef* params, unsigned param_count, LLVMTypeRef ret_type)
{
LLVMValueRef func = LLVMAddFunction(self->env->module, name, LLVMFunctionType(ret_type, params, param_count, 0));
LLVMSetFunctionCallConv(func, LLVMCCallConv);
uint32_t sel = 0; // TODO: Get a hash of the name and the param types
obj_install_slot(self, sel, func);
return func;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment