zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 47a4d43e41b07b939b840fbf8230b89e27694093 (tree)
parent 19cfd310b0d5ba7d9542d50db281035b15daad35
Author: Timon Kruiper <timonkruiper@gmail.com>
Date:   Tue, 29 Dec 2020 20:18:17 +0100

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;
}
```

Diffstat:
Msrc/llvm_backend.zig | 6++++++
Msrc/llvm_bindings.zig | 3+++
2 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/src/llvm_backend.zig b/src/llvm_backend.zig @@ -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); diff --git a/src/llvm_bindings.zig b/src/llvm_bindings.zig @@ -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 {