authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-08-02 21:28:06-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-08-02 21:28:06-07:00
log659603c6211e5628db0ab0dd9b1e8454ed1b69c6
treeb289d736f4ac0956dec00b72ca6e1ac0af4c9855
parent42d331b58aa874420d2515071e94f046adaf0689

codegen: emit .debug_line ops for IR instructions


7 files changed, 159 insertions(+), 66 deletions(-)

lib/std/zig.zig+9
......@@ -43,6 +43,15 @@ pub fn findLineColumn(source: []const u8, byte_offset: usize) struct { line: usi
4343 return .{ .line = line, .column = column };
4444}
4545
46pub fn lineDelta(source: []const u8, start: usize, end: usize) usize {
47 var line: usize = 0;
48 for (source[start..end]) |byte| switch (byte) {
49 '\n' => line += 1,
50 else => continue,
51 };
52 return line;
53}
54
4655/// Returns the standard file system basename of a binary generated by the Zig compiler.
4756pub fn binNameAlloc(
4857 allocator: *std.mem.Allocator,
src-self-hosted/astgen.zig+2-1
......@@ -120,6 +120,8 @@ pub fn blockExpr(mod: *Module, parent_scope: *Scope, block_node: *ast.Node.Block
120120
121121 var scope = parent_scope;
122122 for (block_node.statements()) |statement| {
123 const src = scope.tree().token_locs[statement.firstToken()].start;
124 _ = try addZIRNoOp(mod, scope, src, .dbg_stmt);
123125 switch (statement.tag) {
124126 .VarDecl => {
125127 const var_decl_node = statement.castTag(.VarDecl).?;
......@@ -146,7 +148,6 @@ pub fn blockExpr(mod: *Module, parent_scope: *Scope, block_node: *ast.Node.Block
146148 else => {
147149 const possibly_unused_result = try expr(mod, scope, .none, statement);
148150 if (!possibly_unused_result.tag.isNoReturn()) {
149 const src = scope.tree().token_locs[statement.firstToken()].start;
150151 _ = try addZIRUnOp(mod, scope, src, .ensure_result_used, possibly_unused_result);
151152 }
152153 },
src-self-hosted/codegen.zig+128-61
......@@ -12,6 +12,11 @@ const ErrorMsg = Module.ErrorMsg;
1212const Target = std.Target;
1313const Allocator = mem.Allocator;
1414const trace = @import("tracy.zig").trace;
15const DW = std.dwarf;
16const leb128 = std.debug.leb;
17
18// TODO Turn back on zig fmt when https://github.com/ziglang/zig/issues/5948 is implemented.
19// zig fmt: off
1520
1621/// The codegen-related data that is stored in `ir.Inst.Block` instructions.
1722pub const BlockData = struct {
......@@ -52,57 +57,57 @@ pub fn generateSymbol(
5257 switch (typed_value.ty.zigTypeTag()) {
5358 .Fn => {
5459 switch (bin_file.base.options.target.cpu.arch) {
55 //.arm => return Function(.arm).generateSymbol(bin_file, src, typed_value, code),
56 //.armeb => return Function(.armeb).generateSymbol(bin_file, src, typed_value, code),
57 //.aarch64 => return Function(.aarch64).generateSymbol(bin_file, src, typed_value, code),
58 //.aarch64_be => return Function(.aarch64_be).generateSymbol(bin_file, src, typed_value, code),
59 //.aarch64_32 => return Function(.aarch64_32).generateSymbol(bin_file, src, typed_value, code),
60 //.arc => return Function(.arc).generateSymbol(bin_file, src, typed_value, code),
61 //.avr => return Function(.avr).generateSymbol(bin_file, src, typed_value, code),
62 //.bpfel => return Function(.bpfel).generateSymbol(bin_file, src, typed_value, code),
63 //.bpfeb => return Function(.bpfeb).generateSymbol(bin_file, src, typed_value, code),
64 //.hexagon => return Function(.hexagon).generateSymbol(bin_file, src, typed_value, code),
65 //.mips => return Function(.mips).generateSymbol(bin_file, src, typed_value, code),
66 //.mipsel => return Function(.mipsel).generateSymbol(bin_file, src, typed_value, code),
67 //.mips64 => return Function(.mips64).generateSymbol(bin_file, src, typed_value, code),
68 //.mips64el => return Function(.mips64el).generateSymbol(bin_file, src, typed_value, code),
69 //.msp430 => return Function(.msp430).generateSymbol(bin_file, src, typed_value, code),
70 //.powerpc => return Function(.powerpc).generateSymbol(bin_file, src, typed_value, code),
71 //.powerpc64 => return Function(.powerpc64).generateSymbol(bin_file, src, typed_value, code),
72 //.powerpc64le => return Function(.powerpc64le).generateSymbol(bin_file, src, typed_value, code),
73 //.r600 => return Function(.r600).generateSymbol(bin_file, src, typed_value, code),
74 //.amdgcn => return Function(.amdgcn).generateSymbol(bin_file, src, typed_value, code),
75 //.riscv32 => return Function(.riscv32).generateSymbol(bin_file, src, typed_value, code),
76 //.riscv64 => return Function(.riscv64).generateSymbol(bin_file, src, typed_value, code),
77 //.sparc => return Function(.sparc).generateSymbol(bin_file, src, typed_value, code),
78 //.sparcv9 => return Function(.sparcv9).generateSymbol(bin_file, src, typed_value, code),
79 //.sparcel => return Function(.sparcel).generateSymbol(bin_file, src, typed_value, code),
80 //.s390x => return Function(.s390x).generateSymbol(bin_file, src, typed_value, code),
81 //.tce => return Function(.tce).generateSymbol(bin_file, src, typed_value, code),
82 //.tcele => return Function(.tcele).generateSymbol(bin_file, src, typed_value, code),
83 //.thumb => return Function(.thumb).generateSymbol(bin_file, src, typed_value, code),
84 //.thumbeb => return Function(.thumbeb).generateSymbol(bin_file, src, typed_value, code),
85 //.i386 => return Function(.i386).generateSymbol(bin_file, src, typed_value, code),
86 .x86_64 => return Function(.x86_64).generateSymbol(bin_file, src, typed_value, code),
87 //.xcore => return Function(.xcore).generateSymbol(bin_file, src, typed_value, code),
88 //.nvptx => return Function(.nvptx).generateSymbol(bin_file, src, typed_value, code),
89 //.nvptx64 => return Function(.nvptx64).generateSymbol(bin_file, src, typed_value, code),
90 //.le32 => return Function(.le32).generateSymbol(bin_file, src, typed_value, code),
91 //.le64 => return Function(.le64).generateSymbol(bin_file, src, typed_value, code),
92 //.amdil => return Function(.amdil).generateSymbol(bin_file, src, typed_value, code),
93 //.amdil64 => return Function(.amdil64).generateSymbol(bin_file, src, typed_value, code),
94 //.hsail => return Function(.hsail).generateSymbol(bin_file, src, typed_value, code),
95 //.hsail64 => return Function(.hsail64).generateSymbol(bin_file, src, typed_value, code),
96 //.spir => return Function(.spir).generateSymbol(bin_file, src, typed_value, code),
97 //.spir64 => return Function(.spir64).generateSymbol(bin_file, src, typed_value, code),
98 //.kalimba => return Function(.kalimba).generateSymbol(bin_file, src, typed_value, code),
99 //.shave => return Function(.shave).generateSymbol(bin_file, src, typed_value, code),
100 //.lanai => return Function(.lanai).generateSymbol(bin_file, src, typed_value, code),
101 //.wasm32 => return Function(.wasm32).generateSymbol(bin_file, src, typed_value, code),
102 //.wasm64 => return Function(.wasm64).generateSymbol(bin_file, src, typed_value, code),
103 //.renderscript32 => return Function(.renderscript32).generateSymbol(bin_file, src, typed_value, code),
104 //.renderscript64 => return Function(.renderscript64).generateSymbol(bin_file, src, typed_value, code),
105 //.ve => return Function(.ve).generateSymbol(bin_file, src, typed_value, code),
60 //.arm => return Function(.arm).generateSymbol(bin_file, src, typed_value, code, dbg_line),
61 //.armeb => return Function(.armeb).generateSymbol(bin_file, src, typed_value, code, dbg_line),
62 //.aarch64 => return Function(.aarch64).generateSymbol(bin_file, src, typed_value, code, dbg_line),
63 //.aarch64_be => return Function(.aarch64_be).generateSymbol(bin_file, src, typed_value, code, dbg_line),
64 //.aarch64_32 => return Function(.aarch64_32).generateSymbol(bin_file, src, typed_value, code, dbg_line),
65 //.arc => return Function(.arc).generateSymbol(bin_file, src, typed_value, code, dbg_line),
66 //.avr => return Function(.avr).generateSymbol(bin_file, src, typed_value, code, dbg_line),
67 //.bpfel => return Function(.bpfel).generateSymbol(bin_file, src, typed_value, code, dbg_line),
68 //.bpfeb => return Function(.bpfeb).generateSymbol(bin_file, src, typed_value, code, dbg_line),
69 //.hexagon => return Function(.hexagon).generateSymbol(bin_file, src, typed_value, code, dbg_line),
70 //.mips => return Function(.mips).generateSymbol(bin_file, src, typed_value, code, dbg_line),
71 //.mipsel => return Function(.mipsel).generateSymbol(bin_file, src, typed_value, code, dbg_line),
72 //.mips64 => return Function(.mips64).generateSymbol(bin_file, src, typed_value, code, dbg_line),
73 //.mips64el => return Function(.mips64el).generateSymbol(bin_file, src, typed_value, code, dbg_line),
74 //.msp430 => return Function(.msp430).generateSymbol(bin_file, src, typed_value, code, dbg_line),
75 //.powerpc => return Function(.powerpc).generateSymbol(bin_file, src, typed_value, code, dbg_line),
76 //.powerpc64 => return Function(.powerpc64).generateSymbol(bin_file, src, typed_value, code, dbg_line),
77 //.powerpc64le => return Function(.powerpc64le).generateSymbol(bin_file, src, typed_value, code, dbg_line),
78 //.r600 => return Function(.r600).generateSymbol(bin_file, src, typed_value, code, dbg_line),
79 //.amdgcn => return Function(.amdgcn).generateSymbol(bin_file, src, typed_value, code, dbg_line),
80 //.riscv32 => return Function(.riscv32).generateSymbol(bin_file, src, typed_value, code, dbg_line),
81 //.riscv64 => return Function(.riscv64).generateSymbol(bin_file, src, typed_value, code, dbg_line),
82 //.sparc => return Function(.sparc).generateSymbol(bin_file, src, typed_value, code, dbg_line),
83 //.sparcv9 => return Function(.sparcv9).generateSymbol(bin_file, src, typed_value, code, dbg_line),
84 //.sparcel => return Function(.sparcel).generateSymbol(bin_file, src, typed_value, code, dbg_line),
85 //.s390x => return Function(.s390x).generateSymbol(bin_file, src, typed_value, code, dbg_line),
86 //.tce => return Function(.tce).generateSymbol(bin_file, src, typed_value, code, dbg_line),
87 //.tcele => return Function(.tcele).generateSymbol(bin_file, src, typed_value, code, dbg_line),
88 //.thumb => return Function(.thumb).generateSymbol(bin_file, src, typed_value, code, dbg_line),
89 //.thumbeb => return Function(.thumbeb).generateSymbol(bin_file, src, typed_value, code, dbg_line),
90 //.i386 => return Function(.i386).generateSymbol(bin_file, src, typed_value, code, dbg_line),
91 .x86_64 => return Function(.x86_64).generateSymbol(bin_file, src, typed_value, code, dbg_line),
92 //.xcore => return Function(.xcore).generateSymbol(bin_file, src, typed_value, code, dbg_line),
93 //.nvptx => return Function(.nvptx).generateSymbol(bin_file, src, typed_value, code, dbg_line),
94 //.nvptx64 => return Function(.nvptx64).generateSymbol(bin_file, src, typed_value, code, dbg_line),
95 //.le32 => return Function(.le32).generateSymbol(bin_file, src, typed_value, code, dbg_line),
96 //.le64 => return Function(.le64).generateSymbol(bin_file, src, typed_value, code, dbg_line),
97 //.amdil => return Function(.amdil).generateSymbol(bin_file, src, typed_value, code, dbg_line),
98 //.amdil64 => return Function(.amdil64).generateSymbol(bin_file, src, typed_value, code, dbg_line),
99 //.hsail => return Function(.hsail).generateSymbol(bin_file, src, typed_value, code, dbg_line),
100 //.hsail64 => return Function(.hsail64).generateSymbol(bin_file, src, typed_value, code, dbg_line),
101 //.spir => return Function(.spir).generateSymbol(bin_file, src, typed_value, code, dbg_line),
102 //.spir64 => return Function(.spir64).generateSymbol(bin_file, src, typed_value, code, dbg_line),
103 //.kalimba => return Function(.kalimba).generateSymbol(bin_file, src, typed_value, code, dbg_line),
104 //.shave => return Function(.shave).generateSymbol(bin_file, src, typed_value, code, dbg_line),
105 //.lanai => return Function(.lanai).generateSymbol(bin_file, src, typed_value, code, dbg_line),
106 //.wasm32 => return Function(.wasm32).generateSymbol(bin_file, src, typed_value, code, dbg_line),
107 //.wasm64 => return Function(.wasm64).generateSymbol(bin_file, src, typed_value, code, dbg_line),
108 //.renderscript32 => return Function(.renderscript32).generateSymbol(bin_file, src, typed_value, code, dbg_line),
109 //.renderscript64 => return Function(.renderscript64).generateSymbol(bin_file, src, typed_value, code, dbg_line),
110 //.ve => return Function(.ve).generateSymbol(bin_file, src, typed_value, code, dbg_line),
106111 else => @panic("Backend architectures that don't have good support yet are commented out, to improve compilation performance. If you are interested in one of these other backends feel free to uncomment them. Eventually these will be completed, but stage1 is slow and a memory hog."),
107112 }
108113 },
......@@ -207,6 +212,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
207212 target: *const std.Target,
208213 mod_fn: *const Module.Fn,
209214 code: *std.ArrayList(u8),
215 dbg_line: *std.ArrayList(u8),
210216 err_msg: ?*ErrorMsg,
211217 args: []MCValue,
212218 ret_mcv: MCValue,
......@@ -215,6 +221,15 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
215221 src: usize,
216222 stack_align: u32,
217223
224 /// Byte offset within the source file.
225 prev_di_src: usize,
226 /// Relative to the beginning of `code`.
227 prev_di_pc: usize,
228 /// Used to find newlines and count line deltas.
229 source: []const u8,
230 /// Byte offset within the source file of the ending curly.
231 rbrace_src: usize,
232
218233 /// The value is an offset into the `Function` `code` from the beginning.
219234 /// To perform the reloc, write 32-bit signed little-endian integer
220235 /// which is a relative jump, based on the address following the reloc.
......@@ -366,6 +381,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
366381 src: usize,
367382 typed_value: TypedValue,
368383 code: *std.ArrayList(u8),
384 dbg_line: *std.ArrayList(u8),
369385 ) GenerateSymbolError!Result {
370386 const module_fn = typed_value.val.cast(Value.Payload.Function).?.func;
371387
......@@ -380,12 +396,20 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
380396 const branch = try branch_stack.addOne();
381397 branch.* = .{};
382398
399 const scope_file = module_fn.owner_decl.scope.cast(Module.Scope.File).?;
400 const tree = scope_file.contents.tree;
401 const fn_proto = tree.root_node.decls()[module_fn.owner_decl.src_index].castTag(.FnProto).?;
402 const block = fn_proto.body().?.castTag(.Block).?;
403 const lbrace_src = tree.token_locs[block.lbrace].start;
404 const rbrace_src = tree.token_locs[block.rbrace].start;
405
383406 var function = Self{
384407 .gpa = bin_file.allocator,
385408 .target = &bin_file.base.options.target,
386409 .bin_file = bin_file,
387410 .mod_fn = module_fn,
388411 .code = code,
412 .dbg_line = dbg_line,
389413 .err_msg = null,
390414 .args = undefined, // populated after `resolveCallingConventionValues`
391415 .ret_mcv = undefined, // populated after `resolveCallingConventionValues`
......@@ -394,6 +418,10 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
394418 .branch_stack = &branch_stack,
395419 .src = src,
396420 .stack_align = undefined,
421 .prev_di_pc = 0,
422 .prev_di_src = lbrace_src,
423 .rbrace_src = rbrace_src,
424 .source = tree.source,
397425 };
398426 defer function.exitlude_jump_relocs.deinit(bin_file.allocator);
399427
......@@ -432,21 +460,16 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
432460 // TODO During semantic analysis, check if there are no function calls. If there
433461 // are none, here we can omit the part where we subtract and then add rsp.
434462 self.code.appendSliceAssumeCapacity(&[_]u8{
435 // push rbp
436 0x55,
437 // mov rbp, rsp
438 0x48,
439 0x89,
440 0xe5,
441 // sub rsp, imm32 (with reloc)
442 0x48,
443 0x81,
444 0xec,
463 0x55, // push rbp
464 0x48, 0x89, 0xe5, // mov rbp, rsp
465 0x48, 0x81, 0xec, // sub rsp, imm32 (with reloc)
445466 });
446467 const reloc_index = self.code.items.len;
447468 self.code.items.len += 4;
448469
470 try self.dbgSetPrologueEnd();
449471 try self.genBody(self.mod_fn.analysis.success);
472 try self.dbgSetEpilogueBegin();
450473
451474 const stack_end = self.branch_stack.items[0].max_end_stack;
452475 if (stack_end > math.maxInt(i32))
......@@ -486,13 +509,19 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
486509 0xc3, // ret
487510 });
488511 } else {
512 try self.dbgSetPrologueEnd();
489513 try self.genBody(self.mod_fn.analysis.success);
514 try self.dbgSetEpilogueBegin();
490515 }
491516 },
492517 else => {
518 try self.dbgSetPrologueEnd();
493519 try self.genBody(self.mod_fn.analysis.success);
520 try self.dbgSetEpilogueBegin();
494521 },
495522 }
523 // Drop them off at the rbrace.
524 try self.dbgAdvancePCAndLine(self.rbrace_src);
496525 }
497526
498527 fn genBody(self: *Self, body: ir.Body) InnerError!void {
......@@ -509,6 +538,38 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
509538 }
510539 }
511540
541 fn dbgSetPrologueEnd(self: *Self) InnerError!void {
542 try self.dbg_line.append(DW.LNS_set_prologue_end);
543 try self.dbgAdvancePCAndLine(self.prev_di_src);
544 }
545
546 fn dbgSetEpilogueBegin(self: *Self) InnerError!void {
547 try self.dbg_line.append(DW.LNS_set_epilogue_begin);
548 try self.dbgAdvancePCAndLine(self.prev_di_src);
549 }
550
551 fn dbgAdvancePCAndLine(self: *Self, src: usize) InnerError!void {
552 // TODO Look into improving the performance here by adding a token-index-to-line
553 // lookup table, and changing ir.Inst from storing byte offset to token. Currently
554 // this involves scanning over the source code for newlines
555 // (but only from the previous byte offset to the new one).
556 const delta_line = std.zig.lineDelta(self.source, self.prev_di_src, src);
557 const delta_pc = self.code.items.len - self.prev_di_pc;
558 self.prev_di_src = src;
559 self.prev_di_pc = self.code.items.len;
560 // TODO Look into using the DWARF special opcodes to compress this data. It lets you emit
561 // single-byte opcodes that add different numbers to both the PC and the line number
562 // at the same time.
563 try self.dbg_line.ensureCapacity(self.dbg_line.items.len + 11);
564 self.dbg_line.appendAssumeCapacity(DW.LNS_advance_pc);
565 leb128.writeULEB128(self.dbg_line.writer(), delta_pc) catch unreachable;
566 if (delta_line != 0) {
567 self.dbg_line.appendAssumeCapacity(DW.LNS_advance_line);
568 leb128.writeULEB128(self.dbg_line.writer(), delta_line) catch unreachable;
569 }
570 self.dbg_line.appendAssumeCapacity(DW.LNS_copy);
571 }
572
512573 fn processDeath(self: *Self, inst: *ir.Inst) void {
513574 const branch = &self.branch_stack.items[self.branch_stack.items.len - 1];
514575 const entry = branch.inst_table.getEntry(inst) orelse return;
......@@ -544,6 +605,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
544605 .cmp_neq => return self.genCmp(inst.castTag(.cmp_neq).?, .neq),
545606 .condbr => return self.genCondBr(inst.castTag(.condbr).?),
546607 .constant => unreachable, // excluded from function bodies
608 .dbg_stmt => return self.genDbgStmt(inst.castTag(.dbg_stmt).?),
547609 .floatcast => return self.genFloatCast(inst.castTag(.floatcast).?),
548610 .intcast => return self.genIntCast(inst.castTag(.intcast).?),
549611 .isnonnull => return self.genIsNonNull(inst.castTag(.isnonnull).?),
......@@ -1107,6 +1169,11 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
11071169 }
11081170 }
11091171
1172 fn genDbgStmt(self: *Self, inst: *ir.Inst.NoOp) !MCValue {
1173 try self.dbgAdvancePCAndLine(inst.base.src);
1174 return MCValue.none;
1175 }
1176
11101177 fn genCondBr(self: *Self, inst: *ir.Inst.CondBr) !MCValue {
11111178 switch (arch) {
11121179 .x86_64 => {
src-self-hosted/ir.zig+2
......@@ -65,6 +65,7 @@ pub const Inst = struct {
6565 cmp_neq,
6666 condbr,
6767 constant,
68 dbg_stmt,
6869 isnonnull,
6970 isnull,
7071 /// Read a value from a pointer.
......@@ -88,6 +89,7 @@ pub const Inst = struct {
8889 .unreach,
8990 .arg,
9091 .breakpoint,
92 .dbg_stmt,
9193 => NoOp,
9294
9395 .ref,
src-self-hosted/link.zig+7-4
......@@ -2024,9 +2024,9 @@ pub const File = struct {
20242024 // line number of the open curly from the beginning of the file.
20252025 const fn_proto = file_ast_decls[decl.src_index].castTag(.FnProto).?;
20262026 const block = fn_proto.body().?.castTag(.Block).?;
2027 const loc = tree.tokenLocation(0, block.lbrace);
2027 const line_delta = std.zig.lineDelta(tree.source, 0, tree.token_locs[block.lbrace].start);
20282028 // No need to add one; this is a delta from DWARF's starting line number (1).
2029 break :blk @intCast(u28, loc.line);
2029 break :blk @intCast(u28, line_delta);
20302030 } else {
20312031 const prev_src_fn = src_file.fns.entries.items[src_fn_index - 1].key;
20322032 const mod_fn = @fieldParentPtr(Module.Fn, "link", prev_src_fn);
......@@ -2035,9 +2035,12 @@ pub const File = struct {
20352035 const prev_block = prev_fn_proto.body().?.castTag(.Block).?;
20362036 const this_block = this_fn_proto.body().?.castTag(.Block).?;
20372037 // Find the difference between prev decl end curly and this decl begin curly.
2038 const loc = tree.tokenLocation(tree.token_locs[prev_block.rbrace].start, this_block.lbrace);
2038 const line_delta = std.zig.lineDelta(tree.source,
2039 tree.token_locs[prev_block.rbrace].start,
2040 tree.token_locs[this_block.lbrace].start,
2041 );
20392042 // No need to add one; this is a delta from the previous line number.
2040 break :blk @intCast(u28, loc.line);
2043 break :blk @intCast(u28, line_delta);
20412044 }
20422045 };
20432046
src-self-hosted/zir.zig+5
......@@ -107,6 +107,8 @@ pub const Inst = struct {
107107 condbr,
108108 /// Special case, has no textual representation.
109109 @"const",
110 /// Declares the beginning of a statement. Used for debug info.
111 dbg_stmt,
110112 /// Represents a pointer to a global decl by name.
111113 declref,
112114 /// Represents a pointer to a global decl by string name.
......@@ -211,6 +213,7 @@ pub const Inst = struct {
211213 return switch (tag) {
212214 .arg,
213215 .breakpoint,
216 .dbg_stmt,
214217 .returnvoid,
215218 .alloc_inferred,
216219 .ret_ptr,
......@@ -324,6 +327,7 @@ pub const Inst = struct {
324327 .coerce_result_block_ptr,
325328 .coerce_to_ptr_elem,
326329 .@"const",
330 .dbg_stmt,
327331 .declref,
328332 .declref_str,
329333 .declval,
......@@ -1843,6 +1847,7 @@ const EmitZIR = struct {
18431847 .breakpoint => try self.emitNoOp(inst.src, .breakpoint),
18441848 .unreach => try self.emitNoOp(inst.src, .@"unreachable"),
18451849 .retvoid => try self.emitNoOp(inst.src, .returnvoid),
1850 .dbg_stmt => try self.emitNoOp(inst.src, .dbg_stmt),
18461851
18471852 .not => try self.emitUnOp(inst.src, new_body, inst.castTag(.not).?, .boolnot),
18481853 .ret => try self.emitUnOp(inst.src, new_body, inst.castTag(.ret).?, .@"return"),
src-self-hosted/zir_sema.zig+6
......@@ -41,6 +41,7 @@ pub fn analyzeInst(mod: *Module, scope: *Scope, old_inst: *zir.Inst) InnerError!
4141 .coerce_to_ptr_elem => return analyzeInstCoerceToPtrElem(mod, scope, old_inst.castTag(.coerce_to_ptr_elem).?),
4242 .compileerror => return analyzeInstCompileError(mod, scope, old_inst.castTag(.compileerror).?),
4343 .@"const" => return analyzeInstConst(mod, scope, old_inst.castTag(.@"const").?),
44 .dbg_stmt => return analyzeInstDbgStmt(mod, scope, old_inst.castTag(.dbg_stmt).?),
4445 .declref => return analyzeInstDeclRef(mod, scope, old_inst.castTag(.declref).?),
4546 .declref_str => return analyzeInstDeclRefStr(mod, scope, old_inst.castTag(.declref_str).?),
4647 .declval => return analyzeInstDeclVal(mod, scope, old_inst.castTag(.declval).?),
......@@ -487,6 +488,11 @@ fn analyzeInstBreakVoid(mod: *Module, scope: *Scope, inst: *zir.Inst.BreakVoid)
487488 return analyzeBreak(mod, scope, inst.base.src, block, void_inst);
488489}
489490
491fn analyzeInstDbgStmt(mod: *Module, scope: *Scope, inst: *zir.Inst.NoOp) InnerError!*Inst {
492 const b = try mod.requireRuntimeBlock(scope, inst.base.src);
493 return mod.addNoOp(b, inst.base.src, Type.initTag(.void), .dbg_stmt);
494}
495
490496fn analyzeInstDeclRefStr(mod: *Module, scope: *Scope, inst: *zir.Inst.DeclRefStr) InnerError!*Inst {
491497 const decl_name = try resolveConstString(mod, scope, inst.positionals.name);
492498 return mod.analyzeDeclRefByName(scope, inst.base.src, decl_name);