From d537dc94aecf4b0504e217a7a6aaf0c17dfbb424 Mon Sep 17 00:00:00 2001 From: servostar Date: Sun, 9 Jun 2024 22:00:28 +0200 Subject: [PATCH] fixed: function call --- src/llvm/llvm-ir/func.c | 5 ++--- src/llvm/llvm-ir/stmt.c | 6 ++++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/llvm/llvm-ir/func.c b/src/llvm/llvm-ir/func.c index 246fbf7..d8b3894 100644 --- a/src/llvm/llvm-ir/func.c +++ b/src/llvm/llvm-ir/func.c @@ -114,6 +114,8 @@ BackendError impl_func_decl(LLVMBackendCompileUnit* unit, *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); return err; @@ -136,9 +138,6 @@ BackendError impl_func_def(LLVMBackendCompileUnit* unit, func_scope->global_scope = global_scope; 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 LLVMBasicBlockRef entry = LLVMAppendBasicBlockInContext(unit->context, llvm_func, "func.entry"); diff --git a/src/llvm/llvm-ir/stmt.c b/src/llvm/llvm-ir/stmt.c index d25d0ae..6c09651 100644 --- a/src/llvm/llvm-ir/stmt.c +++ b/src/llvm/llvm-ir/stmt.c @@ -180,9 +180,11 @@ BackendError impl_func_call(LLVMBackendCompileUnit *unit, if (err.kind == Success) { 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, - "stmt.call"); + ""); } return err;