authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-03-20 17:09:06-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-03-20 17:09:06-07:00
log50010447bde42ca96aff63e0a620f941464f2eae
tree620e963139761ede5900e91f7ebbbe4373a7b864
parent907142a03627f170ef1e721e996a8759952fb58f

astgen: implement function calls


4 files changed, 96 insertions(+), 46 deletions(-)

src/Module.zig+68-28
...@@ -237,12 +237,20 @@ pub const Decl = struct {...@@ -237,12 +237,20 @@ pub const Decl = struct {
237 }237 }
238 }238 }
239239
240 pub fn tokSrcLoc(decl: *Decl, token_index: ast.TokenIndex) LazySrcLoc {240 pub fn relativeToNodeIndex(decl: Decl, offset: i32) ast.Node.Index {
241 return @bitCast(ast.Node.Index, offset + @bitCast(i32, decl.srcNode()));
242 }
243
244 pub fn nodeIndexToRelative(decl: Decl, node_index: ast.Node.Index) i32 {
245 return @bitCast(i32, node_index) - @bitCast(i32, decl.srcNode());
246 }
247
248 pub fn tokSrcLoc(decl: Decl, token_index: ast.TokenIndex) LazySrcLoc {
241 return .{ .token_offset = token_index - decl.srcToken() };249 return .{ .token_offset = token_index - decl.srcToken() };
242 }250 }
243251
244 pub fn nodeSrcLoc(decl: *Decl, node_index: ast.Node.Index) LazySrcLoc {252 pub fn nodeSrcLoc(decl: Decl, node_index: ast.Node.Index) LazySrcLoc {
245 return .{ .node_offset = node_index - decl.srcNode() };253 return .{ .node_offset = decl.nodeIndexToRelative(node_index) };
246 }254 }
247255
248 pub fn srcLoc(decl: *Decl) SrcLoc {256 pub fn srcLoc(decl: *Decl) SrcLoc {
...@@ -1076,6 +1084,40 @@ pub const Scope = struct {...@@ -1076,6 +1084,40 @@ pub const Scope = struct {
1076 return new_index + gz.zir_code.ref_start_index;1084 return new_index + gz.zir_code.ref_start_index;
1077 }1085 }
10781086
1087 pub fn addCall(
1088 gz: *GenZir,
1089 tag: zir.Inst.Tag,
1090 callee: zir.Inst.Ref,
1091 args: []const zir.Inst.Ref,
1092 /// Absolute node index. This function does the conversion to offset from Decl.
1093 abs_node_index: ast.Node.Index,
1094 ) !zir.Inst.Index {
1095 assert(callee != 0);
1096 assert(abs_node_index != 0);
1097 const gpa = gz.zir_code.gpa;
1098 try gz.instructions.ensureCapacity(gpa, gz.instructions.items.len + 1);
1099 try gz.zir_code.instructions.ensureCapacity(gpa, gz.zir_code.instructions.len + 1);
1100 try gz.zir_code.extra.ensureCapacity(gpa, gz.zir_code.extra.items.len +
1101 @typeInfo(zir.Inst.Call).Struct.fields.len + args.len);
1102
1103 const payload_index = gz.zir_code.addExtra(zir.Inst.Call{
1104 .callee = callee,
1105 .args_len = @intCast(u32, args.len),
1106 }) catch unreachable; // Capacity is ensured above.
1107 gz.zir_code.extra.appendSliceAssumeCapacity(args);
1108
1109 const new_index = @intCast(zir.Inst.Index, gz.zir_code.instructions.len);
1110 gz.zir_code.instructions.appendAssumeCapacity(.{
1111 .tag = tag,
1112 .data = .{ .pl_node = .{
1113 .src_node = gz.zir_code.decl.nodeIndexToRelative(abs_node_index),
1114 .payload_index = payload_index,
1115 } },
1116 });
1117 gz.instructions.appendAssumeCapacity(new_index);
1118 return new_index + gz.zir_code.ref_start_index;
1119 }
1120
1079 pub fn addInt(gz: *GenZir, integer: u64) !zir.Inst.Ref {1121 pub fn addInt(gz: *GenZir, integer: u64) !zir.Inst.Ref {
1080 return gz.add(.{1122 return gz.add(.{
1081 .tag = .int,1123 .tag = .int,
...@@ -1095,7 +1137,7 @@ pub const Scope = struct {...@@ -1095,7 +1137,7 @@ pub const Scope = struct {
1095 .tag = tag,1137 .tag = tag,
1096 .data = .{ .un_node = .{1138 .data = .{ .un_node = .{
1097 .operand = operand,1139 .operand = operand,
1098 .src_node = abs_node_index - gz.zir_code.decl.srcNode(),1140 .src_node = gz.zir_code.decl.nodeIndexToRelative(abs_node_index),
1099 } },1141 } },
1100 });1142 });
1101 }1143 }
...@@ -1116,7 +1158,7 @@ pub const Scope = struct {...@@ -1116,7 +1158,7 @@ pub const Scope = struct {
1116 gz.zir_code.instructions.appendAssumeCapacity(.{1158 gz.zir_code.instructions.appendAssumeCapacity(.{
1117 .tag = tag,1159 .tag = tag,
1118 .data = .{ .pl_node = .{1160 .data = .{ .pl_node = .{
1119 .src_node = gz.zir_code.decl.srcNode() - abs_node_index,1161 .src_node = gz.zir_code.decl.nodeIndexToRelative(abs_node_index),
1120 .payload_index = payload_index,1162 .payload_index = payload_index,
1121 } },1163 } },
1122 });1164 });
...@@ -1177,7 +1219,7 @@ pub const Scope = struct {...@@ -1177,7 +1219,7 @@ pub const Scope = struct {
1177 ) !zir.Inst.Ref {1219 ) !zir.Inst.Ref {
1178 return gz.add(.{1220 return gz.add(.{
1179 .tag = tag,1221 .tag = tag,
1180 .data = .{ .node = abs_node_index - gz.zir_code.decl.srcNode() },1222 .data = .{ .node = gz.zir_code.decl.nodeIndexToRelative(abs_node_index) },
1181 });1223 });
1182 }1224 }
11831225
...@@ -1205,14 +1247,14 @@ pub const Scope = struct {...@@ -1205,14 +1247,14 @@ pub const Scope = struct {
1205 try gz.zir_code.instructions.append(gz.zir_code.gpa, .{1247 try gz.zir_code.instructions.append(gz.zir_code.gpa, .{
1206 .tag = tag,1248 .tag = tag,
1207 .data = .{ .pl_node = .{1249 .data = .{ .pl_node = .{
1208 .src_node = node - gz.zir_code.decl.srcNode(),1250 .src_node = gz.zir_code.decl.nodeIndexToRelative(node),
1209 .payload_index = undefined,1251 .payload_index = undefined,
1210 } },1252 } },
1211 });1253 });
1212 return new_index;1254 return new_index;
1213 }1255 }
12141256
1215 fn add(gz: *GenZir, inst: zir.Inst) !zir.Inst.Ref {1257 pub fn add(gz: *GenZir, inst: zir.Inst) !zir.Inst.Ref {
1216 const gpa = gz.zir_code.gpa;1258 const gpa = gz.zir_code.gpa;
1217 try gz.instructions.ensureCapacity(gpa, gz.instructions.items.len + 1);1259 try gz.instructions.ensureCapacity(gpa, gz.instructions.items.len + 1);
1218 try gz.zir_code.instructions.ensureCapacity(gpa, gz.zir_code.instructions.len + 1);1260 try gz.zir_code.instructions.ensureCapacity(gpa, gz.zir_code.instructions.len + 1);
...@@ -1593,7 +1635,7 @@ pub const SrcLoc = struct {...@@ -1593,7 +1635,7 @@ pub const SrcLoc = struct {
1593 },1635 },
1594 .node_offset => |node_off| {1636 .node_offset => |node_off| {
1595 const decl = src_loc.container.decl;1637 const decl = src_loc.container.decl;
1596 const node_index = decl.srcNode() + node_off;1638 const node_index = decl.relativeToNodeIndex(node_off);
1597 const tree = decl.container.file_scope.base.tree();1639 const tree = decl.container.file_scope.base.tree();
1598 const tok_index = tree.firstToken(node_index);1640 const tok_index = tree.firstToken(node_index);
1599 const token_starts = tree.tokens.items(.start);1641 const token_starts = tree.tokens.items(.start);
...@@ -1659,84 +1701,84 @@ pub const LazySrcLoc = union(enum) {...@@ -1659,84 +1701,84 @@ pub const LazySrcLoc = union(enum) {
1659 /// The source location points to an AST node, which is this value offset1701 /// The source location points to an AST node, which is this value offset
1660 /// from its containing Decl node AST index.1702 /// from its containing Decl node AST index.
1661 /// The Decl is determined contextually.1703 /// The Decl is determined contextually.
1662 node_offset: u32,1704 node_offset: i32,
1663 /// The source location points to a variable declaration type expression,1705 /// The source location points to a variable declaration type expression,
1664 /// found by taking this AST node index offset from the containing1706 /// found by taking this AST node index offset from the containing
1665 /// Decl AST node, which points to a variable declaration AST node. Next, navigate1707 /// Decl AST node, which points to a variable declaration AST node. Next, navigate
1666 /// to the type expression.1708 /// to the type expression.
1667 /// The Decl is determined contextually.1709 /// The Decl is determined contextually.
1668 node_offset_var_decl_ty: u32,1710 node_offset_var_decl_ty: i32,
1669 /// The source location points to a for loop condition expression,1711 /// The source location points to a for loop condition expression,
1670 /// found by taking this AST node index offset from the containing1712 /// found by taking this AST node index offset from the containing
1671 /// Decl AST node, which points to a for loop AST node. Next, navigate1713 /// Decl AST node, which points to a for loop AST node. Next, navigate
1672 /// to the condition expression.1714 /// to the condition expression.
1673 /// The Decl is determined contextually.1715 /// The Decl is determined contextually.
1674 node_offset_for_cond: u32,1716 node_offset_for_cond: i32,
1675 /// The source location points to the first parameter of a builtin1717 /// The source location points to the first parameter of a builtin
1676 /// function call, found by taking this AST node index offset from the containing1718 /// function call, found by taking this AST node index offset from the containing
1677 /// Decl AST node, which points to a builtin call AST node. Next, navigate1719 /// Decl AST node, which points to a builtin call AST node. Next, navigate
1678 /// to the first parameter.1720 /// to the first parameter.
1679 /// The Decl is determined contextually.1721 /// The Decl is determined contextually.
1680 node_offset_builtin_call_arg0: u32,1722 node_offset_builtin_call_arg0: i32,
1681 /// Same as `node_offset_builtin_call_arg0` except arg index 1.1723 /// Same as `node_offset_builtin_call_arg0` except arg index 1.
1682 node_offset_builtin_call_arg1: u32,1724 node_offset_builtin_call_arg1: i32,
1683 /// Same as `node_offset_builtin_call_arg0` except the arg index is contextually1725 /// Same as `node_offset_builtin_call_arg0` except the arg index is contextually
1684 /// determined.1726 /// determined.
1685 node_offset_builtin_call_argn: u32,1727 node_offset_builtin_call_argn: i32,
1686 /// The source location points to the index expression of an array access1728 /// The source location points to the index expression of an array access
1687 /// expression, found by taking this AST node index offset from the containing1729 /// expression, found by taking this AST node index offset from the containing
1688 /// Decl AST node, which points to an array access AST node. Next, navigate1730 /// Decl AST node, which points to an array access AST node. Next, navigate
1689 /// to the index expression.1731 /// to the index expression.
1690 /// The Decl is determined contextually.1732 /// The Decl is determined contextually.
1691 node_offset_array_access_index: u32,1733 node_offset_array_access_index: i32,
1692 /// The source location points to the sentinel expression of a slice1734 /// The source location points to the sentinel expression of a slice
1693 /// expression, found by taking this AST node index offset from the containing1735 /// expression, found by taking this AST node index offset from the containing
1694 /// Decl AST node, which points to a slice AST node. Next, navigate1736 /// Decl AST node, which points to a slice AST node. Next, navigate
1695 /// to the sentinel expression.1737 /// to the sentinel expression.
1696 /// The Decl is determined contextually.1738 /// The Decl is determined contextually.
1697 node_offset_slice_sentinel: u32,1739 node_offset_slice_sentinel: i32,
1698 /// The source location points to the callee expression of a function1740 /// The source location points to the callee expression of a function
1699 /// call expression, found by taking this AST node index offset from the containing1741 /// call expression, found by taking this AST node index offset from the containing
1700 /// Decl AST node, which points to a function call AST node. Next, navigate1742 /// Decl AST node, which points to a function call AST node. Next, navigate
1701 /// to the callee expression.1743 /// to the callee expression.
1702 /// The Decl is determined contextually.1744 /// The Decl is determined contextually.
1703 node_offset_call_func: u32,1745 node_offset_call_func: i32,
1704 /// The source location points to the field name of a field access expression,1746 /// The source location points to the field name of a field access expression,
1705 /// found by taking this AST node index offset from the containing1747 /// found by taking this AST node index offset from the containing
1706 /// Decl AST node, which points to a field access AST node. Next, navigate1748 /// Decl AST node, which points to a field access AST node. Next, navigate
1707 /// to the field name token.1749 /// to the field name token.
1708 /// The Decl is determined contextually.1750 /// The Decl is determined contextually.
1709 node_offset_field_name: u32,1751 node_offset_field_name: i32,
1710 /// The source location points to the pointer of a pointer deref expression,1752 /// The source location points to the pointer of a pointer deref expression,
1711 /// found by taking this AST node index offset from the containing1753 /// found by taking this AST node index offset from the containing
1712 /// Decl AST node, which points to a pointer deref AST node. Next, navigate1754 /// Decl AST node, which points to a pointer deref AST node. Next, navigate
1713 /// to the pointer expression.1755 /// to the pointer expression.
1714 /// The Decl is determined contextually.1756 /// The Decl is determined contextually.
1715 node_offset_deref_ptr: u32,1757 node_offset_deref_ptr: i32,
1716 /// The source location points to the assembly source code of an inline assembly1758 /// The source location points to the assembly source code of an inline assembly
1717 /// expression, found by taking this AST node index offset from the containing1759 /// expression, found by taking this AST node index offset from the containing
1718 /// Decl AST node, which points to inline assembly AST node. Next, navigate1760 /// Decl AST node, which points to inline assembly AST node. Next, navigate
1719 /// to the asm template source code.1761 /// to the asm template source code.
1720 /// The Decl is determined contextually.1762 /// The Decl is determined contextually.
1721 node_offset_asm_source: u32,1763 node_offset_asm_source: i32,
1722 /// The source location points to the return type of an inline assembly1764 /// The source location points to the return type of an inline assembly
1723 /// expression, found by taking this AST node index offset from the containing1765 /// expression, found by taking this AST node index offset from the containing
1724 /// Decl AST node, which points to inline assembly AST node. Next, navigate1766 /// Decl AST node, which points to inline assembly AST node. Next, navigate
1725 /// to the return type expression.1767 /// to the return type expression.
1726 /// The Decl is determined contextually.1768 /// The Decl is determined contextually.
1727 node_offset_asm_ret_ty: u32,1769 node_offset_asm_ret_ty: i32,
1728 /// The source location points to the condition expression of an if1770 /// The source location points to the condition expression of an if
1729 /// expression, found by taking this AST node index offset from the containing1771 /// expression, found by taking this AST node index offset from the containing
1730 /// Decl AST node, which points to an if expression AST node. Next, navigate1772 /// Decl AST node, which points to an if expression AST node. Next, navigate
1731 /// to the condition expression.1773 /// to the condition expression.
1732 /// The Decl is determined contextually.1774 /// The Decl is determined contextually.
1733 node_offset_if_cond: u32,1775 node_offset_if_cond: i32,
1734 /// The source location points to the type expression of an `anyframe->T`1776 /// The source location points to the type expression of an `anyframe->T`
1735 /// expression, found by taking this AST node index offset from the containing1777 /// expression, found by taking this AST node index offset from the containing
1736 /// Decl AST node, which points to a `anyframe->T` expression AST node. Next, navigate1778 /// Decl AST node, which points to a `anyframe->T` expression AST node. Next, navigate
1737 /// to the type expression.1779 /// to the type expression.
1738 /// The Decl is determined contextually.1780 /// The Decl is determined contextually.
1739 node_offset_anyframe_type: u32,1781 node_offset_anyframe_type: i32,
17401782
1741 /// Upgrade to a `SrcLoc` based on the `Decl` or file in the provided scope.1783 /// Upgrade to a `SrcLoc` based on the `Decl` or file in the provided scope.
1742 pub fn toSrcLoc(lazy: LazySrcLoc, scope: *Scope) SrcLoc {1784 pub fn toSrcLoc(lazy: LazySrcLoc, scope: *Scope) SrcLoc {
...@@ -3678,8 +3720,7 @@ pub fn failTok(...@@ -3678,8 +3720,7 @@ pub fn failTok(
3678 comptime format: []const u8,3720 comptime format: []const u8,
3679 args: anytype,3721 args: anytype,
3680) InnerError {3722) InnerError {
3681 const decl_token = scope.srcDecl().?.srcToken();3723 const src = scope.srcDecl().?.tokSrcLoc(token_index);
3682 const src: LazySrcLoc = .{ .token_offset = token_index - decl_token };
3683 return mod.fail(scope, src, format, args);3724 return mod.fail(scope, src, format, args);
3684}3725}
36853726
...@@ -3692,8 +3733,7 @@ pub fn failNode(...@@ -3692,8 +3733,7 @@ pub fn failNode(
3692 comptime format: []const u8,3733 comptime format: []const u8,
3693 args: anytype,3734 args: anytype,
3694) InnerError {3735) InnerError {
3695 const decl_node = scope.srcDecl().?.srcNode();3736 const src = scope.srcDecl().?.nodeSrcLoc(node_index);
3696 const src: LazySrcLoc = .{ .node_offset = decl_node - node_index };
3697 return mod.fail(scope, src, format, args);3737 return mod.fail(scope, src, format, args);
3698}3738}
36993739
src/Sema.zig+1-1
...@@ -618,7 +618,7 @@ fn zirParamType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerErr...@@ -618,7 +618,7 @@ fn zirParamType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerErr
618 const tracy = trace(@src());618 const tracy = trace(@src());
619 defer tracy.end();619 defer tracy.end();
620620
621 const src: LazySrcLoc = .todo;621 const src: LazySrcLoc = .unneeded;
622 const inst_data = sema.code.instructions.items(.data)[inst].param_type;622 const inst_data = sema.code.instructions.items(.data)[inst].param_type;
623 const fn_inst = try sema.resolveInst(inst_data.callee);623 const fn_inst = try sema.resolveInst(inst_data.callee);
624 const param_index = inst_data.param_index;624 const param_index = inst_data.param_index;
src/astgen.zig+10-11
...@@ -3402,10 +3402,6 @@ fn callExpr(...@@ -3402,10 +3402,6 @@ fn callExpr(
3402 node: ast.Node.Index,3402 node: ast.Node.Index,
3403 call: ast.full.Call,3403 call: ast.full.Call,
3404) InnerError!zir.Inst.Ref {3404) InnerError!zir.Inst.Ref {
3405 if (true) {
3406 @panic("TODO update for zir-memory-layout branch");
3407 }
3408
3409 if (call.async_token) |async_token| {3405 if (call.async_token) |async_token| {
3410 return mod.failTok(scope, async_token, "TODO implement async fn call", .{});3406 return mod.failTok(scope, async_token, "TODO implement async fn call", .{});
3411 }3407 }
...@@ -3414,11 +3410,14 @@ fn callExpr(...@@ -3414,11 +3410,14 @@ fn callExpr(
3414 const args = try mod.gpa.alloc(zir.Inst.Index, call.ast.params.len);3410 const args = try mod.gpa.alloc(zir.Inst.Index, call.ast.params.len);
3415 defer mod.gpa.free(args);3411 defer mod.gpa.free(args);
34163412
3417 const gen_zir = scope.getGenZir();3413 const gz = scope.getGenZir();
3418 for (call.ast.params) |param_node, i| {3414 for (call.ast.params) |param_node, i| {
3419 const param_type = try gen_zir.addParamType(.{3415 const param_type = try gz.add(.{
3420 .callee = lhs,3416 .tag = .param_type,
3421 .param_index = i,3417 .data = .{ .param_type = .{
3418 .callee = lhs,
3419 .param_index = @intCast(u32, i),
3420 } },
3422 });3421 });
3423 args[i] = try expr(mod, scope, .{ .ty = param_type }, param_node);3422 args[i] = try expr(mod, scope, .{ .ty = param_type }, param_node);
3424 }3423 }
...@@ -3430,7 +3429,7 @@ fn callExpr(...@@ -3430,7 +3429,7 @@ fn callExpr(
3430 const result: zir.Inst.Index = res: {3429 const result: zir.Inst.Index = res: {
3431 const tag: zir.Inst.Tag = switch (modifier) {3430 const tag: zir.Inst.Tag = switch (modifier) {
3432 .auto => switch (args.len == 0) {3431 .auto => switch (args.len == 0) {
3433 true => break :res try gen_zir.addCallNone(lhs, node),3432 true => break :res try gz.addUnNode(.call_none, lhs, node),
3434 false => .call,3433 false => .call,
3435 },3434 },
3436 .async_kw => .call_async_kw,3435 .async_kw => .call_async_kw,
...@@ -3441,9 +3440,9 @@ fn callExpr(...@@ -3441,9 +3440,9 @@ fn callExpr(
3441 .always_inline => unreachable,3440 .always_inline => unreachable,
3442 .compile_time => .call_compile_time,3441 .compile_time => .call_compile_time,
3443 };3442 };
3444 break :res try gen_zir.addCall(tag, lhs, args, node);3443 break :res try gz.addCall(tag, lhs, args, node);
3445 };3444 };
3446 return rvalue(mod, scope, rl, result); // TODO function call with result location3445 return rvalue(mod, scope, rl, result, node); // TODO function call with result location
3447}3446}
34483447
3449fn suspendExpr(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!zir.Inst.Ref {3448fn suspendExpr(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!zir.Inst.Ref {
src/zir.zig+17-6
...@@ -1019,7 +1019,7 @@ pub const Inst = struct {...@@ -1019,7 +1019,7 @@ pub const Inst = struct {
1019 /// Used for unary operators, with an AST node source location.1019 /// Used for unary operators, with an AST node source location.
1020 un_node: struct {1020 un_node: struct {
1021 /// Offset from Decl AST node index.1021 /// Offset from Decl AST node index.
1022 src_node: ast.Node.Index,1022 src_node: i32,
1023 /// The meaning of this operand depends on the corresponding `Tag`.1023 /// The meaning of this operand depends on the corresponding `Tag`.
1024 operand: Ref,1024 operand: Ref,
10251025
...@@ -1041,7 +1041,7 @@ pub const Inst = struct {...@@ -1041,7 +1041,7 @@ pub const Inst = struct {
1041 pl_node: struct {1041 pl_node: struct {
1042 /// Offset from Decl AST node index.1042 /// Offset from Decl AST node index.
1043 /// `Tag` determines which kind of AST node this points to.1043 /// `Tag` determines which kind of AST node this points to.
1044 src_node: ast.Node.Index,1044 src_node: i32,
1045 /// index into extra.1045 /// index into extra.
1046 /// `Tag` determines what lives there.1046 /// `Tag` determines what lives there.
1047 payload_index: u32,1047 payload_index: u32,
...@@ -1092,7 +1092,7 @@ pub const Inst = struct {...@@ -1092,7 +1092,7 @@ pub const Inst = struct {
1092 /// Offset from Decl AST token index.1092 /// Offset from Decl AST token index.
1093 tok: ast.TokenIndex,1093 tok: ast.TokenIndex,
1094 /// Offset from Decl AST node index.1094 /// Offset from Decl AST node index.
1095 node: ast.Node.Index,1095 node: i32,
1096 int: u64,1096 int: u64,
1097 array_type_sentinel: struct {1097 array_type_sentinel: struct {
1098 len: Ref,1098 len: Ref,
...@@ -1400,9 +1400,10 @@ const Writer = struct {...@@ -1400,9 +1400,10 @@ const Writer = struct {
1400 .slice_sentinel,1400 .slice_sentinel,
1401 .typeof_peer,1401 .typeof_peer,
1402 .suspend_block,1402 .suspend_block,
1403 .as_node,
1404 => try self.writePlNode(stream, inst),1403 => try self.writePlNode(stream, inst),
14051404
1405 .as_node => try self.writeAs(stream, inst),
1406
1406 .breakpoint,1407 .breakpoint,
1407 .dbg_stmt_node,1408 .dbg_stmt_node,
1408 .ret_ptr,1409 .ret_ptr,
...@@ -1544,6 +1545,16 @@ const Writer = struct {...@@ -1544,6 +1545,16 @@ const Writer = struct {
1544 try self.writeSrc(stream, inst_data.src());1545 try self.writeSrc(stream, inst_data.src());
1545 }1546 }
15461547
1548 fn writeAs(self: *Writer, stream: anytype, inst: Inst.Index) !void {
1549 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
1550 const extra = self.code.extraData(Inst.As, inst_data.payload_index).data;
1551 try self.writeInstRef(stream, extra.dest_type);
1552 try stream.writeAll(", ");
1553 try self.writeInstRef(stream, extra.operand);
1554 try stream.writeAll(") ");
1555 try self.writeSrc(stream, inst_data.src());
1556 }
1557
1547 fn writeNode(1558 fn writeNode(
1548 self: *Writer,1559 self: *Writer,
1549 stream: anytype,1560 stream: anytype,
...@@ -1560,8 +1571,8 @@ const Writer = struct {...@@ -1560,8 +1571,8 @@ const Writer = struct {
1560 stream: anytype,1571 stream: anytype,
1561 inst: Inst.Index,1572 inst: Inst.Index,
1562 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {1573 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {
1563 const inst_data = self.code.instructions.items(.data)[inst].decl;1574 const decl = self.code.instructions.items(.data)[inst].decl;
1564 try stream.writeAll("TODO)");1575 try stream.print("{s})", .{decl.name});
1565 }1576 }
15661577
1567 fn writeStrTok(1578 fn writeStrTok(