added assign implementation

This commit is contained in:
Sven Vogel 2024-05-28 13:32:56 +02:00
parent 48110c85f2
commit 9eddfd75bc
3 changed files with 57 additions and 0 deletions

View File

@ -9,6 +9,26 @@
#include <sys/log.h>
#include <llvm/func.h>
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) {

28
src/llvm/stmt.c Normal file
View File

@ -0,0 +1,28 @@
//
// Created by servostar on 5/28/24.
//
#include <codegen/backend.h>
#include <llvm/func.h>
#include <llvm/parser.h>
#include <llvm/stmt.h>
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) {}

9
src/llvm/stmt.h Normal file
View File

@ -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