added: more semantic errors checks
This commit is contained in:
parent
f243bb6bfe
commit
d4ce3387b9
|
@ -181,9 +181,11 @@ static void build_target(ModuleFileStack *unit, const TargetConfig *target) {
|
||||||
print_ast_to_file(ast, target);
|
print_ast_to_file(ast, target);
|
||||||
Module* module = create_set(ast);
|
Module* module = create_set(ast);
|
||||||
|
|
||||||
|
if (module != NULL) {
|
||||||
run_backend_codegen(module, target);
|
run_backend_codegen(module, target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
AST_delete_node(ast);
|
AST_delete_node(ast);
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include <llvm/llvm-ir/func.h>
|
#include <llvm/llvm-ir/func.h>
|
||||||
#include <llvm/llvm-ir/types.h>
|
#include <llvm/llvm-ir/types.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <mem/cache.h>
|
||||||
|
|
||||||
BackendError impl_assign_stmt(
|
BackendError impl_assign_stmt(
|
||||||
LLVMBackendCompileUnit *unit,
|
LLVMBackendCompileUnit *unit,
|
||||||
|
@ -146,12 +147,13 @@ gboolean is_parameter_out(Parameter *param) {
|
||||||
BackendError impl_func_call(LLVMBackendCompileUnit *unit,
|
BackendError impl_func_call(LLVMBackendCompileUnit *unit,
|
||||||
LLVMBuilderRef builder, LLVMLocalScope *scope,
|
LLVMBuilderRef builder, LLVMLocalScope *scope,
|
||||||
const FunctionCall *call) {
|
const FunctionCall *call) {
|
||||||
|
DEBUG("implementing function call...");
|
||||||
BackendError err = SUCCESS;
|
BackendError err = SUCCESS;
|
||||||
|
|
||||||
GArray *arguments = g_array_new(FALSE, FALSE, sizeof(LLVMValueRef));
|
LLVMValueRef* arguments = mem_alloc(MemoryNamespaceLlvm, sizeof(LLVMValueRef) * call->expressions->len);
|
||||||
|
|
||||||
for (size_t i = 0; i < call->expressions->len; i++) {
|
for (size_t i = 0; i < call->expressions->len; i++) {
|
||||||
Expression *arg = ((Expression *) call->expressions->data) + i;
|
Expression *arg = g_array_index(call->expressions, Expression*, i);
|
||||||
|
|
||||||
LLVMValueRef llvm_arg = NULL;
|
LLVMValueRef llvm_arg = NULL;
|
||||||
err = impl_expr(unit, scope, builder, arg, &llvm_arg);
|
err = impl_expr(unit, scope, builder, arg, &llvm_arg);
|
||||||
|
@ -159,25 +161,30 @@ BackendError impl_func_call(LLVMBackendCompileUnit *unit,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Parameter *parameter = g_array_index(call->function->impl.declaration.parameter, Parameter*, i);
|
GArray* param_list;
|
||||||
|
if (call->function->kind == FunctionDeclarationKind) {
|
||||||
|
param_list = call->function->impl.definition.parameter;
|
||||||
|
} else {
|
||||||
|
param_list = call->function->impl.declaration.parameter;
|
||||||
|
}
|
||||||
|
|
||||||
if (is_parameter_out(parameter)) {
|
Parameter parameter = g_array_index(param_list, Parameter, i);
|
||||||
|
|
||||||
|
if (is_parameter_out(¶meter)) {
|
||||||
LLVMValueRef zero = LLVMConstInt(LLVMInt32TypeInContext(unit->context), 0, 0);
|
LLVMValueRef zero = LLVMConstInt(LLVMInt32TypeInContext(unit->context), 0, 0);
|
||||||
llvm_arg = LLVMBuildGEP2(builder, LLVMTypeOf(llvm_arg), llvm_arg, &zero, 1, "");
|
llvm_arg = LLVMBuildGEP2(builder, LLVMTypeOf(llvm_arg), llvm_arg, &zero, 1, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
g_array_append_vals(arguments, &llvm_arg, 1);
|
arguments[i] = llvm_arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err.kind == Success) {
|
if (err.kind == Success) {
|
||||||
LLVMValueRef llvm_func = LLVMGetNamedFunction(unit->module, "");
|
LLVMValueRef llvm_func = LLVMGetNamedFunction(unit->module, call->function->name);
|
||||||
LLVMTypeRef llvm_func_type = LLVMTypeOf(llvm_func);
|
LLVMTypeRef llvm_func_type = LLVMTypeOf(llvm_func);
|
||||||
LLVMBuildCall2(builder, llvm_func_type, llvm_func, (LLVMValueRef *) arguments->data, arguments->len,
|
LLVMBuildCall2(builder, llvm_func_type, llvm_func, arguments, call->expressions->len,
|
||||||
"stmt.call");
|
"stmt.call");
|
||||||
}
|
}
|
||||||
|
|
||||||
g_array_free(arguments, FALSE);
|
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -200,7 +200,6 @@ BackendError get_type_impl(LLVMBackendCompileUnit* unit, LLVMGlobalScope* scope,
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
PANIC("invalid type kind: %ld", gemstone_type->kind);
|
PANIC("invalid type kind: %ld", gemstone_type->kind);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
|
|
914
src/set/set.c
914
src/set/set.c
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue