resolve llvm types for function parameters
This commit is contained in:
parent
e25621350a
commit
1ac63cdbef
|
@ -1,6 +1,6 @@
|
||||||
// import std;
|
// import std;
|
||||||
|
|
||||||
fn add() i32 {
|
fn add(a: i32, b: i32) i32 {
|
||||||
return 69 + 69;
|
return 69 + 69;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,9 @@ pub const CompileError = error{
|
||||||
TypeError,
|
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")) {
|
if (std.mem.eql(u8, ret_type, "i32")) {
|
||||||
return llvm.LLVMInt32Type();
|
return llvm.LLVMInt32Type();
|
||||||
} else if (std.mem.eql(u8, ret_type, "bool")) {
|
} else if (std.mem.eql(u8, ret_type, "bool")) {
|
||||||
|
@ -124,12 +126,12 @@ pub const Codegen = struct {
|
||||||
errdefer param_types.deinit();
|
errdefer param_types.deinit();
|
||||||
|
|
||||||
for (decl.params.toSlice()) |param| {
|
for (decl.params.toSlice()) |param| {
|
||||||
// TODO solve type with cute enums etc
|
// TODO better type resolution
|
||||||
try param_types.append(llvm.LLVMInt32Type());
|
try param_types.append(try basicTypeToLLVM(param.typ.lexeme));
|
||||||
}
|
}
|
||||||
|
|
||||||
var llvm_ret_type = llvm.LLVMFunctionType(
|
var llvm_ret_type = llvm.LLVMFunctionType(
|
||||||
try retTypeToLLVM(fn_ret_type),
|
try basicTypeToLLVM(fn_ret_type),
|
||||||
param_types.toSlice().ptr,
|
param_types.toSlice().ptr,
|
||||||
@intCast(c_uint, param_types.len),
|
@intCast(c_uint, param_types.len),
|
||||||
0,
|
0,
|
||||||
|
|
Loading…
Reference in New Issue