aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimon Kruiper <timonkruiper@gmail.com>2020-12-29 20:18:17 +0100
committerTimon Kruiper <timonkruiper@gmail.com>2021-01-03 17:23:30 +0100
commit47a4d43e41b07b939b840fbf8230b89e27694093 (patch)
tree2699734285adc39084e664da773e997e672e422d
parent19cfd310b0d5ba7d9542d50db281035b15daad35 (diff)
downloadzig-47a4d43e41b07b939b840fbf8230b89e27694093.tar.gz
zig-47a4d43e41b07b939b840fbf8230b89e27694093.zip
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; } ```
-rw-r--r--src/llvm_backend.zig6
-rw-r--r--src/llvm_bindings.zig3
2 files changed, 9 insertions, 0 deletions
diff --git a/src/llvm_backend.zig b/src/llvm_backend.zig
index 0a203777fc..d56233a503 100644
--- 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
index f7da7c34ad..133415d634 100644
--- 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 {