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 {...@@ -182,21 +182,22 @@ const Writer = struct {
182 }182 }
183183
184 fn writeBinOp(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {184 fn writeBinOp(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
185 _ = w;185 const bin_op = w.air.instructions.items(.data)[inst].bin_op;
186 _ = inst;186 try w.writeInstRef(s, bin_op.lhs);
187 try s.writeAll("TODO");187 try s.writeAll(", ");
188 try w.writeInstRef(s, bin_op.rhs);
188 }189 }
189190
190 fn writeUnOp(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {191 fn writeUnOp(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
191 _ = w;192 const un_op = w.air.instructions.items(.data)[inst].un_op;
192 _ = inst;193 try w.writeInstRef(s, un_op);
193 try s.writeAll("TODO");
194 }194 }
195195
196 fn writeNoOp(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {196 fn writeNoOp(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
197 _ = w;197 _ = w;
198 _ = inst;198 _ = inst;
199 try s.writeAll("TODO");199 _ = s;
200 // no-op, no argument to write
200 }201 }
201202
202 fn writeTy(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {203 fn writeTy(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
...@@ -205,21 +206,31 @@ const Writer = struct {...@@ -205,21 +206,31 @@ const Writer = struct {
205 }206 }
206207
207 fn writeTyOp(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {208 fn writeTyOp(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
208 _ = w;209 const ty_op = w.air.instructions.items(.data)[inst].ty_op;
209 _ = inst;210 try s.print("{}, ", .{w.air.getRefType(ty_op.ty)});
210 try s.writeAll("TODO");211 try w.writeInstRef(s, ty_op.operand);
211 }212 }
212213
213 fn writeBlock(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {214 fn writeBlock(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
214 _ = w;215 const ty_pl = w.air.instructions.items(.data)[inst].ty_pl;
215 _ = inst;216 const extra = w.air.extraData(Air.Block, ty_pl.payload);
216 try s.writeAll("TODO");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("}");
217 }226 }
218227
219 fn writeStructFieldPtr(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {228 fn writeStructFieldPtr(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
220 _ = w;229 const ty_pl = w.air.instructions.items(.data)[inst].ty_pl;
221 _ = inst;230 const extra = w.air.extraData(Air.StructField, ty_pl.payload);
222 try s.writeAll("TODO");231
232 try w.writeInstRef(s, extra.data.struct_ptr);
233 try s.print(", {d}", .{extra.data.field_index});
223 }234 }
224235
225 fn writeVarPtr(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {236 fn writeVarPtr(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
...@@ -231,7 +242,7 @@ const Writer = struct {...@@ -231,7 +242,7 @@ const Writer = struct {
231 fn writeConstant(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {242 fn writeConstant(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
232 const ty_pl = w.air.instructions.items(.data)[inst].ty_pl;243 const ty_pl = w.air.instructions.items(.data)[inst].ty_pl;
233 const val = w.air.values[ty_pl.payload];244 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 });
235 }246 }
236247
237 fn writeAssembly(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {248 fn writeAssembly(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
...@@ -259,15 +270,32 @@ const Writer = struct {...@@ -259,15 +270,32 @@ const Writer = struct {
259 }270 }
260271
261 fn writeBr(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {272 fn writeBr(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
262 _ = w;273 const br = w.air.instructions.items(.data)[inst].br;
263 _ = inst;274 try w.writeInstIndex(s, br.block_inst);
264 try s.writeAll("TODO");275 try s.writeAll(", ");
276 try w.writeInstRef(s, br.operand);
265 }277 }
266278
267 fn writeCondBr(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {279 fn writeCondBr(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
268 _ = w;280 const pl_op = w.air.instructions.items(.data)[inst].pl_op;
269 _ = inst;281 const extra = w.air.extraData(Air.CondBr, pl_op.payload);
270 try s.writeAll("TODO");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("}");
271 }299 }
272300
273 fn writeSwitchBr(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {301 fn writeSwitchBr(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {