| author | |
| committer | |
| log | a8520fbd0f73c57d133c28c44d97e1173c6fe381 |
| tree | 6b5480c45c1bf1317fe7a3d82a1da046835cac38 |
| parent | ad5770eba40e0cc425c7a1eab4d37c6f9788d670 |
14 files changed, 119 insertions(+), 1 deletions(-)
src/Air.zig+6| ... | ... | @@ -326,6 +326,10 @@ pub const Inst = struct { |
| 326 | 326 | /// Result type is always void. |
| 327 | 327 | /// Uses the `dbg_stmt` field. |
| 328 | 328 | dbg_stmt, |
| 329 | /// Marks the beginning of a semantic scope for debug info variables. | |
| 330 | dbg_block_begin, | |
| 331 | /// Marks the end of a semantic scope for debug info variables. | |
| 332 | dbg_block_end, | |
| 329 | 333 | /// Marks the start of an inline call. |
| 330 | 334 | /// Uses `ty_pl` with the payload being the index of a Value.Function in air.values. |
| 331 | 335 | dbg_inline_begin, |
| ... | ... | @@ -990,6 +994,8 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index) Type { |
| 990 | 994 | .dbg_stmt, |
| 991 | 995 | .dbg_inline_begin, |
| 992 | 996 | .dbg_inline_end, |
| 997 | .dbg_block_begin, | |
| 998 | .dbg_block_end, | |
| 993 | 999 | .dbg_var_ptr, |
| 994 | 1000 | .dbg_var_val, |
| 995 | 1001 | .store, |
src/AstGen.zig+12| ... | ... | @@ -2052,6 +2052,12 @@ fn blockExprStmts(gz: *GenZir, parent_scope: *Scope, statements: []const Ast.Nod |
| 2052 | 2052 | const tree = astgen.tree; |
| 2053 | 2053 | const node_tags = tree.nodes.items(.tag); |
| 2054 | 2054 | |
| 2055 | _ = try gz.add(.{ .tag = .extended, .data = .{ .extended = .{ | |
| 2056 | .opcode = .dbg_block_begin, | |
| 2057 | .small = undefined, | |
| 2058 | .operand = undefined | |
| 2059 | } } }); | |
| 2060 | ||
| 2055 | 2061 | var block_arena = std.heap.ArenaAllocator.init(gz.astgen.gpa); |
| 2056 | 2062 | defer block_arena.deinit(); |
| 2057 | 2063 | const block_arena_allocator = block_arena.allocator(); |
| ... | ... | @@ -2105,6 +2111,12 @@ fn blockExprStmts(gz: *GenZir, parent_scope: *Scope, statements: []const Ast.Nod |
| 2105 | 2111 | } |
| 2106 | 2112 | } |
| 2107 | 2113 | |
| 2114 | _ = try gz.add(.{ .tag = .extended, .data = .{ .extended = .{ | |
| 2115 | .opcode = .dbg_block_end, | |
| 2116 | .small = undefined, | |
| 2117 | .operand = undefined | |
| 2118 | } } }); | |
| 2119 | ||
| 2108 | 2120 | try genDefers(gz, parent_scope, scope, .normal_only); |
| 2109 | 2121 | try checkUsed(gz, parent_scope, scope); |
| 2110 | 2122 | } |
src/Liveness.zig+2| ... | ... | @@ -316,6 +316,8 @@ fn analyzeInst( |
| 316 | 316 | .dbg_stmt, |
| 317 | 317 | .dbg_inline_begin, |
| 318 | 318 | .dbg_inline_end, |
| 319 | .dbg_block_begin, | |
| 320 | .dbg_block_end, | |
| 319 | 321 | .unreach, |
| 320 | 322 | .fence, |
| 321 | 323 | .ret_addr, |
src/Sema.zig+25-1| ... | ... | @@ -1216,6 +1216,8 @@ fn zirExtended(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 1216 | 1216 | .wasm_memory_size => return sema.zirWasmMemorySize( block, extended), |
| 1217 | 1217 | .wasm_memory_grow => return sema.zirWasmMemoryGrow( block, extended), |
| 1218 | 1218 | .prefetch => return sema.zirPrefetch( block, extended), |
| 1219 | .dbg_block_begin => return sema.zirDbgBlockBegin( block), | |
| 1220 | .dbg_block_end => return sema.zirDbgBlockEnd( block), | |
| 1219 | 1221 | // zig fmt: on |
| 1220 | 1222 | } |
| 1221 | 1223 | } |
| ... | ... | @@ -4215,6 +4217,26 @@ fn zirDbgStmt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!voi |
| 4215 | 4217 | }); |
| 4216 | 4218 | } |
| 4217 | 4219 | |
| 4220 | fn zirDbgBlockBegin(sema: *Sema, block: *Block) CompileError!Air.Inst.Ref { | |
| 4221 | if (block.is_comptime or sema.mod.comp.bin_file.options.strip) return .void_value; | |
| 4222 | ||
| 4223 | _ = try block.addInst(.{ | |
| 4224 | .tag = .dbg_block_begin, | |
| 4225 | .data = undefined, | |
| 4226 | }); | |
| 4227 | return .void_value; | |
| 4228 | } | |
| 4229 | ||
| 4230 | fn zirDbgBlockEnd(sema: *Sema, block: *Block) CompileError!Air.Inst.Ref { | |
| 4231 | if (block.is_comptime or sema.mod.comp.bin_file.options.strip) return .void_value; | |
| 4232 | ||
| 4233 | _ = try block.addInst(.{ | |
| 4234 | .tag = .dbg_block_end, | |
| 4235 | .data = undefined, | |
| 4236 | }); | |
| 4237 | return .void_value; | |
| 4238 | } | |
| 4239 | ||
| 4218 | 4240 | fn zirDbgVar( |
| 4219 | 4241 | sema: *Sema, |
| 4220 | 4242 | block: *Block, |
| ... | ... | @@ -5224,7 +5246,9 @@ fn emitDbgInline( |
| 5224 | 5246 | new_func_ty: Type, |
| 5225 | 5247 | tag: Air.Inst.Tag, |
| 5226 | 5248 | ) CompileError!void { |
| 5227 | // No change of file; no dbg_inline needed. | |
| 5249 | if (sema.mod.comp.bin_file.options.strip) return; | |
| 5250 | ||
| 5251 | // Recursive inline call; no dbg_inline needed. | |
| 5228 | 5252 | if (old_func == new_func) return; |
| 5229 | 5253 | |
| 5230 | 5254 | try sema.air_values.append(sema.gpa, try Value.Tag.function.create(sema.arena, new_func)); |
src/Zir.zig+4| ... | ... | @@ -1646,6 +1646,10 @@ pub const Inst = struct { |
| 1646 | 1646 | /// The `@prefetch` builtin. |
| 1647 | 1647 | /// `operand` is payload index to `BinNode`. |
| 1648 | 1648 | prefetch, |
| 1649 | /// Marks the beginning of a semantic scope for debug info variables. | |
| 1650 | dbg_block_begin, | |
| 1651 | /// Marks the end of a semantic scope for debug info variables. | |
| 1652 | dbg_block_end, | |
| 1649 | 1653 | |
| 1650 | 1654 | pub const InstData = struct { |
| 1651 | 1655 | opcode: Extended, |
src/arch/aarch64/CodeGen.zig+9| ... | ... | @@ -654,6 +654,10 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void { |
| 654 | 654 | .dbg_inline_end, |
| 655 | 655 | => try self.airDbgInline(inst), |
| 656 | 656 | |
| 657 | .dbg_block_begin, | |
| 658 | .dbg_block_end, | |
| 659 | => try self.airDbgBlock(inst), | |
| 660 | ||
| 657 | 661 | .call => try self.airCall(inst, .auto), |
| 658 | 662 | .call_always_tail => try self.airCall(inst, .always_tail), |
| 659 | 663 | .call_never_tail => try self.airCall(inst, .never_tail), |
| ... | ... | @@ -2731,6 +2735,11 @@ fn airDbgInline(self: *Self, inst: Air.Inst.Index) !void { |
| 2731 | 2735 | return self.finishAir(inst, .dead, .{ .none, .none, .none }); |
| 2732 | 2736 | } |
| 2733 | 2737 | |
| 2738 | fn airDbgBlock(self: *Self, inst: Air.Inst.Index) !void { | |
| 2739 | // TODO emit debug info lexical block | |
| 2740 | return self.finishAir(inst, .dead, .{ .none, .none, .none }); | |
| 2741 | } | |
| 2742 | ||
| 2734 | 2743 | fn airDbgVar(self: *Self, inst: Air.Inst.Index) !void { |
| 2735 | 2744 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; |
| 2736 | 2745 | const name = self.air.nullTerminatedString(pl_op.payload); |
src/arch/arm/CodeGen.zig+9| ... | ... | @@ -644,6 +644,10 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void { |
| 644 | 644 | .dbg_inline_end, |
| 645 | 645 | => try self.airDbgInline(inst), |
| 646 | 646 | |
| 647 | .dbg_block_begin, | |
| 648 | .dbg_block_end, | |
| 649 | => try self.airDbgBlock(inst), | |
| 650 | ||
| 647 | 651 | .call => try self.airCall(inst, .auto), |
| 648 | 652 | .call_always_tail => try self.airCall(inst, .always_tail), |
| 649 | 653 | .call_never_tail => try self.airCall(inst, .never_tail), |
| ... | ... | @@ -2948,6 +2952,11 @@ fn airDbgInline(self: *Self, inst: Air.Inst.Index) !void { |
| 2948 | 2952 | return self.finishAir(inst, .dead, .{ .none, .none, .none }); |
| 2949 | 2953 | } |
| 2950 | 2954 | |
| 2955 | fn airDbgBlock(self: *Self, inst: Air.Inst.Index) !void { | |
| 2956 | // TODO emit debug info lexical block | |
| 2957 | return self.finishAir(inst, .dead, .{ .none, .none, .none }); | |
| 2958 | } | |
| 2959 | ||
| 2951 | 2960 | fn airDbgVar(self: *Self, inst: Air.Inst.Index) !void { |
| 2952 | 2961 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; |
| 2953 | 2962 | const name = self.air.nullTerminatedString(pl_op.payload); |
src/arch/riscv64/CodeGen.zig+9| ... | ... | @@ -618,6 +618,10 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void { |
| 618 | 618 | .dbg_inline_end, |
| 619 | 619 | => try self.airDbgInline(inst), |
| 620 | 620 | |
| 621 | .dbg_block_begin, | |
| 622 | .dbg_block_end, | |
| 623 | => try self.airDbgBlock(inst), | |
| 624 | ||
| 621 | 625 | .call => try self.airCall(inst, .auto), |
| 622 | 626 | .call_always_tail => try self.airCall(inst, .always_tail), |
| 623 | 627 | .call_never_tail => try self.airCall(inst, .never_tail), |
| ... | ... | @@ -1653,6 +1657,11 @@ fn airDbgInline(self: *Self, inst: Air.Inst.Index) !void { |
| 1653 | 1657 | return self.finishAir(inst, .dead, .{ .none, .none, .none }); |
| 1654 | 1658 | } |
| 1655 | 1659 | |
| 1660 | fn airDbgBlock(self: *Self, inst: Air.Inst.Index) !void { | |
| 1661 | // TODO emit debug info lexical block | |
| 1662 | return self.finishAir(inst, .dead, .{ .none, .none, .none }); | |
| 1663 | } | |
| 1664 | ||
| 1656 | 1665 | fn airDbgVar(self: *Self, inst: Air.Inst.Index) !void { |
| 1657 | 1666 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; |
| 1658 | 1667 | const name = self.air.nullTerminatedString(pl_op.payload); |
src/arch/wasm/CodeGen.zig+2| ... | ... | @@ -1330,6 +1330,8 @@ fn genInst(self: *Self, inst: Air.Inst.Index) !WValue { |
| 1330 | 1330 | .dbg_stmt, |
| 1331 | 1331 | .dbg_inline_begin, |
| 1332 | 1332 | .dbg_inline_end, |
| 1333 | .dbg_block_begin, | |
| 1334 | .dbg_block_end, | |
| 1333 | 1335 | .dbg_var_ptr, |
| 1334 | 1336 | .dbg_var_val, |
| 1335 | 1337 | => WValue.none, |
src/arch/x86_64/CodeGen.zig+9| ... | ... | @@ -735,6 +735,10 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void { |
| 735 | 735 | .dbg_inline_end, |
| 736 | 736 | => try self.airDbgInline(inst), |
| 737 | 737 | |
| 738 | .dbg_block_begin, | |
| 739 | .dbg_block_end, | |
| 740 | => try self.airDbgBlock(inst), | |
| 741 | ||
| 738 | 742 | .call => try self.airCall(inst, .auto), |
| 739 | 743 | .call_always_tail => try self.airCall(inst, .always_tail), |
| 740 | 744 | .call_never_tail => try self.airCall(inst, .never_tail), |
| ... | ... | @@ -3683,6 +3687,11 @@ fn airDbgInline(self: *Self, inst: Air.Inst.Index) !void { |
| 3683 | 3687 | return self.finishAir(inst, .dead, .{ .none, .none, .none }); |
| 3684 | 3688 | } |
| 3685 | 3689 | |
| 3690 | fn airDbgBlock(self: *Self, inst: Air.Inst.Index) !void { | |
| 3691 | // TODO emit debug info lexical block | |
| 3692 | return self.finishAir(inst, .dead, .{ .none, .none, .none }); | |
| 3693 | } | |
| 3694 | ||
| 3686 | 3695 | fn airDbgVar(self: *Self, inst: Air.Inst.Index) !void { |
| 3687 | 3696 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; |
| 3688 | 3697 | const name = self.air.nullTerminatedString(pl_op.payload); |
src/codegen/c.zig+4| ... | ... | @@ -1786,6 +1786,10 @@ fn genBody(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail, OutO |
| 1786 | 1786 | .dbg_inline_end, |
| 1787 | 1787 | => try airDbgInline(f, inst), |
| 1788 | 1788 | |
| 1789 | .dbg_block_begin, | |
| 1790 | .dbg_block_end, | |
| 1791 | => CValue{ .none = {} }, | |
| 1792 | ||
| 1789 | 1793 | .call => try airCall(f, inst, .auto), |
| 1790 | 1794 | .call_always_tail => try airCall(f, inst, .always_tail), |
| 1791 | 1795 | .call_never_tail => try airCall(f, inst, .never_tail), |
src/codegen/llvm.zig+22| ... | ... | @@ -3220,6 +3220,10 @@ pub const FuncGen = struct { |
| 3220 | 3220 | /// Stack of locations where a call was inlined. |
| 3221 | 3221 | dbg_inlined: std.ArrayListUnmanaged(DbgState) = .{}, |
| 3222 | 3222 | |
| 3223 | /// Stack of `DILexicalBlock`s. dbg_block instructions cannot happend accross | |
| 3224 | /// dbg_inline instructions so no special handling there is required. | |
| 3225 | dbg_block_stack: std.ArrayListUnmanaged(*llvm.DIScope) = .{}, | |
| 3226 | ||
| 3223 | 3227 | /// This stores the LLVM values used in a function, such that they can be referred to |
| 3224 | 3228 | /// in other instructions. This table is cleared before every function is generated. |
| 3225 | 3229 | func_inst_table: std.AutoHashMapUnmanaged(Air.Inst.Ref, *const llvm.Value), |
| ... | ... | @@ -3254,6 +3258,7 @@ pub const FuncGen = struct { |
| 3254 | 3258 | fn deinit(self: *FuncGen) void { |
| 3255 | 3259 | self.builder.dispose(); |
| 3256 | 3260 | self.dbg_inlined.deinit(self.gpa); |
| 3261 | self.dbg_block_stack.deinit(self.gpa); | |
| 3257 | 3262 | self.func_inst_table.deinit(self.gpa); |
| 3258 | 3263 | self.blocks.deinit(self.gpa); |
| 3259 | 3264 | } |
| ... | ... | @@ -3475,6 +3480,8 @@ pub const FuncGen = struct { |
| 3475 | 3480 | .dbg_stmt => self.airDbgStmt(inst), |
| 3476 | 3481 | .dbg_inline_begin => try self.airDbgInlineBegin(inst), |
| 3477 | 3482 | .dbg_inline_end => try self.airDbgInlineEnd(inst), |
| 3483 | .dbg_block_begin => try self.airDbgBlockBegin(), | |
| 3484 | .dbg_block_end => try self.airDbgBlockEnd(), | |
| 3478 | 3485 | .dbg_var_ptr => try self.airDbgVarPtr(inst), |
| 3479 | 3486 | .dbg_var_val => try self.airDbgVarVal(inst), |
| 3480 | 3487 | // zig fmt: on |
| ... | ... | @@ -4256,6 +4263,21 @@ pub const FuncGen = struct { |
| 4256 | 4263 | return null; |
| 4257 | 4264 | } |
| 4258 | 4265 | |
| 4266 | fn airDbgBlockBegin(self: *FuncGen) !?*const llvm.Value { | |
| 4267 | const dib = self.dg.object.di_builder orelse return null; | |
| 4268 | const old_scope = self.di_scope.?; | |
| 4269 | try self.dbg_block_stack.append(self.gpa, old_scope); | |
| 4270 | const lexical_block = dib.createLexicalBlock(old_scope, self.di_file.?, self.prev_dbg_line, self.prev_dbg_column); | |
| 4271 | self.di_scope = lexical_block.toScope(); | |
| 4272 | return null; | |
| 4273 | } | |
| 4274 | ||
| 4275 | fn airDbgBlockEnd(self: *FuncGen) !?*const llvm.Value { | |
| 4276 | if (self.dg.object.di_builder == null) return null; | |
| 4277 | self.di_scope = self.dbg_block_stack.pop(); | |
| 4278 | return null; | |
| 4279 | } | |
| 4280 | ||
| 4259 | 4281 | fn airDbgVarPtr(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value { |
| 4260 | 4282 | const dib = self.dg.object.di_builder orelse return null; |
| 4261 | 4283 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; |
src/print_air.zig+2| ... | ... | @@ -272,6 +272,8 @@ const Writer = struct { |
| 272 | 272 | .mul_with_overflow, |
| 273 | 273 | .shl_with_overflow, |
| 274 | 274 | => try w.writeOverflow(s, inst), |
| 275 | ||
| 276 | .dbg_block_begin, .dbg_block_end => {}, | |
| 275 | 277 | } |
| 276 | 278 | } |
| 277 | 279 |
src/print_zir.zig+4| ... | ... | @@ -463,6 +463,10 @@ const Writer = struct { |
| 463 | 463 | .builtin_src, |
| 464 | 464 | => try self.writeExtNode(stream, extended), |
| 465 | 465 | |
| 466 | .dbg_block_begin, | |
| 467 | .dbg_block_end, | |
| 468 | => try stream.writeAll("))"), | |
| 469 | ||
| 466 | 470 | .@"asm" => try self.writeAsm(stream, extended), |
| 467 | 471 | .func => try self.writeFuncExtended(stream, extended), |
| 468 | 472 | .variable => try self.writeVarExtended(stream, extended), |