| ... | ... | @@ -1074,10 +1074,10 @@ pub const Scope = struct { |
| 1074 | 1074 | callee: zir.Inst.Ref, |
| 1075 | 1075 | args: []const zir.Inst.Ref, |
| 1076 | 1076 | /// Absolute node index. This function does the conversion to offset from Decl. |
| 1077 | | abs_node_index: ast.Node.Index, |
| 1077 | src_node: ast.Node.Index, |
| 1078 | 1078 | ) !zir.Inst.Ref { |
| 1079 | 1079 | assert(callee != 0); |
| 1080 | | assert(abs_node_index != 0); |
| 1080 | assert(src_node != 0); |
| 1081 | 1081 | const gpa = gz.zir_code.gpa; |
| 1082 | 1082 | try gz.instructions.ensureCapacity(gpa, gz.instructions.items.len + 1); |
| 1083 | 1083 | try gz.zir_code.instructions.ensureCapacity(gpa, gz.zir_code.instructions.len + 1); |
| ... | ... | @@ -1094,7 +1094,7 @@ pub const Scope = struct { |
| 1094 | 1094 | gz.zir_code.instructions.appendAssumeCapacity(.{ |
| 1095 | 1095 | .tag = tag, |
| 1096 | 1096 | .data = .{ .pl_node = .{ |
| 1097 | | .src_node = gz.zir_code.decl.nodeIndexToRelative(abs_node_index), |
| 1097 | .src_node = gz.zir_code.decl.nodeIndexToRelative(src_node), |
| 1098 | 1098 | .payload_index = payload_index, |
| 1099 | 1099 | } }, |
| 1100 | 1100 | }); |
| ... | ... | @@ -1138,14 +1138,24 @@ pub const Scope = struct { |
| 1138 | 1138 | tag: zir.Inst.Tag, |
| 1139 | 1139 | operand: zir.Inst.Ref, |
| 1140 | 1140 | /// Absolute node index. This function does the conversion to offset from Decl. |
| 1141 | | abs_node_index: ast.Node.Index, |
| 1141 | src_node: ast.Node.Index, |
| 1142 | 1142 | ) !zir.Inst.Ref { |
| 1143 | return gz.zir_code.ref_start_index + try gz.addUnNodeAsIndex(tag, operand, src_node); |
| 1144 | } |
| 1145 | |
| 1146 | pub fn addUnNodeAsIndex( |
| 1147 | gz: *GenZir, |
| 1148 | tag: zir.Inst.Tag, |
| 1149 | operand: zir.Inst.Ref, |
| 1150 | /// Absolute node index. This function does the conversion to offset from Decl. |
| 1151 | src_node: ast.Node.Index, |
| 1152 | ) !zir.Inst.Index { |
| 1143 | 1153 | assert(operand != 0); |
| 1144 | | return gz.add(.{ |
| 1154 | return gz.addAsIndex(.{ |
| 1145 | 1155 | .tag = tag, |
| 1146 | 1156 | .data = .{ .un_node = .{ |
| 1147 | 1157 | .operand = operand, |
| 1148 | | .src_node = gz.zir_code.decl.nodeIndexToRelative(abs_node_index), |
| 1158 | .src_node = gz.zir_code.decl.nodeIndexToRelative(src_node), |
| 1149 | 1159 | } }, |
| 1150 | 1160 | }); |
| 1151 | 1161 | } |
| ... | ... | @@ -1154,7 +1164,7 @@ pub const Scope = struct { |
| 1154 | 1164 | gz: *GenZir, |
| 1155 | 1165 | tag: zir.Inst.Tag, |
| 1156 | 1166 | /// Absolute node index. This function does the conversion to offset from Decl. |
| 1157 | | abs_node_index: ast.Node.Index, |
| 1167 | src_node: ast.Node.Index, |
| 1158 | 1168 | extra: anytype, |
| 1159 | 1169 | ) !zir.Inst.Ref { |
| 1160 | 1170 | const gpa = gz.zir_code.gpa; |
| ... | ... | @@ -1166,7 +1176,7 @@ pub const Scope = struct { |
| 1166 | 1176 | gz.zir_code.instructions.appendAssumeCapacity(.{ |
| 1167 | 1177 | .tag = tag, |
| 1168 | 1178 | .data = .{ .pl_node = .{ |
| 1169 | | .src_node = gz.zir_code.decl.nodeIndexToRelative(abs_node_index), |
| 1179 | .src_node = gz.zir_code.decl.nodeIndexToRelative(src_node), |
| 1170 | 1180 | .payload_index = payload_index, |
| 1171 | 1181 | } }, |
| 1172 | 1182 | }); |
| ... | ... | @@ -1239,9 +1249,18 @@ pub const Scope = struct { |
| 1239 | 1249 | lhs: zir.Inst.Ref, |
| 1240 | 1250 | rhs: zir.Inst.Ref, |
| 1241 | 1251 | ) !zir.Inst.Ref { |
| 1252 | return gz.zir_code.ref_start_index + try gz.addBinAsIndex(tag, lhs, rhs); |
| 1253 | } |
| 1254 | |
| 1255 | pub fn addBinAsIndex( |
| 1256 | gz: *GenZir, |
| 1257 | tag: zir.Inst.Tag, |
| 1258 | lhs: zir.Inst.Ref, |
| 1259 | rhs: zir.Inst.Ref, |
| 1260 | ) !zir.Inst.Index { |
| 1242 | 1261 | assert(lhs != 0); |
| 1243 | 1262 | assert(rhs != 0); |
| 1244 | | return gz.add(.{ |
| 1263 | return gz.addAsIndex(.{ |
| 1245 | 1264 | .tag = tag, |
| 1246 | 1265 | .data = .{ .bin = .{ |
| 1247 | 1266 | .lhs = lhs, |
| ... | ... | @@ -1265,11 +1284,11 @@ pub const Scope = struct { |
| 1265 | 1284 | gz: *GenZir, |
| 1266 | 1285 | tag: zir.Inst.Tag, |
| 1267 | 1286 | /// Absolute node index. This function does the conversion to offset from Decl. |
| 1268 | | abs_node_index: ast.Node.Index, |
| 1287 | src_node: ast.Node.Index, |
| 1269 | 1288 | ) !zir.Inst.Ref { |
| 1270 | 1289 | return gz.add(.{ |
| 1271 | 1290 | .tag = tag, |
| 1272 | | .data = .{ .node = gz.zir_code.decl.nodeIndexToRelative(abs_node_index) }, |
| 1291 | .data = .{ .node = gz.zir_code.decl.nodeIndexToRelative(src_node) }, |
| 1273 | 1292 | }); |
| 1274 | 1293 | } |
| 1275 | 1294 | |
| ... | ... | @@ -1321,6 +1340,10 @@ pub const Scope = struct { |
| 1321 | 1340 | } |
| 1322 | 1341 | |
| 1323 | 1342 | pub fn add(gz: *GenZir, inst: zir.Inst) !zir.Inst.Ref { |
| 1343 | return gz.zir_code.ref_start_index + try gz.addAsIndex(inst); |
| 1344 | } |
| 1345 | |
| 1346 | pub fn addAsIndex(gz: *GenZir, inst: zir.Inst) !zir.Inst.Index { |
| 1324 | 1347 | const gpa = gz.zir_code.gpa; |
| 1325 | 1348 | try gz.instructions.ensureCapacity(gpa, gz.instructions.items.len + 1); |
| 1326 | 1349 | try gz.zir_code.instructions.ensureCapacity(gpa, gz.zir_code.instructions.len + 1); |
| ... | ... | @@ -1328,7 +1351,7 @@ pub const Scope = struct { |
| 1328 | 1351 | const new_index = @intCast(zir.Inst.Index, gz.zir_code.instructions.len); |
| 1329 | 1352 | gz.zir_code.instructions.appendAssumeCapacity(inst); |
| 1330 | 1353 | gz.instructions.appendAssumeCapacity(new_index); |
| 1331 | | return new_index + gz.zir_code.ref_start_index; |
| 1354 | return new_index; |
| 1332 | 1355 | } |
| 1333 | 1356 | }; |
| 1334 | 1357 | |