Add support for void function calls
Signed-off-by: Slendi <slendi@socopon.com>
This commit is contained in:
parent
453689642c
commit
d54f9fb2f8
@ -111,6 +111,9 @@ generate_llvm :: proc(ctx: LLVMContextRef, mod: LLVMModuleRef, builder: LLVMBuil
|
|||||||
|
|
||||||
switch type.kind {
|
switch type.kind {
|
||||||
case .Integer:
|
case .Integer:
|
||||||
|
if type.bit_size == 0 {
|
||||||
|
return LLVMVoidTypeInContext(ctx)
|
||||||
|
}
|
||||||
return LLVMIntTypeInContext(ctx, uint(type.bit_size))
|
return LLVMIntTypeInContext(ctx, uint(type.bit_size))
|
||||||
case .Float:
|
case .Float:
|
||||||
if type.bit_size == 64 {
|
if type.bit_size == 64 {
|
||||||
@ -142,6 +145,9 @@ generate_llvm :: proc(ctx: LLVMContextRef, mod: LLVMModuleRef, builder: LLVMBuil
|
|||||||
) {
|
) {
|
||||||
function_args_type := [dynamic]LLVMTypeRef{}
|
function_args_type := [dynamic]LLVMTypeRef{}
|
||||||
for arg in fn.children {
|
for arg in fn.children {
|
||||||
|
if arg == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if arg.kind != .VariableDeclaration {
|
if arg.kind != .VariableDeclaration {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -257,7 +263,12 @@ generate_llvm :: proc(ctx: LLVMContextRef, mod: LLVMModuleRef, builder: LLVMBuil
|
|||||||
append(&fn_args, value)
|
append(&fn_args, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
call := LLVMBuildCall2(
|
if node.return_type == nil || (node.return_type.kind == .Integer && node.return_type.bit_size == 0) {
|
||||||
|
fmt.printf("Void function call: %s\n", name)
|
||||||
|
return LLVMBuildCall2(builder, fn_type, fn_value, raw_data(fn_args[:]), len(fn_args), cstring(""))
|
||||||
|
}
|
||||||
|
|
||||||
|
return LLVMBuildCall2(
|
||||||
builder,
|
builder,
|
||||||
fn_type,
|
fn_type,
|
||||||
fn_value,
|
fn_value,
|
||||||
@ -265,7 +276,6 @@ generate_llvm :: proc(ctx: LLVMContextRef, mod: LLVMModuleRef, builder: LLVMBuil
|
|||||||
len(fn_args),
|
len(fn_args),
|
||||||
cstring(raw_data(name[:])),
|
cstring(raw_data(name[:])),
|
||||||
)
|
)
|
||||||
return call
|
|
||||||
}
|
}
|
||||||
|
|
||||||
generate_llvm_value :: proc(
|
generate_llvm_value :: proc(
|
||||||
@ -283,7 +293,6 @@ generate_llvm :: proc(ctx: LLVMContextRef, mod: LLVMModuleRef, builder: LLVMBuil
|
|||||||
} else if node.kind == .Identifier {
|
} else if node.kind == .Identifier {
|
||||||
def := llvm_scope_find_definition(&node.value.([dynamic]u8))
|
def := llvm_scope_find_definition(&node.value.([dynamic]u8))
|
||||||
type := llvm_scope_find_type(&node.value.([dynamic]u8))
|
type := llvm_scope_find_type(&node.value.([dynamic]u8))
|
||||||
//LLVMBuildLoad2 :: proc(Builder: LLVMBuilderRef, Ty: LLVMTypeRef, PointerVal: LLVMValueRef, Name: cstring) -> LLVMValueRef ---
|
|
||||||
def_value := LLVMBuildLoad2(builder, type, def, "loadtmp")
|
def_value := LLVMBuildLoad2(builder, type, def, "loadtmp")
|
||||||
return def_value
|
return def_value
|
||||||
}
|
}
|
||||||
|
@ -111,6 +111,7 @@ foreign llvmc {
|
|||||||
LLVMFloatTypeInContext :: proc(C: LLVMContextRef) -> LLVMTypeRef ---
|
LLVMFloatTypeInContext :: proc(C: LLVMContextRef) -> LLVMTypeRef ---
|
||||||
|
|
||||||
LLVMVoidTypeInContext :: proc(C: LLVMContextRef) -> LLVMTypeRef ---
|
LLVMVoidTypeInContext :: proc(C: LLVMContextRef) -> LLVMTypeRef ---
|
||||||
|
LLVMVoidType :: proc() -> LLVMTypeRef ---
|
||||||
|
|
||||||
LLVMGetTypeKind :: proc(Ty: LLVMTypeRef) -> LLVMTypeKind ---
|
LLVMGetTypeKind :: proc(Ty: LLVMTypeRef) -> LLVMTypeKind ---
|
||||||
|
|
||||||
@ -176,4 +177,6 @@ foreign llvmc {
|
|||||||
|
|
||||||
LLVMGetParam :: proc(Fn: LLVMValueRef, Index: uint) -> LLVMValueRef ---
|
LLVMGetParam :: proc(Fn: LLVMValueRef, Index: uint) -> LLVMValueRef ---
|
||||||
LLVMSetValueName2 :: proc(Val: LLVMValueRef, Name: cstring, Length: u64) ---
|
LLVMSetValueName2 :: proc(Val: LLVMValueRef, Name: cstring, Length: u64) ---
|
||||||
|
|
||||||
|
LLVMGetReturnType :: proc(Fn: LLVMTypeRef) -> LLVMTypeRef ---
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user