mirror of
https://github.com/ziglang/zig.git
synced 2026-01-05 13:03:25 +00:00
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:
parent
19cfd310b0
commit
47a4d43e41
@ -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);
|
||||
|
||||
@ -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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user