stage2: @returnAddress()
This commit is contained in:
@@ -1125,6 +1125,7 @@ fn genBody(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail, OutO
|
||||
.arg => airArg(f),
|
||||
|
||||
.breakpoint => try airBreakpoint(f),
|
||||
.ret_addr => try airRetAddr(f),
|
||||
.unreach => try airUnreach(f),
|
||||
.fence => try airFence(f, inst),
|
||||
|
||||
@@ -2191,6 +2192,10 @@ fn airBreakpoint(f: *Function) !CValue {
|
||||
return CValue.none;
|
||||
}
|
||||
|
||||
fn airRetAddr(f: *Function) !CValue {
|
||||
return f.fail("TODO implement codegen for airRetAddr", .{});
|
||||
}
|
||||
|
||||
fn airFence(f: *Function, inst: Air.Inst.Index) !CValue {
|
||||
const atomic_order = f.air.instructions.items(.data)[inst].fence;
|
||||
const writer = f.object.writer();
|
||||
|
||||
@@ -1747,6 +1747,7 @@ pub const FuncGen = struct {
|
||||
.br => try self.airBr(inst),
|
||||
.switch_br => try self.airSwitchBr(inst),
|
||||
.breakpoint => try self.airBreakpoint(inst),
|
||||
.ret_addr => try self.airRetAddr(inst),
|
||||
.call => try self.airCall(inst),
|
||||
.cond_br => try self.airCondBr(inst),
|
||||
.intcast => try self.airIntCast(inst),
|
||||
@@ -3550,6 +3551,15 @@ pub const FuncGen = struct {
|
||||
return null;
|
||||
}
|
||||
|
||||
fn airRetAddr(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value {
|
||||
_ = inst;
|
||||
const i32_zero = self.context.intType(32).constNull();
|
||||
const usize_llvm_ty = try self.dg.llvmType(Type.usize);
|
||||
const llvm_fn = self.getIntrinsic("llvm.returnaddress", &.{});
|
||||
const ptr_val = self.builder.buildCall(llvm_fn, &[_]*const llvm.Value{i32_zero}, 1, .Fast, .Auto, "");
|
||||
return self.builder.buildPtrToInt(ptr_val, usize_llvm_ty, "");
|
||||
}
|
||||
|
||||
fn airFence(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value {
|
||||
const atomic_order = self.air.instructions.items(.data)[inst].fence;
|
||||
const llvm_memory_order = toLlvmAtomicOrdering(atomic_order);
|
||||
|
||||
Reference in New Issue
Block a user