resolve llvm types for function parameters

This commit is contained in:
Luna 2019-09-24 13:32:00 -03:00
parent e25621350a
commit 1ac63cdbef
2 changed files with 7 additions and 5 deletions

View File

@ -1,6 +1,6 @@
// import std;
fn add() i32 {
fn add(a: i32, b: i32) i32 {
return 69 + 69;
}

View File

@ -13,7 +13,9 @@ pub const CompileError = error{
TypeError,
};
fn retTypeToLLVM(ret_type: []const u8) !llvm.LLVMTypeRef {
/// Does not account for custom types e.g structs, better type resolution
/// should be found
fn basicTypeToLLVM(ret_type: []const u8) !llvm.LLVMTypeRef {
if (std.mem.eql(u8, ret_type, "i32")) {
return llvm.LLVMInt32Type();
} else if (std.mem.eql(u8, ret_type, "bool")) {
@ -124,12 +126,12 @@ pub const Codegen = struct {
errdefer param_types.deinit();
for (decl.params.toSlice()) |param| {
// TODO solve type with cute enums etc
try param_types.append(llvm.LLVMInt32Type());
// TODO better type resolution
try param_types.append(try basicTypeToLLVM(param.typ.lexeme));
}
var llvm_ret_type = llvm.LLVMFunctionType(
try retTypeToLLVM(fn_ret_type),
try basicTypeToLLVM(fn_ret_type),
param_types.toSlice().ptr,
@intCast(c_uint, param_types.len),
0,