authorgravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2021-07-18 16:53:21+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-07-20 12:19:16-07:00
log480242b78a5018bbe28824eb3549bfa86126a6e8
tree7dc02c646ae10af6e5586b9ab24ddc5a394b3a0f
parent44fe9c52e15deb1a1ea82760c5f4204d50fb0e9f

Debug info - Implement more instructions:

- bin_op - un_op - block - struct_field_ptr - br - condbr Also updates constant to write the actual Type, rather than the enum tag of the `Ref`.

1 files changed, 51 insertions(+), 23 deletions(-)

src/print_air.zig+51-23
......@@ -182,21 +182,22 @@ const Writer = struct {
182182 }
183183
184184 fn writeBinOp(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
185 _ = w;
186 _ = inst;
187 try s.writeAll("TODO");
185 const bin_op = w.air.instructions.items(.data)[inst].bin_op;
186 try w.writeInstRef(s, bin_op.lhs);
187 try s.writeAll(", ");
188 try w.writeInstRef(s, bin_op.rhs);
188189 }
189190
190191 fn writeUnOp(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
191 _ = w;
192 _ = inst;
193 try s.writeAll("TODO");
192 const un_op = w.air.instructions.items(.data)[inst].un_op;
193 try w.writeInstRef(s, un_op);
194194 }
195195
196196 fn writeNoOp(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
197197 _ = w;
198198 _ = inst;
199 try s.writeAll("TODO");
199 _ = s;
200 // no-op, no argument to write
200201 }
201202
202203 fn writeTy(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
......@@ -205,21 +206,31 @@ const Writer = struct {
205206 }
206207
207208 fn writeTyOp(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
208 _ = w;
209 _ = inst;
210 try s.writeAll("TODO");
209 const ty_op = w.air.instructions.items(.data)[inst].ty_op;
210 try s.print("{}, ", .{w.air.getRefType(ty_op.ty)});
211 try w.writeInstRef(s, ty_op.operand);
211212 }
212213
213214 fn writeBlock(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
214 _ = w;
215 _ = inst;
216 try s.writeAll("TODO");
215 const ty_pl = w.air.instructions.items(.data)[inst].ty_pl;
216 const extra = w.air.extraData(Air.Block, ty_pl.payload);
217 const body = w.air.extra[extra.end..][0..extra.data.body_len];
218
219 try s.writeAll("{\n");
220 const old_indent = w.indent;
221 w.indent += 2;
222 try w.writeBody(s, body);
223 w.indent = old_indent;
224 try s.writeByteNTimes(' ', w.indent);
225 try s.writeAll("}");
217226 }
218227
219228 fn writeStructFieldPtr(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
220 _ = w;
221 _ = inst;
222 try s.writeAll("TODO");
229 const ty_pl = w.air.instructions.items(.data)[inst].ty_pl;
230 const extra = w.air.extraData(Air.StructField, ty_pl.payload);
231
232 try w.writeInstRef(s, extra.data.struct_ptr);
233 try s.print(", {d}", .{extra.data.field_index});
223234 }
224235
225236 fn writeVarPtr(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
......@@ -231,7 +242,7 @@ const Writer = struct {
231242 fn writeConstant(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
232243 const ty_pl = w.air.instructions.items(.data)[inst].ty_pl;
233244 const val = w.air.values[ty_pl.payload];
234 try s.print("{}, {}", .{ ty_pl.ty, val });
245 try s.print("{}, {}", .{ w.air.getRefType(ty_pl.ty), val });
235246 }
236247
237248 fn writeAssembly(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
......@@ -259,15 +270,32 @@ const Writer = struct {
259270 }
260271
261272 fn writeBr(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
262 _ = w;
263 _ = inst;
264 try s.writeAll("TODO");
273 const br = w.air.instructions.items(.data)[inst].br;
274 try w.writeInstIndex(s, br.block_inst);
275 try s.writeAll(", ");
276 try w.writeInstRef(s, br.operand);
265277 }
266278
267279 fn writeCondBr(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
268 _ = w;
269 _ = inst;
270 try s.writeAll("TODO");
280 const pl_op = w.air.instructions.items(.data)[inst].pl_op;
281 const extra = w.air.extraData(Air.CondBr, pl_op.payload);
282 const then_body = w.air.extra[extra.end..][0..extra.data.then_body_len];
283 const else_body = w.air.extra[extra.end + then_body.len ..][0..extra.data.else_body_len];
284
285 try w.writeInstRef(s, pl_op.operand);
286 try s.writeAll(", {\n");
287 const old_indent = w.indent;
288 w.indent += 2;
289
290 try w.writeBody(s, then_body);
291 try s.writeByteNTimes(' ', old_indent);
292 try s.writeAll("}, {\n");
293
294 try w.writeBody(s, else_body);
295 w.indent = old_indent;
296
297 try s.writeByteNTimes(' ', old_indent);
298 try s.writeAll("}");
271299 }
272300
273301 fn writeSwitchBr(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {