| ... | ... | @@ -175,7 +175,12 @@ pub const Tree = struct { |
| 175 | 175 | } |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | | fn writeInstToStream(self: Tree, stream: var, decl: *Inst, inst_table: *const InstPtrTable) !void { |
| 178 | fn writeInstToStream( |
| 179 | self: Tree, |
| 180 | stream: var, |
| 181 | decl: *Inst, |
| 182 | inst_table: *const InstPtrTable, |
| 183 | ) @TypeOf(stream).Error!void { |
| 179 | 184 | // TODO I tried implementing this with an inline for loop and hit a compiler bug |
| 180 | 185 | switch (decl.tag) { |
| 181 | 186 | .constant => return self.writeInstToStreamGeneric(stream, .constant, decl, inst_table), |
| ... | ... | @@ -201,14 +206,16 @@ pub const Tree = struct { |
| 201 | 206 | if (@hasField(SpecificInst, "ty")) { |
| 202 | 207 | try stream.print(": {} ", .{inst.ty}); |
| 203 | 208 | } |
| 204 | | if (inst_tag == .constant) switch (inst.positionals.value.tag()) { |
| 205 | | .bytes => { |
| 209 | if (inst_tag == .constant) { |
| 210 | if (inst.positionals.value.cast(Value.Payload.Bytes)) |bytes_value| { |
| 206 | 211 | try stream.writeAll("= "); |
| 207 | | const bytes_value = inst.positionals.value.cast(Value.Payload.Bytes).?; |
| 208 | 212 | return std.zig.renderStringLiteral(bytes_value.data, stream); |
| 209 | | }, |
| 210 | | else => {}, |
| 211 | | }; |
| 213 | } else if (inst.positionals.value.cast(Value.Payload.Int_u64)) |v| { |
| 214 | return stream.print("= {}", .{v.int}); |
| 215 | } else if (inst.positionals.value.cast(Value.Payload.Int_i64)) |v| { |
| 216 | return stream.print("= {}", .{v.int}); |
| 217 | } |
| 218 | } |
| 212 | 219 | const Positionals = @TypeOf(inst.positionals); |
| 213 | 220 | try stream.writeAll("= " ++ @tagName(inst_tag) ++ "("); |
| 214 | 221 | inline for (@typeInfo(Positionals).Struct.fields) |arg_field, i| { |
| ... | ... | @@ -231,7 +238,13 @@ pub const Tree = struct { |
| 231 | 238 | try stream.print("{}{}", .{ prefix, info.index }); |
| 232 | 239 | }, |
| 233 | 240 | Inst.Fn.Body => { |
| 234 | | try stream.print("(fn body)", .{}); |
| 241 | try stream.writeAll("{\n"); |
| 242 | for (param.instructions) |inst, i| { |
| 243 | try stream.print(" %{} ", .{i}); |
| 244 | try self.writeInstToStream(stream, inst, inst_table); |
| 245 | try stream.writeByte('\n'); |
| 246 | } |
| 247 | try stream.writeByte('}'); |
| 235 | 248 | }, |
| 236 | 249 | else => |T| @compileError("unimplemented: rendering parameter of type " ++ @typeName(T)), |
| 237 | 250 | } |