resolve llvm types for function parameters
This commit is contained in:
parent
e25621350a
commit
1ac63cdbef
2 changed files with 7 additions and 5 deletions
|
@ -1,6 +1,6 @@
|
|||
// import std;
|
||||
|
||||
fn add() i32 {
|
||||
fn add(a: i32, b: i32) i32 {
|
||||
return 69 + 69;
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue