| ... | ... | @@ -1255,8 +1255,8 @@ const Writer = struct { |
| 1255 | 1255 | bool => return stream.writeByte("01"[@boolToInt(param)]), |
| 1256 | 1256 | []u8, []const u8 => return stream.print("\"{Z}\"", .{param}), |
| 1257 | 1257 | BigIntConst, usize => return stream.print("{}", .{param}), |
| 1258 | | TypedValue => unreachable, // this is a special case |
| 1259 | | *IrModule.Decl => unreachable, // this is a special case |
| 1258 | TypedValue => return stream.print("TypedValue{{ .ty = {}, .val = {}}}", .{ param.ty, param.val }), |
| 1259 | *IrModule.Decl => return stream.print("Decl({s})", .{param.name}), |
| 1260 | 1260 | *Inst.Block => { |
| 1261 | 1261 | const name = self.block_table.get(param).?; |
| 1262 | 1262 | return stream.print("\"{Z}\"", .{name}); |
| ... | ... | @@ -2830,3 +2830,52 @@ const EmitZIR = struct { |
| 2830 | 2830 | return decl; |
| 2831 | 2831 | } |
| 2832 | 2832 | }; |
| 2833 | |
| 2834 | /// For debugging purposes, like dumpFn but for unanalyzed zir blocks |
| 2835 | pub fn dumpZir(allocator: *Allocator, kind: []const u8, decl_name: [*:0]const u8, instructions: []*Inst) !void { |
| 2836 | var fib = std.heap.FixedBufferAllocator.init(&[_]u8{}); |
| 2837 | var module = Module{ |
| 2838 | .decls = &[_]*Decl{}, |
| 2839 | .arena = std.heap.ArenaAllocator.init(&fib.allocator), |
| 2840 | .metadata = std.AutoHashMap(*Inst, Module.MetaData).init(&fib.allocator), |
| 2841 | .body_metadata = std.AutoHashMap(*Module.Body, Module.BodyMetaData).init(&fib.allocator), |
| 2842 | }; |
| 2843 | var write = Writer{ |
| 2844 | .module = &module, |
| 2845 | .inst_table = InstPtrTable.init(allocator), |
| 2846 | .block_table = std.AutoHashMap(*Inst.Block, []const u8).init(allocator), |
| 2847 | .loop_table = std.AutoHashMap(*Inst.Loop, []const u8).init(allocator), |
| 2848 | .arena = std.heap.ArenaAllocator.init(allocator), |
| 2849 | .indent = 2, |
| 2850 | .next_instr_index = 0, |
| 2851 | }; |
| 2852 | defer write.arena.deinit(); |
| 2853 | defer write.inst_table.deinit(); |
| 2854 | defer write.block_table.deinit(); |
| 2855 | defer write.loop_table.deinit(); |
| 2856 | |
| 2857 | try write.inst_table.ensureCapacity(@intCast(u32, instructions.len)); |
| 2858 | |
| 2859 | const stderr = std.io.getStdErr().outStream(); |
| 2860 | try stderr.print("{} {s} {{ // unanalyzed\n", .{ kind, decl_name }); |
| 2861 | |
| 2862 | for (instructions) |inst| { |
| 2863 | const my_i = write.next_instr_index; |
| 2864 | write.next_instr_index += 1; |
| 2865 | |
| 2866 | if (inst.cast(Inst.Block)) |block| { |
| 2867 | const name = try std.fmt.allocPrint(&write.arena.allocator, "label_{}", .{my_i}); |
| 2868 | try write.block_table.put(block, name); |
| 2869 | } else if (inst.cast(Inst.Loop)) |loop| { |
| 2870 | const name = try std.fmt.allocPrint(&write.arena.allocator, "loop_{}", .{my_i}); |
| 2871 | try write.loop_table.put(loop, name); |
| 2872 | } |
| 2873 | |
| 2874 | try write.inst_table.putNoClobber(inst, .{ .inst = inst, .index = my_i, .name = "inst" }); |
| 2875 | try stderr.print(" %{} ", .{my_i}); |
| 2876 | try write.writeInstToStream(stderr, inst); |
| 2877 | try stderr.writeByte('\n'); |
| 2878 | } |
| 2879 | |
| 2880 | try stderr.print("}} // {} {s}\n\n", .{ kind, decl_name }); |
| 2881 | } |