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