fixed: function call

This commit is contained in:
Sven Vogel 2024-06-09 22:00:28 +02:00
parent d4ce3387b9
commit d537dc94ae
2 changed files with 6 additions and 5 deletions

View File

@ -114,6 +114,8 @@ BackendError impl_func_decl(LLVMBackendCompileUnit* unit,
*llvm_fun = LLVMAddFunction(unit->module, name, llvm_fun_type); *llvm_fun = LLVMAddFunction(unit->module, name, llvm_fun_type);
g_hash_table_insert(scope->functions, name, llvm_fun_type);
g_array_free(llvm_params, FALSE); g_array_free(llvm_params, FALSE);
return err; return err;
@ -136,9 +138,6 @@ BackendError impl_func_def(LLVMBackendCompileUnit* unit,
func_scope->global_scope = global_scope; func_scope->global_scope = global_scope;
func_scope->params = g_hash_table_new(g_str_hash, g_str_equal); func_scope->params = g_hash_table_new(g_str_hash, g_str_equal);
// store function type in global scope
g_hash_table_insert(global_scope->functions, (gpointer)name, llvm_func);
// create function body builder // create function body builder
LLVMBasicBlockRef entry = LLVMBasicBlockRef entry =
LLVMAppendBasicBlockInContext(unit->context, llvm_func, "func.entry"); LLVMAppendBasicBlockInContext(unit->context, llvm_func, "func.entry");

View File

@ -180,9 +180,11 @@ BackendError impl_func_call(LLVMBackendCompileUnit *unit,
if (err.kind == Success) { if (err.kind == Success) {
LLVMValueRef llvm_func = LLVMGetNamedFunction(unit->module, call->function->name); LLVMValueRef llvm_func = LLVMGetNamedFunction(unit->module, call->function->name);
LLVMTypeRef llvm_func_type = LLVMTypeOf(llvm_func);
LLVMTypeRef llvm_func_type = g_hash_table_lookup(scope->func_scope->global_scope->functions, call->function->name);
LLVMBuildCall2(builder, llvm_func_type, llvm_func, arguments, call->expressions->len, LLVMBuildCall2(builder, llvm_func_type, llvm_func, arguments, call->expressions->len,
"stmt.call"); "");
} }
return err; return err;