stage2: Add code generation for Load instruction in LLVM backend

The following now works:
```
export fn _start() noreturn {
    var x: bool = true;
    var y: bool = x;
    exit();
}

fn exit() noreturn {
    unreachable;
}
```
This commit is contained in:
Timon Kruiper 2020-12-29 20:18:17 +01:00
parent 19cfd310b0
commit 47a4d43e41
2 changed files with 9 additions and 0 deletions

View File

@ -312,6 +312,7 @@ pub const LLVMIRModule = struct {
.arg => try self.genArg(inst.castTag(.arg).?),
.alloc => try self.genAlloc(inst.castTag(.alloc).?),
.store => try self.genStore(inst.castTag(.store).?),
.load => try self.genLoad(inst.castTag(.load).?),
.dbg_stmt => blk: {
// TODO: implement debug info
break :blk null;
@ -396,6 +397,11 @@ pub const LLVMIRModule = struct {
return null;
}
fn genLoad(self: *LLVMIRModule, inst: *Inst.UnOp) !?*const llvm.ValueRef {
const ptr_val = try self.resolveInst(inst.operand);
return self.builder.buildLoad(ptr_val, "");
}
fn genBreakpoint(self: *LLVMIRModule, inst: *Inst.NoOp) !?*const llvm.ValueRef {
// TODO: Store this function somewhere such that we dont have to add it again
const fn_type = llvm.TypeRef.functionType(llvm.voidType(), null, 0, false);

View File

@ -125,6 +125,9 @@ pub const BuilderRef = opaque {
pub const buildStore = LLVMBuildStore;
extern fn LLVMBuildStore(*const BuilderRef, Val: *const ValueRef, Ptr: *const ValueRef) *const ValueRef;
pub const buildLoad = LLVMBuildLoad;
extern fn LLVMBuildLoad(*const BuilderRef, PointerVal: *const ValueRef, Name: [*:0]const u8) *const ValueRef;
};
pub const BasicBlockRef = opaque {