authorgravatar for timonkruiper@gmail.comTimon Kruiper <timonkruiper@gmail.com> 2020-12-29 20:18:17+01:00
committergravatar for timonkruiper@gmail.comTimon Kruiper <timonkruiper@gmail.com> 2021-01-03 17:23:30+01:00
log47a4d43e41b07b939b840fbf8230b89e27694093
tree2699734285adc39084e664da773e997e672e422d
parent19cfd310b0d5ba7d9542d50db281035b15daad35

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

2 files changed, 9 insertions(+), 0 deletions(-)

src/llvm_backend.zig+6
...@@ -312,6 +312,7 @@ pub const LLVMIRModule = struct {...@@ -312,6 +312,7 @@ pub const LLVMIRModule = struct {
312 .arg => try self.genArg(inst.castTag(.arg).?),312 .arg => try self.genArg(inst.castTag(.arg).?),
313 .alloc => try self.genAlloc(inst.castTag(.alloc).?),313 .alloc => try self.genAlloc(inst.castTag(.alloc).?),
314 .store => try self.genStore(inst.castTag(.store).?),314 .store => try self.genStore(inst.castTag(.store).?),
315 .load => try self.genLoad(inst.castTag(.load).?),
315 .dbg_stmt => blk: {316 .dbg_stmt => blk: {
316 // TODO: implement debug info317 // TODO: implement debug info
317 break :blk null;318 break :blk null;
...@@ -396,6 +397,11 @@ pub const LLVMIRModule = struct {...@@ -396,6 +397,11 @@ pub const LLVMIRModule = struct {
396 return null;397 return null;
397 }398 }
398399
400 fn genLoad(self: *LLVMIRModule, inst: *Inst.UnOp) !?*const llvm.ValueRef {
401 const ptr_val = try self.resolveInst(inst.operand);
402 return self.builder.buildLoad(ptr_val, "");
403 }
404
399 fn genBreakpoint(self: *LLVMIRModule, inst: *Inst.NoOp) !?*const llvm.ValueRef {405 fn genBreakpoint(self: *LLVMIRModule, inst: *Inst.NoOp) !?*const llvm.ValueRef {
400 // TODO: Store this function somewhere such that we dont have to add it again406 // TODO: Store this function somewhere such that we dont have to add it again
401 const fn_type = llvm.TypeRef.functionType(llvm.voidType(), null, 0, false);407 const fn_type = llvm.TypeRef.functionType(llvm.voidType(), null, 0, false);
src/llvm_bindings.zig+3
...@@ -125,6 +125,9 @@ pub const BuilderRef = opaque {...@@ -125,6 +125,9 @@ pub const BuilderRef = opaque {
125125
126 pub const buildStore = LLVMBuildStore;126 pub const buildStore = LLVMBuildStore;
127 extern fn LLVMBuildStore(*const BuilderRef, Val: *const ValueRef, Ptr: *const ValueRef) *const ValueRef;127 extern fn LLVMBuildStore(*const BuilderRef, Val: *const ValueRef, Ptr: *const ValueRef) *const ValueRef;
128
129 pub const buildLoad = LLVMBuildLoad;
130 extern fn LLVMBuildLoad(*const BuilderRef, PointerVal: *const ValueRef, Name: [*:0]const u8) *const ValueRef;
128};131};
129132
130pub const BasicBlockRef = opaque {133pub const BasicBlockRef = opaque {