authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-04-19 23:39:34-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-04-19 23:39:34-04:00
logf7786d0ca822baee75b2d9fd2f3ef4f24421b2a9
tree7ce5a9ef3020df7ee6e820456967ce999f40abc0
parente74c5a7c244d26906a371d8d635a05d68f59ac3c

ir: render function body


1 files changed, 21 insertions(+), 8 deletions(-)

src-self-hosted/ir.zig+21-8
......@@ -175,7 +175,12 @@ pub const Tree = struct {
175175 }
176176 }
177177
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 {
179184 // TODO I tried implementing this with an inline for loop and hit a compiler bug
180185 switch (decl.tag) {
181186 .constant => return self.writeInstToStreamGeneric(stream, .constant, decl, inst_table),
......@@ -201,14 +206,16 @@ pub const Tree = struct {
201206 if (@hasField(SpecificInst, "ty")) {
202207 try stream.print(": {} ", .{inst.ty});
203208 }
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| {
206211 try stream.writeAll("= ");
207 const bytes_value = inst.positionals.value.cast(Value.Payload.Bytes).?;
208212 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 }
212219 const Positionals = @TypeOf(inst.positionals);
213220 try stream.writeAll("= " ++ @tagName(inst_tag) ++ "(");
214221 inline for (@typeInfo(Positionals).Struct.fields) |arg_field, i| {
......@@ -231,7 +238,13 @@ pub const Tree = struct {
231238 try stream.print("{}{}", .{ prefix, info.index });
232239 },
233240 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('}');
235248 },
236249 else => |T| @compileError("unimplemented: rendering parameter of type " ++ @typeName(T)),
237250 }