From 9eddfd75bc7440133c7d0a487be672aa432c5b3c Mon Sep 17 00:00:00 2001 From: servostar Date: Tue, 28 May 2024 13:32:56 +0200 Subject: [PATCH] added assign implementation --- src/llvm/func.c | 20 ++++++++++++++++++++ src/llvm/stmt.c | 28 ++++++++++++++++++++++++++++ src/llvm/stmt.h | 9 +++++++++ 3 files changed, 57 insertions(+) create mode 100644 src/llvm/stmt.c create mode 100644 src/llvm/stmt.h diff --git a/src/llvm/func.c b/src/llvm/func.c index c9a4e65..5c6024d 100644 --- a/src/llvm/func.c +++ b/src/llvm/func.c @@ -9,6 +9,26 @@ #include #include +static LLVMValueRef get_parameter(const LLVMFuncScope* scope, const char* name) { + if (g_hash_table_contains(scope->params, name)) { + return g_hash_table_lookup(scope->params, name); + } + + return NULL; +} + +LLVMValueRef get_variable(const LLVMLocalScope* scope, const char* name) { + if (g_hash_table_contains(scope->vars, name)) { + return g_hash_table_lookup(scope->vars, name); + } + + if (scope->parent_scope != NULL) { + return get_variable(scope->parent_scope, name); + } + + return get_parameter(scope->func_scope, name); +} + BackendError impl_param_type(LLVMBackendCompileUnit* unit, LLVMGlobalScope* scope, Paramer* param, LLVMTypeRef* llvm_type) { diff --git a/src/llvm/stmt.c b/src/llvm/stmt.c new file mode 100644 index 0000000..98fec0f --- /dev/null +++ b/src/llvm/stmt.c @@ -0,0 +1,28 @@ +// +// Created by servostar on 5/28/24. +// + +#include +#include +#include +#include + +BackendError impl_assign_stmt(LLVMBackendCompileUnit* unit, + LLVMBuilderRef builder, LLVMLocalScope* scope, + Assignment* assignment) { + // TODO: resolve expression to LLVMValueRef + const LLVMValueRef llvm_value = NULL; + + switch (assignment->variable->kind) { + case VariableKindDeclaration: + case VariableKindDefinition: + const LLVMValueRef llvm_ptr = + get_variable(scope, assignment->variable->name); + LLVMBuildStore(builder, llvm_value, llvm_ptr); + break; + case VariableKindBoxMember: + break; + } +} + +BackendError impl_stmt(LLVMBackendCompileUnit* unit, Statement* stmt) {} diff --git a/src/llvm/stmt.h b/src/llvm/stmt.h new file mode 100644 index 0000000..bde984d --- /dev/null +++ b/src/llvm/stmt.h @@ -0,0 +1,9 @@ +// +// Created by servostar on 5/28/24. +// + +#ifndef LLVM_BACKEND_STMT_H +#define LLVM_BACKEND_STMT_H + + +#endif // LLVM_BACKEND_STMT_H