| ... | ... | @@ -8,7 +8,7 @@ const Type = @import("../Type.zig"); |
| 8 | 8 | const Air = @import("../Air.zig"); |
| 9 | 9 | const InternPool = @import("../InternPool.zig"); |
| 10 | 10 | |
| 11 | | pub fn write(air: Air, stream: anytype, pt: Zcu.PerThread, liveness: ?Air.Liveness) void { |
| 11 | pub fn write(air: Air, stream: *std.io.BufferedWriter, pt: Zcu.PerThread, liveness: ?Air.Liveness) void { |
| 12 | 12 | comptime std.debug.assert(build_options.enable_debug_extensions); |
| 13 | 13 | const instruction_bytes = air.instructions.len * |
| 14 | 14 | // Here we don't use @sizeOf(Air.Inst.Data) because it would include |
| ... | ... | @@ -54,7 +54,7 @@ pub fn write(air: Air, stream: anytype, pt: Zcu.PerThread, liveness: ?Air.Livene |
| 54 | 54 | |
| 55 | 55 | pub fn writeInst( |
| 56 | 56 | air: Air, |
| 57 | | stream: anytype, |
| 57 | stream: *std.io.BufferedWriter, |
| 58 | 58 | inst: Air.Inst.Index, |
| 59 | 59 | pt: Zcu.PerThread, |
| 60 | 60 | liveness: ?Air.Liveness, |
| ... | ... | @@ -72,11 +72,15 @@ pub fn writeInst( |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | pub fn dump(air: Air, pt: Zcu.PerThread, liveness: ?Air.Liveness) void { |
| 75 | | air.write(std.io.getStdErr().writer(), pt, liveness); |
| 75 | var bw = std.debug.lockStdErr2(); |
| 76 | defer std.debug.unlockStdErr(); |
| 77 | air.write(&bw, pt, liveness); |
| 76 | 78 | } |
| 77 | 79 | |
| 78 | 80 | pub fn dumpInst(air: Air, inst: Air.Inst.Index, pt: Zcu.PerThread, liveness: ?Air.Liveness) void { |
| 79 | | air.writeInst(std.io.getStdErr().writer(), inst, pt, liveness); |
| 81 | var bw = std.debug.lockStdErr2(); |
| 82 | defer std.debug.unlockStdErr(); |
| 83 | air.writeInst(&bw, inst, pt, liveness); |
| 80 | 84 | } |
| 81 | 85 | |
| 82 | 86 | const Writer = struct { |
| ... | ... | @@ -87,16 +91,16 @@ const Writer = struct { |
| 87 | 91 | indent: usize, |
| 88 | 92 | skip_body: bool, |
| 89 | 93 | |
| 90 | | fn writeBody(w: *Writer, s: anytype, body: []const Air.Inst.Index) @TypeOf(s).Error!void { |
| 94 | fn writeBody(w: *Writer, s: *std.io.BufferedWriter, body: []const Air.Inst.Index) anyerror!void { |
| 91 | 95 | for (body) |inst| { |
| 92 | 96 | try w.writeInst(s, inst); |
| 93 | 97 | try s.writeByte('\n'); |
| 94 | 98 | } |
| 95 | 99 | } |
| 96 | 100 | |
| 97 | | fn writeInst(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 101 | fn writeInst(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void { |
| 98 | 102 | const tag = w.air.instructions.items(.tag)[@intFromEnum(inst)]; |
| 99 | | try s.writeByteNTimes(' ', w.indent); |
| 103 | try s.splatByteAll(' ', w.indent); |
| 100 | 104 | try s.print("{}{c}= {s}(", .{ |
| 101 | 105 | inst, |
| 102 | 106 | @as(u8, if (if (w.liveness) |liveness| liveness.isUnused(inst) else false) '!' else ' '), |
| ... | ... | @@ -334,47 +338,48 @@ const Writer = struct { |
| 334 | 338 | try s.writeByte(')'); |
| 335 | 339 | } |
| 336 | 340 | |
| 337 | | fn writeBinOp(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 341 | fn writeBinOp(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void { |
| 338 | 342 | const bin_op = w.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 339 | 343 | try w.writeOperand(s, inst, 0, bin_op.lhs); |
| 340 | 344 | try s.writeAll(", "); |
| 341 | 345 | try w.writeOperand(s, inst, 1, bin_op.rhs); |
| 342 | 346 | } |
| 343 | 347 | |
| 344 | | fn writeUnOp(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 348 | fn writeUnOp(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void { |
| 345 | 349 | const un_op = w.air.instructions.items(.data)[@intFromEnum(inst)].un_op; |
| 346 | 350 | try w.writeOperand(s, inst, 0, un_op); |
| 347 | 351 | } |
| 348 | 352 | |
| 349 | | fn writeNoOp(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 353 | fn writeNoOp(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void { |
| 350 | 354 | _ = w; |
| 355 | _ = s; |
| 351 | 356 | _ = inst; |
| 352 | 357 | // no-op, no argument to write |
| 353 | 358 | } |
| 354 | 359 | |
| 355 | | fn writeType(w: *Writer, s: anytype, ty: Type) !void { |
| 360 | fn writeType(w: *Writer, s: *std.io.BufferedWriter, ty: Type) !void { |
| 356 | 361 | return ty.print(s, w.pt); |
| 357 | 362 | } |
| 358 | 363 | |
| 359 | | fn writeTy(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 364 | fn writeTy(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void { |
| 360 | 365 | const ty = w.air.instructions.items(.data)[@intFromEnum(inst)].ty; |
| 361 | 366 | try w.writeType(s, ty); |
| 362 | 367 | } |
| 363 | 368 | |
| 364 | | fn writeArg(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 369 | fn writeArg(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void { |
| 365 | 370 | const arg = w.air.instructions.items(.data)[@intFromEnum(inst)].arg; |
| 366 | 371 | try w.writeType(s, arg.ty.toType()); |
| 367 | 372 | try s.print(", {d}", .{arg.zir_param_index}); |
| 368 | 373 | } |
| 369 | 374 | |
| 370 | | fn writeTyOp(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 375 | fn writeTyOp(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void { |
| 371 | 376 | const ty_op = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 372 | 377 | try w.writeType(s, ty_op.ty.toType()); |
| 373 | 378 | try s.writeAll(", "); |
| 374 | 379 | try w.writeOperand(s, inst, 0, ty_op.operand); |
| 375 | 380 | } |
| 376 | 381 | |
| 377 | | fn writeBlock(w: *Writer, s: anytype, tag: Air.Inst.Tag, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 382 | fn writeBlock(w: *Writer, s: *std.io.BufferedWriter, tag: Air.Inst.Tag, inst: Air.Inst.Index) anyerror!void { |
| 378 | 383 | const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 379 | 384 | try w.writeType(s, ty_pl.ty.toType()); |
| 380 | 385 | const body: []const Air.Inst.Index = @ptrCast(switch (tag) { |
| ... | ... | @@ -407,7 +412,7 @@ const Writer = struct { |
| 407 | 412 | w.indent += 2; |
| 408 | 413 | try w.writeBody(s, body); |
| 409 | 414 | w.indent = old_indent; |
| 410 | | try s.writeByteNTimes(' ', w.indent); |
| 415 | try s.splatByteAll(' ', w.indent); |
| 411 | 416 | try s.writeAll("}"); |
| 412 | 417 | |
| 413 | 418 | for (liveness_block.deaths) |operand| { |
| ... | ... | @@ -415,7 +420,7 @@ const Writer = struct { |
| 415 | 420 | } |
| 416 | 421 | } |
| 417 | 422 | |
| 418 | | fn writeLoop(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 423 | fn writeLoop(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void { |
| 419 | 424 | const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 420 | 425 | const extra = w.air.extraData(Air.Block, ty_pl.payload); |
| 421 | 426 | const body: []const Air.Inst.Index = @ptrCast(w.air.extra.items[extra.end..][0..extra.data.body_len]); |
| ... | ... | @@ -427,11 +432,11 @@ const Writer = struct { |
| 427 | 432 | w.indent += 2; |
| 428 | 433 | try w.writeBody(s, body); |
| 429 | 434 | w.indent = old_indent; |
| 430 | | try s.writeByteNTimes(' ', w.indent); |
| 435 | try s.splatByteAll(' ', w.indent); |
| 431 | 436 | try s.writeAll("}"); |
| 432 | 437 | } |
| 433 | 438 | |
| 434 | | fn writeAggregateInit(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 439 | fn writeAggregateInit(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void { |
| 435 | 440 | const zcu = w.pt.zcu; |
| 436 | 441 | const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 437 | 442 | const vector_ty = ty_pl.ty.toType(); |
| ... | ... | @@ -447,7 +452,7 @@ const Writer = struct { |
| 447 | 452 | try s.writeAll("]"); |
| 448 | 453 | } |
| 449 | 454 | |
| 450 | | fn writeUnionInit(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 455 | fn writeUnionInit(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void { |
| 451 | 456 | const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 452 | 457 | const extra = w.air.extraData(Air.UnionInit, ty_pl.payload).data; |
| 453 | 458 | |
| ... | ... | @@ -455,7 +460,7 @@ const Writer = struct { |
| 455 | 460 | try w.writeOperand(s, inst, 0, extra.init); |
| 456 | 461 | } |
| 457 | 462 | |
| 458 | | fn writeStructField(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 463 | fn writeStructField(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void { |
| 459 | 464 | const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 460 | 465 | const extra = w.air.extraData(Air.StructField, ty_pl.payload).data; |
| 461 | 466 | |
| ... | ... | @@ -463,7 +468,7 @@ const Writer = struct { |
| 463 | 468 | try s.print(", {d}", .{extra.field_index}); |
| 464 | 469 | } |
| 465 | 470 | |
| 466 | | fn writeTyPlBin(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 471 | fn writeTyPlBin(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void { |
| 467 | 472 | const data = w.air.instructions.items(.data); |
| 468 | 473 | const ty_pl = data[@intFromEnum(inst)].ty_pl; |
| 469 | 474 | const extra = w.air.extraData(Air.Bin, ty_pl.payload).data; |
| ... | ... | @@ -476,7 +481,7 @@ const Writer = struct { |
| 476 | 481 | try w.writeOperand(s, inst, 1, extra.rhs); |
| 477 | 482 | } |
| 478 | 483 | |
| 479 | | fn writeCmpxchg(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 484 | fn writeCmpxchg(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void { |
| 480 | 485 | const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 481 | 486 | const extra = w.air.extraData(Air.Cmpxchg, ty_pl.payload).data; |
| 482 | 487 | |
| ... | ... | @@ -490,7 +495,7 @@ const Writer = struct { |
| 490 | 495 | }); |
| 491 | 496 | } |
| 492 | 497 | |
| 493 | | fn writeMulAdd(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 498 | fn writeMulAdd(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void { |
| 494 | 499 | const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 495 | 500 | const extra = w.air.extraData(Air.Bin, pl_op.payload).data; |
| 496 | 501 | |
| ... | ... | @@ -501,7 +506,7 @@ const Writer = struct { |
| 501 | 506 | try w.writeOperand(s, inst, 2, pl_op.operand); |
| 502 | 507 | } |
| 503 | 508 | |
| 504 | | fn writeShuffleOne(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 509 | fn writeShuffleOne(w: *Writer, s: anytype, inst: Air.Inst.Index) anyerror!void { |
| 505 | 510 | const unwrapped = w.air.unwrapShuffleOne(w.pt.zcu, inst); |
| 506 | 511 | try w.writeType(s, unwrapped.result_ty); |
| 507 | 512 | try s.writeAll(", "); |
| ... | ... | @@ -536,7 +541,7 @@ const Writer = struct { |
| 536 | 541 | try s.writeByte(']'); |
| 537 | 542 | } |
| 538 | 543 | |
| 539 | | fn writeSelect(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 544 | fn writeSelect(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void { |
| 540 | 545 | const zcu = w.pt.zcu; |
| 541 | 546 | const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 542 | 547 | const extra = w.air.extraData(Air.Bin, pl_op.payload).data; |
| ... | ... | @@ -551,14 +556,14 @@ const Writer = struct { |
| 551 | 556 | try w.writeOperand(s, inst, 2, extra.rhs); |
| 552 | 557 | } |
| 553 | 558 | |
| 554 | | fn writeReduce(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 559 | fn writeReduce(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void { |
| 555 | 560 | const reduce = w.air.instructions.items(.data)[@intFromEnum(inst)].reduce; |
| 556 | 561 | |
| 557 | 562 | try w.writeOperand(s, inst, 0, reduce.operand); |
| 558 | 563 | try s.print(", {s}", .{@tagName(reduce.operation)}); |
| 559 | 564 | } |
| 560 | 565 | |
| 561 | | fn writeCmpVector(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 566 | fn writeCmpVector(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void { |
| 562 | 567 | const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 563 | 568 | const extra = w.air.extraData(Air.VectorCmp, ty_pl.payload).data; |
| 564 | 569 | |
| ... | ... | @@ -568,7 +573,7 @@ const Writer = struct { |
| 568 | 573 | try w.writeOperand(s, inst, 1, extra.rhs); |
| 569 | 574 | } |
| 570 | 575 | |
| 571 | | fn writeVectorStoreElem(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 576 | fn writeVectorStoreElem(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void { |
| 572 | 577 | const data = w.air.instructions.items(.data)[@intFromEnum(inst)].vector_store_elem; |
| 573 | 578 | const extra = w.air.extraData(Air.VectorCmp, data.payload).data; |
| 574 | 579 | |
| ... | ... | @@ -579,21 +584,21 @@ const Writer = struct { |
| 579 | 584 | try w.writeOperand(s, inst, 2, extra.rhs); |
| 580 | 585 | } |
| 581 | 586 | |
| 582 | | fn writeRuntimeNavPtr(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 587 | fn writeRuntimeNavPtr(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) std.io.Writer.Error!void { |
| 583 | 588 | const ip = &w.pt.zcu.intern_pool; |
| 584 | 589 | const ty_nav = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_nav; |
| 585 | 590 | try w.writeType(s, .fromInterned(ty_nav.ty)); |
| 586 | 591 | try s.print(", '{}'", .{ip.getNav(ty_nav.nav).fqn.fmt(ip)}); |
| 587 | 592 | } |
| 588 | 593 | |
| 589 | | fn writeAtomicLoad(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 594 | fn writeAtomicLoad(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) std.io.Writer.Error!void { |
| 590 | 595 | const atomic_load = w.air.instructions.items(.data)[@intFromEnum(inst)].atomic_load; |
| 591 | 596 | |
| 592 | 597 | try w.writeOperand(s, inst, 0, atomic_load.ptr); |
| 593 | 598 | try s.print(", {s}", .{@tagName(atomic_load.order)}); |
| 594 | 599 | } |
| 595 | 600 | |
| 596 | | fn writePrefetch(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 601 | fn writePrefetch(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void { |
| 597 | 602 | const prefetch = w.air.instructions.items(.data)[@intFromEnum(inst)].prefetch; |
| 598 | 603 | |
| 599 | 604 | try w.writeOperand(s, inst, 0, prefetch.ptr); |
| ... | ... | @@ -604,10 +609,10 @@ const Writer = struct { |
| 604 | 609 | |
| 605 | 610 | fn writeAtomicStore( |
| 606 | 611 | w: *Writer, |
| 607 | | s: anytype, |
| 612 | s: *std.io.BufferedWriter, |
| 608 | 613 | inst: Air.Inst.Index, |
| 609 | 614 | order: std.builtin.AtomicOrder, |
| 610 | | ) @TypeOf(s).Error!void { |
| 615 | ) anyerror!void { |
| 611 | 616 | const bin_op = w.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 612 | 617 | try w.writeOperand(s, inst, 0, bin_op.lhs); |
| 613 | 618 | try s.writeAll(", "); |
| ... | ... | @@ -615,7 +620,7 @@ const Writer = struct { |
| 615 | 620 | try s.print(", {s}", .{@tagName(order)}); |
| 616 | 621 | } |
| 617 | 622 | |
| 618 | | fn writeAtomicRmw(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 623 | fn writeAtomicRmw(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void { |
| 619 | 624 | const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 620 | 625 | const extra = w.air.extraData(Air.AtomicRmw, pl_op.payload).data; |
| 621 | 626 | |
| ... | ... | @@ -625,7 +630,7 @@ const Writer = struct { |
| 625 | 630 | try s.print(", {s}, {s}", .{ @tagName(extra.op()), @tagName(extra.ordering()) }); |
| 626 | 631 | } |
| 627 | 632 | |
| 628 | | fn writeFieldParentPtr(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 633 | fn writeFieldParentPtr(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void { |
| 629 | 634 | const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 630 | 635 | const extra = w.air.extraData(Air.FieldParentPtr, ty_pl.payload).data; |
| 631 | 636 | |
| ... | ... | @@ -633,7 +638,7 @@ const Writer = struct { |
| 633 | 638 | try s.print(", {d}", .{extra.field_index}); |
| 634 | 639 | } |
| 635 | 640 | |
| 636 | | fn writeAssembly(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 641 | fn writeAssembly(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void { |
| 637 | 642 | const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 638 | 643 | const extra = w.air.extraData(Air.Asm, ty_pl.payload); |
| 639 | 644 | const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0; |
| ... | ... | @@ -706,19 +711,19 @@ const Writer = struct { |
| 706 | 711 | try s.print(", \"{}\"", .{std.zig.fmtEscapes(asm_source)}); |
| 707 | 712 | } |
| 708 | 713 | |
| 709 | | fn writeDbgStmt(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 714 | fn writeDbgStmt(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void { |
| 710 | 715 | const dbg_stmt = w.air.instructions.items(.data)[@intFromEnum(inst)].dbg_stmt; |
| 711 | 716 | try s.print("{d}:{d}", .{ dbg_stmt.line + 1, dbg_stmt.column + 1 }); |
| 712 | 717 | } |
| 713 | 718 | |
| 714 | | fn writeDbgVar(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 719 | fn writeDbgVar(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void { |
| 715 | 720 | const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 716 | 721 | try w.writeOperand(s, inst, 0, pl_op.operand); |
| 717 | 722 | const name: Air.NullTerminatedString = @enumFromInt(pl_op.payload); |
| 718 | 723 | try s.print(", \"{}\"", .{std.zig.fmtEscapes(name.toSlice(w.air))}); |
| 719 | 724 | } |
| 720 | 725 | |
| 721 | | fn writeCall(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 726 | fn writeCall(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void { |
| 722 | 727 | const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 723 | 728 | const extra = w.air.extraData(Air.Call, pl_op.payload); |
| 724 | 729 | const args = @as([]const Air.Inst.Ref, @ptrCast(w.air.extra.items[extra.end..][0..extra.data.args_len])); |
| ... | ... | @@ -731,19 +736,19 @@ const Writer = struct { |
| 731 | 736 | try s.writeAll("]"); |
| 732 | 737 | } |
| 733 | 738 | |
| 734 | | fn writeBr(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 739 | fn writeBr(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void { |
| 735 | 740 | const br = w.air.instructions.items(.data)[@intFromEnum(inst)].br; |
| 736 | 741 | try w.writeInstIndex(s, br.block_inst, false); |
| 737 | 742 | try s.writeAll(", "); |
| 738 | 743 | try w.writeOperand(s, inst, 0, br.operand); |
| 739 | 744 | } |
| 740 | 745 | |
| 741 | | fn writeRepeat(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 746 | fn writeRepeat(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void { |
| 742 | 747 | const repeat = w.air.instructions.items(.data)[@intFromEnum(inst)].repeat; |
| 743 | 748 | try w.writeInstIndex(s, repeat.loop_inst, false); |
| 744 | 749 | } |
| 745 | 750 | |
| 746 | | fn writeTry(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 751 | fn writeTry(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void { |
| 747 | 752 | const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 748 | 753 | const extra = w.air.extraData(Air.Try, pl_op.payload); |
| 749 | 754 | const body: []const Air.Inst.Index = @ptrCast(w.air.extra.items[extra.end..][0..extra.data.body_len]); |
| ... | ... | @@ -759,7 +764,7 @@ const Writer = struct { |
| 759 | 764 | w.indent += 2; |
| 760 | 765 | |
| 761 | 766 | if (liveness_condbr.else_deaths.len != 0) { |
| 762 | | try s.writeByteNTimes(' ', w.indent); |
| 767 | try s.splatByteAll(' ', w.indent); |
| 763 | 768 | for (liveness_condbr.else_deaths, 0..) |operand, i| { |
| 764 | 769 | if (i != 0) try s.writeAll(" "); |
| 765 | 770 | try s.print("{}!", .{operand}); |
| ... | ... | @@ -769,7 +774,7 @@ const Writer = struct { |
| 769 | 774 | try w.writeBody(s, body); |
| 770 | 775 | |
| 771 | 776 | w.indent = old_indent; |
| 772 | | try s.writeByteNTimes(' ', w.indent); |
| 777 | try s.splatByteAll(' ', w.indent); |
| 773 | 778 | try s.writeAll("}"); |
| 774 | 779 | |
| 775 | 780 | for (liveness_condbr.then_deaths) |operand| { |
| ... | ... | @@ -777,7 +782,7 @@ const Writer = struct { |
| 777 | 782 | } |
| 778 | 783 | } |
| 779 | 784 | |
| 780 | | fn writeTryPtr(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 785 | fn writeTryPtr(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void { |
| 781 | 786 | const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 782 | 787 | const extra = w.air.extraData(Air.TryPtr, ty_pl.payload); |
| 783 | 788 | const body: []const Air.Inst.Index = @ptrCast(w.air.extra.items[extra.end..][0..extra.data.body_len]); |
| ... | ... | @@ -796,7 +801,7 @@ const Writer = struct { |
| 796 | 801 | w.indent += 2; |
| 797 | 802 | |
| 798 | 803 | if (liveness_condbr.else_deaths.len != 0) { |
| 799 | | try s.writeByteNTimes(' ', w.indent); |
| 804 | try s.splatByteAll(' ', w.indent); |
| 800 | 805 | for (liveness_condbr.else_deaths, 0..) |operand, i| { |
| 801 | 806 | if (i != 0) try s.writeAll(" "); |
| 802 | 807 | try s.print("{}!", .{operand}); |
| ... | ... | @@ -806,7 +811,7 @@ const Writer = struct { |
| 806 | 811 | try w.writeBody(s, body); |
| 807 | 812 | |
| 808 | 813 | w.indent = old_indent; |
| 809 | | try s.writeByteNTimes(' ', w.indent); |
| 814 | try s.splatByteAll(' ', w.indent); |
| 810 | 815 | try s.writeAll("}"); |
| 811 | 816 | |
| 812 | 817 | for (liveness_condbr.then_deaths) |operand| { |
| ... | ... | @@ -814,7 +819,7 @@ const Writer = struct { |
| 814 | 819 | } |
| 815 | 820 | } |
| 816 | 821 | |
| 817 | | fn writeCondBr(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 822 | fn writeCondBr(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void { |
| 818 | 823 | const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 819 | 824 | const extra = w.air.extraData(Air.CondBr, pl_op.payload); |
| 820 | 825 | const then_body: []const Air.Inst.Index = @ptrCast(w.air.extra.items[extra.end..][0..extra.data.then_body_len]); |
| ... | ... | @@ -838,7 +843,7 @@ const Writer = struct { |
| 838 | 843 | w.indent += 2; |
| 839 | 844 | |
| 840 | 845 | if (liveness_condbr.then_deaths.len != 0) { |
| 841 | | try s.writeByteNTimes(' ', w.indent); |
| 846 | try s.splatByteAll(' ', w.indent); |
| 842 | 847 | for (liveness_condbr.then_deaths, 0..) |operand, i| { |
| 843 | 848 | if (i != 0) try s.writeAll(" "); |
| 844 | 849 | try s.print("{}!", .{operand}); |
| ... | ... | @@ -847,7 +852,7 @@ const Writer = struct { |
| 847 | 852 | } |
| 848 | 853 | |
| 849 | 854 | try w.writeBody(s, then_body); |
| 850 | | try s.writeByteNTimes(' ', old_indent); |
| 855 | try s.splatByteAll(' ', old_indent); |
| 851 | 856 | try s.writeAll("},"); |
| 852 | 857 | if (extra.data.branch_hints.false != .none) { |
| 853 | 858 | try s.print(" {s}", .{@tagName(extra.data.branch_hints.false)}); |
| ... | ... | @@ -858,7 +863,7 @@ const Writer = struct { |
| 858 | 863 | try s.writeAll(" {\n"); |
| 859 | 864 | |
| 860 | 865 | if (liveness_condbr.else_deaths.len != 0) { |
| 861 | | try s.writeByteNTimes(' ', w.indent); |
| 866 | try s.splatByteAll(' ', w.indent); |
| 862 | 867 | for (liveness_condbr.else_deaths, 0..) |operand, i| { |
| 863 | 868 | if (i != 0) try s.writeAll(" "); |
| 864 | 869 | try s.print("{}!", .{operand}); |
| ... | ... | @@ -869,11 +874,11 @@ const Writer = struct { |
| 869 | 874 | try w.writeBody(s, else_body); |
| 870 | 875 | w.indent = old_indent; |
| 871 | 876 | |
| 872 | | try s.writeByteNTimes(' ', old_indent); |
| 877 | try s.splatByteAll(' ', old_indent); |
| 873 | 878 | try s.writeAll("}"); |
| 874 | 879 | } |
| 875 | 880 | |
| 876 | | fn writeSwitchBr(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 881 | fn writeSwitchBr(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void { |
| 877 | 882 | const switch_br = w.air.unwrapSwitch(inst); |
| 878 | 883 | |
| 879 | 884 | const liveness: Air.Liveness.SwitchBrTable = if (w.liveness) |liveness| |
| ... | ... | @@ -915,7 +920,7 @@ const Writer = struct { |
| 915 | 920 | |
| 916 | 921 | const deaths = liveness.deaths[case.idx]; |
| 917 | 922 | if (deaths.len != 0) { |
| 918 | | try s.writeByteNTimes(' ', w.indent); |
| 923 | try s.splatByteAll(' ', w.indent); |
| 919 | 924 | for (deaths, 0..) |operand, i| { |
| 920 | 925 | if (i != 0) try s.writeAll(" "); |
| 921 | 926 | try s.print("{}!", .{operand}); |
| ... | ... | @@ -925,7 +930,7 @@ const Writer = struct { |
| 925 | 930 | |
| 926 | 931 | try w.writeBody(s, case.body); |
| 927 | 932 | w.indent -= 2; |
| 928 | | try s.writeByteNTimes(' ', w.indent); |
| 933 | try s.splatByteAll(' ', w.indent); |
| 929 | 934 | try s.writeAll("}"); |
| 930 | 935 | } |
| 931 | 936 | |
| ... | ... | @@ -941,7 +946,7 @@ const Writer = struct { |
| 941 | 946 | |
| 942 | 947 | const deaths = liveness.deaths[liveness.deaths.len - 1]; |
| 943 | 948 | if (deaths.len != 0) { |
| 944 | | try s.writeByteNTimes(' ', w.indent); |
| 949 | try s.splatByteAll(' ', w.indent); |
| 945 | 950 | for (deaths, 0..) |operand, i| { |
| 946 | 951 | if (i != 0) try s.writeAll(" "); |
| 947 | 952 | try s.print("{}!", .{operand}); |
| ... | ... | @@ -951,37 +956,37 @@ const Writer = struct { |
| 951 | 956 | |
| 952 | 957 | try w.writeBody(s, else_body); |
| 953 | 958 | w.indent -= 2; |
| 954 | | try s.writeByteNTimes(' ', w.indent); |
| 959 | try s.splatByteAll(' ', w.indent); |
| 955 | 960 | try s.writeAll("}"); |
| 956 | 961 | } |
| 957 | 962 | |
| 958 | 963 | try s.writeAll("\n"); |
| 959 | | try s.writeByteNTimes(' ', old_indent); |
| 964 | try s.splatByteAll(' ', old_indent); |
| 960 | 965 | } |
| 961 | 966 | |
| 962 | | fn writeWasmMemorySize(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 967 | fn writeWasmMemorySize(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void { |
| 963 | 968 | const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 964 | 969 | try s.print("{d}", .{pl_op.payload}); |
| 965 | 970 | } |
| 966 | 971 | |
| 967 | | fn writeWasmMemoryGrow(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 972 | fn writeWasmMemoryGrow(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void { |
| 968 | 973 | const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 969 | 974 | try s.print("{d}, ", .{pl_op.payload}); |
| 970 | 975 | try w.writeOperand(s, inst, 0, pl_op.operand); |
| 971 | 976 | } |
| 972 | 977 | |
| 973 | | fn writeWorkDimension(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { |
| 978 | fn writeWorkDimension(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void { |
| 974 | 979 | const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 975 | 980 | try s.print("{d}", .{pl_op.payload}); |
| 976 | 981 | } |
| 977 | 982 | |
| 978 | 983 | fn writeOperand( |
| 979 | 984 | w: *Writer, |
| 980 | | s: anytype, |
| 985 | s: *std.io.BufferedWriter, |
| 981 | 986 | inst: Air.Inst.Index, |
| 982 | 987 | op_index: usize, |
| 983 | 988 | operand: Air.Inst.Ref, |
| 984 | | ) @TypeOf(s).Error!void { |
| 989 | ) anyerror!void { |
| 985 | 990 | const small_tomb_bits = Air.Liveness.bpi - 1; |
| 986 | 991 | const dies = if (w.liveness) |liveness| blk: { |
| 987 | 992 | if (op_index < small_tomb_bits) |
| ... | ... | @@ -1006,7 +1011,7 @@ const Writer = struct { |
| 1006 | 1011 | s: anytype, |
| 1007 | 1012 | operand: Air.Inst.Ref, |
| 1008 | 1013 | dies: bool, |
| 1009 | | ) @TypeOf(s).Error!void { |
| 1014 | ) anyerror!void { |
| 1010 | 1015 | if (@intFromEnum(operand) < InternPool.static_len) { |
| 1011 | 1016 | return s.print("@{}", .{operand}); |
| 1012 | 1017 | } else if (operand.toInterned()) |ip_index| { |
| ... | ... | @@ -1023,10 +1028,10 @@ const Writer = struct { |
| 1023 | 1028 | |
| 1024 | 1029 | fn writeInstIndex( |
| 1025 | 1030 | w: *Writer, |
| 1026 | | s: anytype, |
| 1031 | s: *std.io.BufferedWriter, |
| 1027 | 1032 | inst: Air.Inst.Index, |
| 1028 | 1033 | dies: bool, |
| 1029 | | ) @TypeOf(s).Error!void { |
| 1034 | ) anyerror!void { |
| 1030 | 1035 | _ = w; |
| 1031 | 1036 | try s.print("{}", .{inst}); |
| 1032 | 1037 | if (dies) try s.writeByte('!'); |