| ... | @@ -58,20 +58,14 @@ pub const ResultLoc = union(enum) { | ... | @@ -58,20 +58,14 @@ pub const ResultLoc = union(enum) { |
| 58 | }; | 58 | }; |
| 59 | }; | 59 | }; |
| 60 | | 60 | |
| 61 | pub fn typeExpr(mod: *Module, scope: *Scope, type_node: ast.Node.Index) InnerError!*zir.Inst { | 61 | const void_inst: zir.Inst.Ref = @enumToInt(zir.Const.void_value); |
| 62 | const tree = scope.tree(); | | |
| 63 | const token_starts = tree.tokens.items(.start); | | |
| 64 | | 62 | |
| 65 | const type_src = token_starts[tree.firstToken(type_node)]; | 63 | pub fn typeExpr(mod: *Module, scope: *Scope, type_node: ast.Node.Index) InnerError!zir.Inst.Ref { |
| 66 | const type_type = try addZIRInstConst(mod, scope, type_src, .{ | 64 | const type_rl: ResultLoc = .{ .ty = @enumToInt(zir.Const.type_type) }; |
| 67 | .ty = Type.initTag(.type), | | |
| 68 | .val = Value.initTag(.type_type), | | |
| 69 | }); | | |
| 70 | const type_rl: ResultLoc = .{ .ty = type_type }; | | |
| 71 | return expr(mod, scope, type_rl, type_node); | 65 | return expr(mod, scope, type_rl, type_node); |
| 72 | } | 66 | } |
| 73 | | 67 | |
| 74 | fn lvalExpr(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!*zir.Inst { | 68 | fn lvalExpr(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!zir.Inst.Ref { |
| 75 | const tree = scope.tree(); | 69 | const tree = scope.tree(); |
| 76 | const node_tags = tree.nodes.items(.tag); | 70 | const node_tags = tree.nodes.items(.tag); |
| 77 | const main_tokens = tree.nodes.items(.main_token); | 71 | const main_tokens = tree.nodes.items(.main_token); |
| ... | @@ -265,7 +259,7 @@ fn lvalExpr(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!*zir.I | ... | @@ -265,7 +259,7 @@ fn lvalExpr(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!*zir.I |
| 265 | /// When `rl` is discard, ptr, inferred_ptr, bitcasted_ptr, or inferred_ptr, the | 259 | /// When `rl` is discard, ptr, inferred_ptr, bitcasted_ptr, or inferred_ptr, the |
| 266 | /// result instruction can be used to inspect whether it is isNoReturn() but that is it, | 260 | /// result instruction can be used to inspect whether it is isNoReturn() but that is it, |
| 267 | /// it must otherwise not be used. | 261 | /// it must otherwise not be used. |
| 268 | pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerError!*zir.Inst { | 262 | pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerError!zir.Inst.Ref { |
| 269 | const tree = scope.tree(); | 263 | const tree = scope.tree(); |
| 270 | const main_tokens = tree.nodes.items(.main_token); | 264 | const main_tokens = tree.nodes.items(.main_token); |
| 271 | const token_tags = tree.tokens.items(.tag); | 265 | const token_tags = tree.tokens.items(.tag); |
| ... | @@ -294,20 +288,62 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In | ... | @@ -294,20 +288,62 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 294 | .asm_output => unreachable, // Handled in `asmExpr`. | 288 | .asm_output => unreachable, // Handled in `asmExpr`. |
| 295 | .asm_input => unreachable, // Handled in `asmExpr`. | 289 | .asm_input => unreachable, // Handled in `asmExpr`. |
| 296 | | 290 | |
| 297 | .assign => return rvalueVoid(mod, scope, rl, node, try assign(mod, scope, node)), | 291 | .assign => { |
| 298 | .assign_bit_and => return rvalueVoid(mod, scope, rl, node, try assignOp(mod, scope, node, .bit_and)), | 292 | try assign(mod, scope, node); |
| 299 | .assign_bit_or => return rvalueVoid(mod, scope, rl, node, try assignOp(mod, scope, node, .bit_or)), | 293 | return rvalue(mod, scope, rl, void_inst, node); |
| 300 | .assign_bit_shift_left => return rvalueVoid(mod, scope, rl, node, try assignOp(mod, scope, node, .shl)), | 294 | }, |
| 301 | .assign_bit_shift_right => return rvalueVoid(mod, scope, rl, node, try assignOp(mod, scope, node, .shr)), | 295 | .assign_bit_and => { |
| 302 | .assign_bit_xor => return rvalueVoid(mod, scope, rl, node, try assignOp(mod, scope, node, .xor)), | 296 | try assignOp(mod, scope, node, .bit_and); |
| 303 | .assign_div => return rvalueVoid(mod, scope, rl, node, try assignOp(mod, scope, node, .div)), | 297 | return rvalue(mod, scope, rl, void_inst, node); |
| 304 | .assign_sub => return rvalueVoid(mod, scope, rl, node, try assignOp(mod, scope, node, .sub)), | 298 | }, |
| 305 | .assign_sub_wrap => return rvalueVoid(mod, scope, rl, node, try assignOp(mod, scope, node, .subwrap)), | 299 | .assign_bit_or => { |
| 306 | .assign_mod => return rvalueVoid(mod, scope, rl, node, try assignOp(mod, scope, node, .mod_rem)), | 300 | try assignOp(mod, scope, node, .bit_or); |
| 307 | .assign_add => return rvalueVoid(mod, scope, rl, node, try assignOp(mod, scope, node, .add)), | 301 | return rvalue(mod, scope, rl, void_inst, node); |
| 308 | .assign_add_wrap => return rvalueVoid(mod, scope, rl, node, try assignOp(mod, scope, node, .addwrap)), | 302 | }, |
| 309 | .assign_mul => return rvalueVoid(mod, scope, rl, node, try assignOp(mod, scope, node, .mul)), | 303 | .assign_bit_shift_left => { |
| 310 | .assign_mul_wrap => return rvalueVoid(mod, scope, rl, node, try assignOp(mod, scope, node, .mulwrap)), | 304 | try assignOp(mod, scope, node, .shl); |
| | 305 | return rvalue(mod, scope, rl, void_inst, node); |
| | 306 | }, |
| | 307 | .assign_bit_shift_right => { |
| | 308 | try assignOp(mod, scope, node, .shr); |
| | 309 | return rvalue(mod, scope, rl, void_inst, node); |
| | 310 | }, |
| | 311 | .assign_bit_xor => { |
| | 312 | try assignOp(mod, scope, node, .xor); |
| | 313 | return rvalue(mod, scope, rl, void_inst, node); |
| | 314 | }, |
| | 315 | .assign_div => { |
| | 316 | try assignOp(mod, scope, node, .div); |
| | 317 | return rvalue(mod, scope, rl, void_inst, node); |
| | 318 | }, |
| | 319 | .assign_sub => { |
| | 320 | try assignOp(mod, scope, node, .sub); |
| | 321 | return rvalue(mod, scope, rl, void_inst, node); |
| | 322 | }, |
| | 323 | .assign_sub_wrap => { |
| | 324 | try assignOp(mod, scope, node, .subwrap); |
| | 325 | return rvalue(mod, scope, rl, void_inst, node); |
| | 326 | }, |
| | 327 | .assign_mod => { |
| | 328 | try assignOp(mod, scope, node, .mod_rem); |
| | 329 | return rvalue(mod, scope, rl, void_inst, node); |
| | 330 | }, |
| | 331 | .assign_add => { |
| | 332 | try assignOp(mod, scope, node, .add); |
| | 333 | return rvalue(mod, scope, rl, void_inst, node); |
| | 334 | }, |
| | 335 | .assign_add_wrap => { |
| | 336 | try assignOp(mod, scope, node, .addwrap); |
| | 337 | return rvalue(mod, scope, rl, void_inst, node); |
| | 338 | }, |
| | 339 | .assign_mul => { |
| | 340 | try assignOp(mod, scope, node, .mul); |
| | 341 | return rvalue(mod, scope, rl, void_inst, node); |
| | 342 | }, |
| | 343 | .assign_mul_wrap => { |
| | 344 | try assignOp(mod, scope, node, .mulwrap); |
| | 345 | return rvalue(mod, scope, rl, void_inst, node); |
| | 346 | }, |
| 311 | | 347 | |
| 312 | .add => return simpleBinOp(mod, scope, rl, node, .add), | 348 | .add => return simpleBinOp(mod, scope, rl, node, .add), |
| 313 | .add_wrap => return simpleBinOp(mod, scope, rl, node, .addwrap), | 349 | .add_wrap => return simpleBinOp(mod, scope, rl, node, .addwrap), |
| ... | @@ -336,10 +372,14 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In | ... | @@ -336,10 +372,14 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 336 | .bool_and => return boolBinOp(mod, scope, rl, node, true), | 372 | .bool_and => return boolBinOp(mod, scope, rl, node, true), |
| 337 | .bool_or => return boolBinOp(mod, scope, rl, node, false), | 373 | .bool_or => return boolBinOp(mod, scope, rl, node, false), |
| 338 | | 374 | |
| 339 | .bool_not => return rvalue(mod, scope, rl, try boolNot(mod, scope, node)), | 375 | .bool_not => @panic("TODO"), |
| 340 | .bit_not => return rvalue(mod, scope, rl, try bitNot(mod, scope, node)), | 376 | .bit_not => @panic("TODO"), |
| 341 | .negation => return rvalue(mod, scope, rl, try negation(mod, scope, node, .sub)), | 377 | .negation => @panic("TODO"), |
| 342 | .negation_wrap => return rvalue(mod, scope, rl, try negation(mod, scope, node, .subwrap)), | 378 | .negation_wrap => @panic("TODO"), |
| | 379 | //.bool_not => return rvalue(mod, scope, rl, try boolNot(mod, scope, node)), |
| | 380 | //.bit_not => return rvalue(mod, scope, rl, try bitNot(mod, scope, node)), |
| | 381 | //.negation => return rvalue(mod, scope, rl, try negation(mod, scope, node, .sub)), |
| | 382 | //.negation_wrap => return rvalue(mod, scope, rl, try negation(mod, scope, node, .subwrap)), |
| 343 | | 383 | |
| 344 | .identifier => return identifier(mod, scope, rl, node), | 384 | .identifier => return identifier(mod, scope, rl, node), |
| 345 | | 385 | |
| ... | @@ -377,6 +417,7 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In | ... | @@ -377,6 +417,7 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 377 | }, | 417 | }, |
| 378 | | 418 | |
| 379 | .unreachable_literal => { | 419 | .unreachable_literal => { |
| | 420 | if (true) @panic("TODO update for zir-memory-layout"); |
| 380 | const main_token = main_tokens[node]; | 421 | const main_token = main_tokens[node]; |
| 381 | const src = token_starts[main_token]; | 422 | const src = token_starts[main_token]; |
| 382 | return addZIRNoOp(mod, scope, src, .unreachable_safe); | 423 | return addZIRNoOp(mod, scope, src, .unreachable_safe); |
| ... | @@ -402,16 +443,19 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In | ... | @@ -402,16 +443,19 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 402 | .slice_sentinel => return sliceExpr(mod, scope, rl, tree.sliceSentinel(node)), | 443 | .slice_sentinel => return sliceExpr(mod, scope, rl, tree.sliceSentinel(node)), |
| 403 | | 444 | |
| 404 | .deref => { | 445 | .deref => { |
| | 446 | if (true) @panic("TODO update for zir-memory-layout"); |
| 405 | const lhs = try expr(mod, scope, .none, node_datas[node].lhs); | 447 | const lhs = try expr(mod, scope, .none, node_datas[node].lhs); |
| 406 | const src = token_starts[main_tokens[node]]; | 448 | const src = token_starts[main_tokens[node]]; |
| 407 | const result = try addZIRUnOp(mod, scope, src, .deref, lhs); | 449 | const result = try addZIRUnOp(mod, scope, src, .deref, lhs); |
| 408 | return rvalue(mod, scope, rl, result); | 450 | return rvalue(mod, scope, rl, result); |
| 409 | }, | 451 | }, |
| 410 | .address_of => { | 452 | .address_of => { |
| | 453 | if (true) @panic("TODO update for zir-memory-layout"); |
| 411 | const result = try expr(mod, scope, .ref, node_datas[node].lhs); | 454 | const result = try expr(mod, scope, .ref, node_datas[node].lhs); |
| 412 | return rvalue(mod, scope, rl, result); | 455 | return rvalue(mod, scope, rl, result); |
| 413 | }, | 456 | }, |
| 414 | .undefined_literal => { | 457 | .undefined_literal => { |
| | 458 | if (true) @panic("TODO update for zir-memory-layout"); |
| 415 | const main_token = main_tokens[node]; | 459 | const main_token = main_tokens[node]; |
| 416 | const src = token_starts[main_token]; | 460 | const src = token_starts[main_token]; |
| 417 | const result = try addZIRInstConst(mod, scope, src, .{ | 461 | const result = try addZIRInstConst(mod, scope, src, .{ |
| ... | @@ -421,6 +465,7 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In | ... | @@ -421,6 +465,7 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 421 | return rvalue(mod, scope, rl, result); | 465 | return rvalue(mod, scope, rl, result); |
| 422 | }, | 466 | }, |
| 423 | .true_literal => { | 467 | .true_literal => { |
| | 468 | if (true) @panic("TODO update for zir-memory-layout"); |
| 424 | const main_token = main_tokens[node]; | 469 | const main_token = main_tokens[node]; |
| 425 | const src = token_starts[main_token]; | 470 | const src = token_starts[main_token]; |
| 426 | const result = try addZIRInstConst(mod, scope, src, .{ | 471 | const result = try addZIRInstConst(mod, scope, src, .{ |
| ... | @@ -430,6 +475,7 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In | ... | @@ -430,6 +475,7 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 430 | return rvalue(mod, scope, rl, result); | 475 | return rvalue(mod, scope, rl, result); |
| 431 | }, | 476 | }, |
| 432 | .false_literal => { | 477 | .false_literal => { |
| | 478 | if (true) @panic("TODO update for zir-memory-layout"); |
| 433 | const main_token = main_tokens[node]; | 479 | const main_token = main_tokens[node]; |
| 434 | const src = token_starts[main_token]; | 480 | const src = token_starts[main_token]; |
| 435 | const result = try addZIRInstConst(mod, scope, src, .{ | 481 | const result = try addZIRInstConst(mod, scope, src, .{ |
| ... | @@ -439,6 +485,7 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In | ... | @@ -439,6 +485,7 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 439 | return rvalue(mod, scope, rl, result); | 485 | return rvalue(mod, scope, rl, result); |
| 440 | }, | 486 | }, |
| 441 | .null_literal => { | 487 | .null_literal => { |
| | 488 | if (true) @panic("TODO update for zir-memory-layout"); |
| 442 | const main_token = main_tokens[node]; | 489 | const main_token = main_tokens[node]; |
| 443 | const src = token_starts[main_token]; | 490 | const src = token_starts[main_token]; |
| 444 | const result = try addZIRInstConst(mod, scope, src, .{ | 491 | const result = try addZIRInstConst(mod, scope, src, .{ |
| ... | @@ -448,12 +495,14 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In | ... | @@ -448,12 +495,14 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 448 | return rvalue(mod, scope, rl, result); | 495 | return rvalue(mod, scope, rl, result); |
| 449 | }, | 496 | }, |
| 450 | .optional_type => { | 497 | .optional_type => { |
| | 498 | if (true) @panic("TODO update for zir-memory-layout"); |
| 451 | const src = token_starts[main_tokens[node]]; | 499 | const src = token_starts[main_tokens[node]]; |
| 452 | const operand = try typeExpr(mod, scope, node_datas[node].lhs); | 500 | const operand = try typeExpr(mod, scope, node_datas[node].lhs); |
| 453 | const result = try addZIRUnOp(mod, scope, src, .optional_type, operand); | 501 | const result = try addZIRUnOp(mod, scope, src, .optional_type, operand); |
| 454 | return rvalue(mod, scope, rl, result); | 502 | return rvalue(mod, scope, rl, result); |
| 455 | }, | 503 | }, |
| 456 | .unwrap_optional => { | 504 | .unwrap_optional => { |
| | 505 | if (true) @panic("TODO update for zir-memory-layout"); |
| 457 | const src = token_starts[main_tokens[node]]; | 506 | const src = token_starts[main_tokens[node]]; |
| 458 | switch (rl) { | 507 | switch (rl) { |
| 459 | .ref => return addZIRUnOp( | 508 | .ref => return addZIRUnOp( |
| ... | @@ -473,6 +522,7 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In | ... | @@ -473,6 +522,7 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 473 | } | 522 | } |
| 474 | }, | 523 | }, |
| 475 | .block_two, .block_two_semicolon => { | 524 | .block_two, .block_two_semicolon => { |
| | 525 | if (true) @panic("TODO update for zir-memory-layout"); |
| 476 | const statements = [2]ast.Node.Index{ node_datas[node].lhs, node_datas[node].rhs }; | 526 | const statements = [2]ast.Node.Index{ node_datas[node].lhs, node_datas[node].rhs }; |
| 477 | if (node_datas[node].lhs == 0) { | 527 | if (node_datas[node].lhs == 0) { |
| 478 | return blockExpr(mod, scope, rl, node, statements[0..0]); | 528 | return blockExpr(mod, scope, rl, node, statements[0..0]); |
| ... | @@ -483,10 +533,12 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In | ... | @@ -483,10 +533,12 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 483 | } | 533 | } |
| 484 | }, | 534 | }, |
| 485 | .block, .block_semicolon => { | 535 | .block, .block_semicolon => { |
| | 536 | if (true) @panic("TODO update for zir-memory-layout"); |
| 486 | const statements = tree.extra_data[node_datas[node].lhs..node_datas[node].rhs]; | 537 | const statements = tree.extra_data[node_datas[node].lhs..node_datas[node].rhs]; |
| 487 | return blockExpr(mod, scope, rl, node, statements); | 538 | return blockExpr(mod, scope, rl, node, statements); |
| 488 | }, | 539 | }, |
| 489 | .enum_literal => { | 540 | .enum_literal => { |
| | 541 | if (true) @panic("TODO update for zir-memory-layout"); |
| 490 | const ident_token = main_tokens[node]; | 542 | const ident_token = main_tokens[node]; |
| 491 | const gen_zir = scope.getGenZir(); | 543 | const gen_zir = scope.getGenZir(); |
| 492 | const string_bytes = &gen_zir.zir_exec.string_bytes; | 544 | const string_bytes = &gen_zir.zir_exec.string_bytes; |
| ... | @@ -497,6 +549,7 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In | ... | @@ -497,6 +549,7 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 497 | return rvalue(mod, scope, rl, result); | 549 | return rvalue(mod, scope, rl, result); |
| 498 | }, | 550 | }, |
| 499 | .error_value => { | 551 | .error_value => { |
| | 552 | if (true) @panic("TODO update for zir-memory-layout"); |
| 500 | const ident_token = node_datas[node].rhs; | 553 | const ident_token = node_datas[node].rhs; |
| 501 | const name = try mod.identifierTokenString(scope, ident_token); | 554 | const name = try mod.identifierTokenString(scope, ident_token); |
| 502 | const src = token_starts[ident_token]; | 555 | const src = token_starts[ident_token]; |
| ... | @@ -504,6 +557,7 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In | ... | @@ -504,6 +557,7 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 504 | return rvalue(mod, scope, rl, result); | 557 | return rvalue(mod, scope, rl, result); |
| 505 | }, | 558 | }, |
| 506 | .error_union => { | 559 | .error_union => { |
| | 560 | if (true) @panic("TODO update for zir-memory-layout"); |
| 507 | const error_set = try typeExpr(mod, scope, node_datas[node].lhs); | 561 | const error_set = try typeExpr(mod, scope, node_datas[node].lhs); |
| 508 | const payload = try typeExpr(mod, scope, node_datas[node].rhs); | 562 | const payload = try typeExpr(mod, scope, node_datas[node].rhs); |
| 509 | const src = token_starts[main_tokens[node]]; | 563 | const src = token_starts[main_tokens[node]]; |
| ... | @@ -511,6 +565,7 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In | ... | @@ -511,6 +565,7 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 511 | return rvalue(mod, scope, rl, result); | 565 | return rvalue(mod, scope, rl, result); |
| 512 | }, | 566 | }, |
| 513 | .merge_error_sets => { | 567 | .merge_error_sets => { |
| | 568 | if (true) @panic("TODO update for zir-memory-layout"); |
| 514 | const lhs = try typeExpr(mod, scope, node_datas[node].lhs); | 569 | const lhs = try typeExpr(mod, scope, node_datas[node].lhs); |
| 515 | const rhs = try typeExpr(mod, scope, node_datas[node].rhs); | 570 | const rhs = try typeExpr(mod, scope, node_datas[node].rhs); |
| 516 | const src = token_starts[main_tokens[node]]; | 571 | const src = token_starts[main_tokens[node]]; |
| ... | @@ -518,6 +573,7 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In | ... | @@ -518,6 +573,7 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 518 | return rvalue(mod, scope, rl, result); | 573 | return rvalue(mod, scope, rl, result); |
| 519 | }, | 574 | }, |
| 520 | .anyframe_literal => { | 575 | .anyframe_literal => { |
| | 576 | if (true) @panic("TODO update for zir-memory-layout"); |
| 521 | const main_token = main_tokens[node]; | 577 | const main_token = main_tokens[node]; |
| 522 | const src = token_starts[main_token]; | 578 | const src = token_starts[main_token]; |
| 523 | const result = try addZIRInstConst(mod, scope, src, .{ | 579 | const result = try addZIRInstConst(mod, scope, src, .{ |
| ... | @@ -527,12 +583,14 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In | ... | @@ -527,12 +583,14 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 527 | return rvalue(mod, scope, rl, result); | 583 | return rvalue(mod, scope, rl, result); |
| 528 | }, | 584 | }, |
| 529 | .anyframe_type => { | 585 | .anyframe_type => { |
| | 586 | if (true) @panic("TODO update for zir-memory-layout"); |
| 530 | const src = token_starts[node_datas[node].lhs]; | 587 | const src = token_starts[node_datas[node].lhs]; |
| 531 | const return_type = try typeExpr(mod, scope, node_datas[node].rhs); | 588 | const return_type = try typeExpr(mod, scope, node_datas[node].rhs); |
| 532 | const result = try addZIRUnOp(mod, scope, src, .anyframe_type, return_type); | 589 | const result = try addZIRUnOp(mod, scope, src, .anyframe_type, return_type); |
| 533 | return rvalue(mod, scope, rl, result); | 590 | return rvalue(mod, scope, rl, result); |
| 534 | }, | 591 | }, |
| 535 | .@"catch" => { | 592 | .@"catch" => { |
| | 593 | if (true) @panic("TODO update for zir-memory-layout"); |
| 536 | const catch_token = main_tokens[node]; | 594 | const catch_token = main_tokens[node]; |
| 537 | const payload_token: ?ast.TokenIndex = if (token_tags[catch_token + 1] == .pipe) | 595 | const payload_token: ?ast.TokenIndex = if (token_tags[catch_token + 1] == .pipe) |
| 538 | catch_token + 2 | 596 | catch_token + 2 |
| ... | @@ -631,9 +689,11 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In | ... | @@ -631,9 +689,11 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 631 | .@"switch", .switch_comma => return switchExpr(mod, scope, rl, node), | 689 | .@"switch", .switch_comma => return switchExpr(mod, scope, rl, node), |
| 632 | | 690 | |
| 633 | .@"nosuspend" => return nosuspendExpr(mod, scope, rl, node), | 691 | .@"nosuspend" => return nosuspendExpr(mod, scope, rl, node), |
| 634 | .@"suspend" => return rvalue(mod, scope, rl, try suspendExpr(mod, scope, node)), | 692 | .@"suspend" => @panic("TODO"), |
| | 693 | //.@"suspend" => return rvalue(mod, scope, rl, try suspendExpr(mod, scope, node)), |
| 635 | .@"await" => return awaitExpr(mod, scope, rl, node), | 694 | .@"await" => return awaitExpr(mod, scope, rl, node), |
| 636 | .@"resume" => return rvalue(mod, scope, rl, try resumeExpr(mod, scope, node)), | 695 | .@"resume" => @panic("TODO"), |
| | 696 | //.@"resume" => return rvalue(mod, scope, rl, try resumeExpr(mod, scope, node)), |
| 637 | | 697 | |
| 638 | .@"defer" => return mod.failNode(scope, node, "TODO implement astgen.expr for .defer", .{}), | 698 | .@"defer" => return mod.failNode(scope, node, "TODO implement astgen.expr for .defer", .{}), |
| 639 | .@"errdefer" => return mod.failNode(scope, node, "TODO implement astgen.expr for .errdefer", .{}), | 699 | .@"errdefer" => return mod.failNode(scope, node, "TODO implement astgen.expr for .errdefer", .{}), |
| ... | @@ -673,20 +733,22 @@ pub fn comptimeExpr( | ... | @@ -673,20 +733,22 @@ pub fn comptimeExpr( |
| 673 | parent_scope: *Scope, | 733 | parent_scope: *Scope, |
| 674 | rl: ResultLoc, | 734 | rl: ResultLoc, |
| 675 | node: ast.Node.Index, | 735 | node: ast.Node.Index, |
| 676 | ) InnerError!*zir.Inst { | 736 | ) InnerError!zir.Inst.Ref { |
| | 737 | if (true) @panic("TODO update for zir-memory-layout branch"); |
| | 738 | |
| 677 | // If we are already in a comptime scope, no need to make another one. | 739 | // If we are already in a comptime scope, no need to make another one. |
| 678 | if (parent_scope.isComptime()) { | 740 | if (parent_scope.isComptime()) { |
| 679 | return expr(mod, parent_scope, rl, node); | 741 | return expr(mod, parent_scope, rl, node); |
| 680 | } | 742 | } |
| 681 | | 743 | |
| | 744 | const gz = parent_scope.getGenZir(); |
| 682 | const tree = parent_scope.tree(); | 745 | const tree = parent_scope.tree(); |
| 683 | const token_starts = tree.tokens.items(.start); | 746 | const token_starts = tree.tokens.items(.start); |
| 684 | | 747 | |
| 685 | // Make a scope to collect generated instructions in the sub-expression. | 748 | // Make a scope to collect generated instructions in the sub-expression. |
| 686 | var block_scope: Scope.GenZir = .{ | 749 | var block_scope: Scope.GenZir = .{ |
| 687 | .parent = parent_scope, | 750 | .parent = parent_scope, |
| 688 | .decl = parent_scope.ownerDecl().?, | 751 | .zir_code = gz.zir_code, |
| 689 | .arena = parent_scope.arena(), | | |
| 690 | .force_comptime = true, | 752 | .force_comptime = true, |
| 691 | .instructions = .{}, | 753 | .instructions = .{}, |
| 692 | }; | 754 | }; |
| ... | @@ -698,7 +760,7 @@ pub fn comptimeExpr( | ... | @@ -698,7 +760,7 @@ pub fn comptimeExpr( |
| 698 | | 760 | |
| 699 | const src = token_starts[tree.firstToken(node)]; | 761 | const src = token_starts[tree.firstToken(node)]; |
| 700 | const block = try addZIRInstBlock(mod, parent_scope, src, .block_comptime_flat, .{ | 762 | const block = try addZIRInstBlock(mod, parent_scope, src, .block_comptime_flat, .{ |
| 701 | .instructions = try block_scope.arena.dupe(*zir.Inst, block_scope.instructions.items), | 763 | .instructions = try block_scope.arena.dupe(zir.Inst.Ref, block_scope.instructions.items), |
| 702 | }); | 764 | }); |
| 703 | | 765 | |
| 704 | return &block.base; | 766 | return &block.base; |
| ... | @@ -709,7 +771,8 @@ fn breakExpr( | ... | @@ -709,7 +771,8 @@ fn breakExpr( |
| 709 | parent_scope: *Scope, | 771 | parent_scope: *Scope, |
| 710 | rl: ResultLoc, | 772 | rl: ResultLoc, |
| 711 | node: ast.Node.Index, | 773 | node: ast.Node.Index, |
| 712 | ) InnerError!*zir.Inst { | 774 | ) InnerError!zir.Inst.Ref { |
| | 775 | if (true) @panic("TODO update for zir-memory-layout"); |
| 713 | const tree = parent_scope.tree(); | 776 | const tree = parent_scope.tree(); |
| 714 | const node_datas = tree.nodes.items(.data); | 777 | const node_datas = tree.nodes.items(.data); |
| 715 | const main_tokens = tree.nodes.items(.main_token); | 778 | const main_tokens = tree.nodes.items(.main_token); |
| ... | @@ -787,7 +850,8 @@ fn continueExpr( | ... | @@ -787,7 +850,8 @@ fn continueExpr( |
| 787 | parent_scope: *Scope, | 850 | parent_scope: *Scope, |
| 788 | rl: ResultLoc, | 851 | rl: ResultLoc, |
| 789 | node: ast.Node.Index, | 852 | node: ast.Node.Index, |
| 790 | ) InnerError!*zir.Inst { | 853 | ) InnerError!zir.Inst.Ref { |
| | 854 | if (true) @panic("TODO update for zir-memory-layout"); |
| 791 | const tree = parent_scope.tree(); | 855 | const tree = parent_scope.tree(); |
| 792 | const node_datas = tree.nodes.items(.data); | 856 | const node_datas = tree.nodes.items(.data); |
| 793 | const main_tokens = tree.nodes.items(.main_token); | 857 | const main_tokens = tree.nodes.items(.main_token); |
| ... | @@ -843,7 +907,7 @@ pub fn blockExpr( | ... | @@ -843,7 +907,7 @@ pub fn blockExpr( |
| 843 | rl: ResultLoc, | 907 | rl: ResultLoc, |
| 844 | block_node: ast.Node.Index, | 908 | block_node: ast.Node.Index, |
| 845 | statements: []const ast.Node.Index, | 909 | statements: []const ast.Node.Index, |
| 846 | ) InnerError!*zir.Inst { | 910 | ) InnerError!zir.Inst.Ref { |
| 847 | const tracy = trace(@src()); | 911 | const tracy = trace(@src()); |
| 848 | defer tracy.end(); | 912 | defer tracy.end(); |
| 849 | | 913 | |
| ... | @@ -859,7 +923,7 @@ pub fn blockExpr( | ... | @@ -859,7 +923,7 @@ pub fn blockExpr( |
| 859 | } | 923 | } |
| 860 | | 924 | |
| 861 | try blockExprStmts(mod, scope, block_node, statements); | 925 | try blockExprStmts(mod, scope, block_node, statements); |
| 862 | return rvalueVoid(mod, scope, rl, block_node, {}); | 926 | return rvalue(mod, scope, rl, void_inst, block_node); |
| 863 | } | 927 | } |
| 864 | | 928 | |
| 865 | fn checkLabelRedefinition(mod: *Module, parent_scope: *Scope, label: ast.TokenIndex) !void { | 929 | fn checkLabelRedefinition(mod: *Module, parent_scope: *Scope, label: ast.TokenIndex) !void { |
| ... | @@ -875,21 +939,18 @@ fn checkLabelRedefinition(mod: *Module, parent_scope: *Scope, label: ast.TokenIn | ... | @@ -875,21 +939,18 @@ fn checkLabelRedefinition(mod: *Module, parent_scope: *Scope, label: ast.TokenIn |
| 875 | const main_tokens = tree.nodes.items(.main_token); | 939 | const main_tokens = tree.nodes.items(.main_token); |
| 876 | const token_starts = tree.tokens.items(.start); | 940 | const token_starts = tree.tokens.items(.start); |
| 877 | | 941 | |
| 878 | const label_src = token_starts[label]; | | |
| 879 | const prev_label_src = token_starts[prev_label.token]; | | |
| 880 | | | |
| 881 | const label_name = try mod.identifierTokenString(parent_scope, label); | 942 | const label_name = try mod.identifierTokenString(parent_scope, label); |
| 882 | const msg = msg: { | 943 | const msg = msg: { |
| 883 | const msg = try mod.errMsg( | 944 | const msg = try mod.errMsg( |
| 884 | parent_scope, | 945 | parent_scope, |
| 885 | label_src, | 946 | gen_zir.tokSrcLoc(label), |
| 886 | "redefinition of label '{s}'", | 947 | "redefinition of label '{s}'", |
| 887 | .{label_name}, | 948 | .{label_name}, |
| 888 | ); | 949 | ); |
| 889 | errdefer msg.destroy(mod.gpa); | 950 | errdefer msg.destroy(mod.gpa); |
| 890 | try mod.errNote( | 951 | try mod.errNote( |
| 891 | parent_scope, | 952 | parent_scope, |
| 892 | prev_label_src, | 953 | gen_zir.tokSrcLoc(prev_label.token), |
| 893 | msg, | 954 | msg, |
| 894 | "previous definition is here", | 955 | "previous definition is here", |
| 895 | .{}, | 956 | .{}, |
| ... | @@ -917,7 +978,7 @@ fn labeledBlockExpr( | ... | @@ -917,7 +978,7 @@ fn labeledBlockExpr( |
| 917 | block_node: ast.Node.Index, | 978 | block_node: ast.Node.Index, |
| 918 | statements: []const ast.Node.Index, | 979 | statements: []const ast.Node.Index, |
| 919 | zir_tag: zir.Inst.Tag, | 980 | zir_tag: zir.Inst.Tag, |
| 920 | ) InnerError!*zir.Inst { | 981 | ) InnerError!zir.Inst.Ref { |
| 921 | const tracy = trace(@src()); | 982 | const tracy = trace(@src()); |
| 922 | defer tracy.end(); | 983 | defer tracy.end(); |
| 923 | | 984 | |
| ... | @@ -1285,6 +1346,7 @@ fn assignOp( | ... | @@ -1285,6 +1346,7 @@ fn assignOp( |
| 1285 | infix_node: ast.Node.Index, | 1346 | infix_node: ast.Node.Index, |
| 1286 | op_inst_tag: zir.Inst.Tag, | 1347 | op_inst_tag: zir.Inst.Tag, |
| 1287 | ) InnerError!void { | 1348 | ) InnerError!void { |
| | 1349 | if (true) @panic("TODO update for zir-memory-layout"); |
| 1288 | const tree = scope.tree(); | 1350 | const tree = scope.tree(); |
| 1289 | const node_datas = tree.nodes.items(.data); | 1351 | const node_datas = tree.nodes.items(.data); |
| 1290 | const main_tokens = tree.nodes.items(.main_token); | 1352 | const main_tokens = tree.nodes.items(.main_token); |
| ... | @@ -1299,7 +1361,7 @@ fn assignOp( | ... | @@ -1299,7 +1361,7 @@ fn assignOp( |
| 1299 | _ = try addZIRBinOp(mod, scope, src, .store, lhs_ptr, result); | 1361 | _ = try addZIRBinOp(mod, scope, src, .store, lhs_ptr, result); |
| 1300 | } | 1362 | } |
| 1301 | | 1363 | |
| 1302 | fn boolNot(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!*zir.Inst { | 1364 | fn boolNot(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!zir.Inst.Ref { |
| 1303 | const tree = scope.tree(); | 1365 | const tree = scope.tree(); |
| 1304 | const node_datas = tree.nodes.items(.data); | 1366 | const node_datas = tree.nodes.items(.data); |
| 1305 | const main_tokens = tree.nodes.items(.main_token); | 1367 | const main_tokens = tree.nodes.items(.main_token); |
| ... | @@ -1314,7 +1376,7 @@ fn boolNot(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!*zir.In | ... | @@ -1314,7 +1376,7 @@ fn boolNot(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!*zir.In |
| 1314 | return addZIRUnOp(mod, scope, src, .bool_not, operand); | 1376 | return addZIRUnOp(mod, scope, src, .bool_not, operand); |
| 1315 | } | 1377 | } |
| 1316 | | 1378 | |
| 1317 | fn bitNot(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!*zir.Inst { | 1379 | fn bitNot(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!zir.Inst.Ref { |
| 1318 | const tree = scope.tree(); | 1380 | const tree = scope.tree(); |
| 1319 | const node_datas = tree.nodes.items(.data); | 1381 | const node_datas = tree.nodes.items(.data); |
| 1320 | const main_tokens = tree.nodes.items(.main_token); | 1382 | const main_tokens = tree.nodes.items(.main_token); |
| ... | @@ -1330,7 +1392,7 @@ fn negation( | ... | @@ -1330,7 +1392,7 @@ fn negation( |
| 1330 | scope: *Scope, | 1392 | scope: *Scope, |
| 1331 | node: ast.Node.Index, | 1393 | node: ast.Node.Index, |
| 1332 | op_inst_tag: zir.Inst.Tag, | 1394 | op_inst_tag: zir.Inst.Tag, |
| 1333 | ) InnerError!*zir.Inst { | 1395 | ) InnerError!zir.Inst.Ref { |
| 1334 | const tree = scope.tree(); | 1396 | const tree = scope.tree(); |
| 1335 | const node_datas = tree.nodes.items(.data); | 1397 | const node_datas = tree.nodes.items(.data); |
| 1336 | const main_tokens = tree.nodes.items(.main_token); | 1398 | const main_tokens = tree.nodes.items(.main_token); |
| ... | @@ -1350,7 +1412,8 @@ fn ptrType( | ... | @@ -1350,7 +1412,8 @@ fn ptrType( |
| 1350 | scope: *Scope, | 1412 | scope: *Scope, |
| 1351 | rl: ResultLoc, | 1413 | rl: ResultLoc, |
| 1352 | ptr_info: ast.full.PtrType, | 1414 | ptr_info: ast.full.PtrType, |
| 1353 | ) InnerError!*zir.Inst { | 1415 | ) InnerError!zir.Inst.Ref { |
| | 1416 | if (true) @panic("TODO update for zir-memory-layout"); |
| 1354 | const tree = scope.tree(); | 1417 | const tree = scope.tree(); |
| 1355 | const token_starts = tree.tokens.items(.start); | 1418 | const token_starts = tree.tokens.items(.start); |
| 1356 | | 1419 | |
| ... | @@ -1394,7 +1457,8 @@ fn ptrType( | ... | @@ -1394,7 +1457,8 @@ fn ptrType( |
| 1394 | return rvalue(mod, scope, rl, result); | 1457 | return rvalue(mod, scope, rl, result); |
| 1395 | } | 1458 | } |
| 1396 | | 1459 | |
| 1397 | fn arrayType(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) !*zir.Inst { | 1460 | fn arrayType(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) !zir.Inst.Ref { |
| | 1461 | if (true) @panic("TODO update for zir-memory-layout"); |
| 1398 | const tree = scope.tree(); | 1462 | const tree = scope.tree(); |
| 1399 | const main_tokens = tree.nodes.items(.main_token); | 1463 | const main_tokens = tree.nodes.items(.main_token); |
| 1400 | const node_datas = tree.nodes.items(.data); | 1464 | const node_datas = tree.nodes.items(.data); |
| ... | @@ -1421,7 +1485,8 @@ fn arrayType(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) ! | ... | @@ -1421,7 +1485,8 @@ fn arrayType(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) ! |
| 1421 | } | 1485 | } |
| 1422 | } | 1486 | } |
| 1423 | | 1487 | |
| 1424 | fn arrayTypeSentinel(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) !*zir.Inst { | 1488 | fn arrayTypeSentinel(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) !zir.Inst.Ref { |
| | 1489 | if (true) @panic("TODO update for zir-memory-layout"); |
| 1425 | const tree = scope.tree(); | 1490 | const tree = scope.tree(); |
| 1426 | const main_tokens = tree.nodes.items(.main_token); | 1491 | const main_tokens = tree.nodes.items(.main_token); |
| 1427 | const token_starts = tree.tokens.items(.start); | 1492 | const token_starts = tree.tokens.items(.start); |
| ... | @@ -1454,7 +1519,8 @@ fn containerDecl( | ... | @@ -1454,7 +1519,8 @@ fn containerDecl( |
| 1454 | scope: *Scope, | 1519 | scope: *Scope, |
| 1455 | rl: ResultLoc, | 1520 | rl: ResultLoc, |
| 1456 | container_decl: ast.full.ContainerDecl, | 1521 | container_decl: ast.full.ContainerDecl, |
| 1457 | ) InnerError!*zir.Inst { | 1522 | ) InnerError!zir.Inst.Ref { |
| | 1523 | if (true) @panic("TODO update for zir-memory-layout"); |
| 1458 | return mod.failTok(scope, container_decl.ast.main_token, "TODO implement container decls", .{}); | 1524 | return mod.failTok(scope, container_decl.ast.main_token, "TODO implement container decls", .{}); |
| 1459 | } | 1525 | } |
| 1460 | | 1526 | |
| ... | @@ -1463,7 +1529,8 @@ fn errorSetDecl( | ... | @@ -1463,7 +1529,8 @@ fn errorSetDecl( |
| 1463 | scope: *Scope, | 1529 | scope: *Scope, |
| 1464 | rl: ResultLoc, | 1530 | rl: ResultLoc, |
| 1465 | node: ast.Node.Index, | 1531 | node: ast.Node.Index, |
| 1466 | ) InnerError!*zir.Inst { | 1532 | ) InnerError!zir.Inst.Ref { |
| | 1533 | if (true) @panic("TODO update for zir-memory-layout"); |
| 1467 | const tree = scope.tree(); | 1534 | const tree = scope.tree(); |
| 1468 | const main_tokens = tree.nodes.items(.main_token); | 1535 | const main_tokens = tree.nodes.items(.main_token); |
| 1469 | const token_tags = tree.tokens.items(.tag); | 1536 | const token_tags = tree.tokens.items(.tag); |
| ... | @@ -1516,7 +1583,9 @@ fn orelseCatchExpr( | ... | @@ -1516,7 +1583,9 @@ fn orelseCatchExpr( |
| 1516 | unwrap_code_op: zir.Inst.Tag, | 1583 | unwrap_code_op: zir.Inst.Tag, |
| 1517 | rhs: ast.Node.Index, | 1584 | rhs: ast.Node.Index, |
| 1518 | payload_token: ?ast.TokenIndex, | 1585 | payload_token: ?ast.TokenIndex, |
| 1519 | ) InnerError!*zir.Inst { | 1586 | ) InnerError!zir.Inst.Ref { |
| | 1587 | if (true) @panic("TODO update for zir-memory-layout"); |
| | 1588 | |
| 1520 | const tree = scope.tree(); | 1589 | const tree = scope.tree(); |
| 1521 | const token_starts = tree.tokens.items(.start); | 1590 | const token_starts = tree.tokens.items(.start); |
| 1522 | | 1591 | |
| ... | @@ -1548,7 +1617,7 @@ fn orelseCatchExpr( | ... | @@ -1548,7 +1617,7 @@ fn orelseCatchExpr( |
| 1548 | }, .{}); | 1617 | }, .{}); |
| 1549 | | 1618 | |
| 1550 | const block = try addZIRInstBlock(mod, scope, src, .block, .{ | 1619 | const block = try addZIRInstBlock(mod, scope, src, .block, .{ |
| 1551 | .instructions = try block_scope.arena.dupe(*zir.Inst, block_scope.instructions.items), | 1620 | .instructions = try block_scope.arena.dupe(zir.Inst.Ref, block_scope.instructions.items), |
| 1552 | }); | 1621 | }); |
| 1553 | | 1622 | |
| 1554 | var then_scope: Scope.GenZir = .{ | 1623 | var then_scope: Scope.GenZir = .{ |
| ... | @@ -1624,11 +1693,11 @@ fn finishThenElseBlock( | ... | @@ -1624,11 +1693,11 @@ fn finishThenElseBlock( |
| 1624 | else_body: *zir.Body, | 1693 | else_body: *zir.Body, |
| 1625 | then_src: usize, | 1694 | then_src: usize, |
| 1626 | else_src: usize, | 1695 | else_src: usize, |
| 1627 | then_result: *zir.Inst, | 1696 | then_result: zir.Inst.Ref, |
| 1628 | else_result: ?*zir.Inst, | 1697 | else_result: ?*zir.Inst, |
| 1629 | main_block: *zir.Inst.Block, | 1698 | main_block: zir.Inst.Ref.Block, |
| 1630 | then_break_block: *zir.Inst.Block, | 1699 | then_break_block: zir.Inst.Ref.Block, |
| 1631 | ) InnerError!*zir.Inst { | 1700 | ) InnerError!zir.Inst.Ref { |
| 1632 | // We now have enough information to decide whether the result instruction should | 1701 | // We now have enough information to decide whether the result instruction should |
| 1633 | // be communicated via result location pointer or break instructions. | 1702 | // be communicated via result location pointer or break instructions. |
| 1634 | const strat = rlStrategy(rl, block_scope); | 1703 | const strat = rlStrategy(rl, block_scope); |
| ... | @@ -1699,7 +1768,8 @@ fn tokenIdentEql(mod: *Module, scope: *Scope, token1: ast.TokenIndex, token2: as | ... | @@ -1699,7 +1768,8 @@ fn tokenIdentEql(mod: *Module, scope: *Scope, token1: ast.TokenIndex, token2: as |
| 1699 | return mem.eql(u8, ident_name_1, ident_name_2); | 1768 | return mem.eql(u8, ident_name_1, ident_name_2); |
| 1700 | } | 1769 | } |
| 1701 | | 1770 | |
| 1702 | pub fn fieldAccess(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerError!*zir.Inst { | 1771 | pub fn fieldAccess(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerError!zir.Inst.Ref { |
| | 1772 | if (true) @panic("TODO update for zir-memory-layout"); |
| 1703 | const tree = scope.tree(); | 1773 | const tree = scope.tree(); |
| 1704 | const token_starts = tree.tokens.items(.start); | 1774 | const token_starts = tree.tokens.items(.start); |
| 1705 | const main_tokens = tree.nodes.items(.main_token); | 1775 | const main_tokens = tree.nodes.items(.main_token); |
| ... | @@ -1727,7 +1797,8 @@ fn arrayAccess( | ... | @@ -1727,7 +1797,8 @@ fn arrayAccess( |
| 1727 | scope: *Scope, | 1797 | scope: *Scope, |
| 1728 | rl: ResultLoc, | 1798 | rl: ResultLoc, |
| 1729 | node: ast.Node.Index, | 1799 | node: ast.Node.Index, |
| 1730 | ) InnerError!*zir.Inst { | 1800 | ) InnerError!zir.Inst.Ref { |
| | 1801 | if (true) @panic("TODO update for zir-memory-layout"); |
| 1731 | const tree = scope.tree(); | 1802 | const tree = scope.tree(); |
| 1732 | const main_tokens = tree.nodes.items(.main_token); | 1803 | const main_tokens = tree.nodes.items(.main_token); |
| 1733 | const token_starts = tree.tokens.items(.start); | 1804 | const token_starts = tree.tokens.items(.start); |
| ... | @@ -1756,7 +1827,8 @@ fn sliceExpr( | ... | @@ -1756,7 +1827,8 @@ fn sliceExpr( |
| 1756 | scope: *Scope, | 1827 | scope: *Scope, |
| 1757 | rl: ResultLoc, | 1828 | rl: ResultLoc, |
| 1758 | slice: ast.full.Slice, | 1829 | slice: ast.full.Slice, |
| 1759 | ) InnerError!*zir.Inst { | 1830 | ) InnerError!zir.Inst.Ref { |
| | 1831 | if (true) @panic("TODO update for zir-memory-layout"); |
| 1760 | const tree = scope.tree(); | 1832 | const tree = scope.tree(); |
| 1761 | const token_starts = tree.tokens.items(.start); | 1833 | const token_starts = tree.tokens.items(.start); |
| 1762 | | 1834 | |
| ... | @@ -1805,7 +1877,8 @@ fn simpleBinOp( | ... | @@ -1805,7 +1877,8 @@ fn simpleBinOp( |
| 1805 | rl: ResultLoc, | 1877 | rl: ResultLoc, |
| 1806 | infix_node: ast.Node.Index, | 1878 | infix_node: ast.Node.Index, |
| 1807 | op_inst_tag: zir.Inst.Tag, | 1879 | op_inst_tag: zir.Inst.Tag, |
| 1808 | ) InnerError!*zir.Inst { | 1880 | ) InnerError!zir.Inst.Ref { |
| | 1881 | if (true) @panic("TODO update for zir-memory-layout"); |
| 1809 | const tree = scope.tree(); | 1882 | const tree = scope.tree(); |
| 1810 | const node_datas = tree.nodes.items(.data); | 1883 | const node_datas = tree.nodes.items(.data); |
| 1811 | const main_tokens = tree.nodes.items(.main_token); | 1884 | const main_tokens = tree.nodes.items(.main_token); |
| ... | @@ -1824,7 +1897,8 @@ fn boolBinOp( | ... | @@ -1824,7 +1897,8 @@ fn boolBinOp( |
| 1824 | rl: ResultLoc, | 1897 | rl: ResultLoc, |
| 1825 | infix_node: ast.Node.Index, | 1898 | infix_node: ast.Node.Index, |
| 1826 | is_bool_and: bool, | 1899 | is_bool_and: bool, |
| 1827 | ) InnerError!*zir.Inst { | 1900 | ) InnerError!zir.Inst.Ref { |
| | 1901 | if (true) @panic("TODO update for zir-memory-layout"); |
| 1828 | const tree = scope.tree(); | 1902 | const tree = scope.tree(); |
| 1829 | const node_datas = tree.nodes.items(.data); | 1903 | const node_datas = tree.nodes.items(.data); |
| 1830 | const main_tokens = tree.nodes.items(.main_token); | 1904 | const main_tokens = tree.nodes.items(.main_token); |
| ... | @@ -1853,7 +1927,7 @@ fn boolBinOp( | ... | @@ -1853,7 +1927,7 @@ fn boolBinOp( |
| 1853 | }, .{}); | 1927 | }, .{}); |
| 1854 | | 1928 | |
| 1855 | const block = try addZIRInstBlock(mod, scope, src, .block, .{ | 1929 | const block = try addZIRInstBlock(mod, scope, src, .block, .{ |
| 1856 | .instructions = try block_scope.arena.dupe(*zir.Inst, block_scope.instructions.items), | 1930 | .instructions = try block_scope.arena.dupe(zir.Inst.Ref, block_scope.instructions.items), |
| 1857 | }); | 1931 | }); |
| 1858 | | 1932 | |
| 1859 | var rhs_scope: Scope.GenZir = .{ | 1933 | var rhs_scope: Scope.GenZir = .{ |
| ... | @@ -1893,15 +1967,15 @@ fn boolBinOp( | ... | @@ -1893,15 +1967,15 @@ fn boolBinOp( |
| 1893 | // break rhs | 1967 | // break rhs |
| 1894 | // else | 1968 | // else |
| 1895 | // break false | 1969 | // break false |
| 1896 | condbr.positionals.then_body = .{ .instructions = try rhs_scope.arena.dupe(*zir.Inst, rhs_scope.instructions.items) }; | 1970 | condbr.positionals.then_body = .{ .instructions = try rhs_scope.arena.dupe(zir.Inst.Ref, rhs_scope.instructions.items) }; |
| 1897 | condbr.positionals.else_body = .{ .instructions = try const_scope.arena.dupe(*zir.Inst, const_scope.instructions.items) }; | 1971 | condbr.positionals.else_body = .{ .instructions = try const_scope.arena.dupe(zir.Inst.Ref, const_scope.instructions.items) }; |
| 1898 | } else { | 1972 | } else { |
| 1899 | // if lhs // OR | 1973 | // if lhs // OR |
| 1900 | // break true | 1974 | // break true |
| 1901 | // else | 1975 | // else |
| 1902 | // break rhs | 1976 | // break rhs |
| 1903 | condbr.positionals.then_body = .{ .instructions = try const_scope.arena.dupe(*zir.Inst, const_scope.instructions.items) }; | 1977 | condbr.positionals.then_body = .{ .instructions = try const_scope.arena.dupe(zir.Inst.Ref, const_scope.instructions.items) }; |
| 1904 | condbr.positionals.else_body = .{ .instructions = try rhs_scope.arena.dupe(*zir.Inst, rhs_scope.instructions.items) }; | 1978 | condbr.positionals.else_body = .{ .instructions = try rhs_scope.arena.dupe(zir.Inst.Ref, rhs_scope.instructions.items) }; |
| 1905 | } | 1979 | } |
| 1906 | | 1980 | |
| 1907 | return rvalue(mod, scope, rl, &block.base); | 1981 | return rvalue(mod, scope, rl, &block.base); |
| ... | @@ -1912,7 +1986,8 @@ fn ifExpr( | ... | @@ -1912,7 +1986,8 @@ fn ifExpr( |
| 1912 | scope: *Scope, | 1986 | scope: *Scope, |
| 1913 | rl: ResultLoc, | 1987 | rl: ResultLoc, |
| 1914 | if_full: ast.full.If, | 1988 | if_full: ast.full.If, |
| 1915 | ) InnerError!*zir.Inst { | 1989 | ) InnerError!zir.Inst.Ref { |
| | 1990 | if (true) @panic("TODO update for zir-memory-layout"); |
| 1916 | var block_scope: Scope.GenZir = .{ | 1991 | var block_scope: Scope.GenZir = .{ |
| 1917 | .parent = scope, | 1992 | .parent = scope, |
| 1918 | .decl = scope.ownerDecl().?, | 1993 | .decl = scope.ownerDecl().?, |
| ... | @@ -1951,7 +2026,7 @@ fn ifExpr( | ... | @@ -1951,7 +2026,7 @@ fn ifExpr( |
| 1951 | }, .{}); | 2026 | }, .{}); |
| 1952 | | 2027 | |
| 1953 | const block = try addZIRInstBlock(mod, scope, if_src, .block, .{ | 2028 | const block = try addZIRInstBlock(mod, scope, if_src, .block, .{ |
| 1954 | .instructions = try block_scope.arena.dupe(*zir.Inst, block_scope.instructions.items), | 2029 | .instructions = try block_scope.arena.dupe(zir.Inst.Ref, block_scope.instructions.items), |
| 1955 | }); | 2030 | }); |
| 1956 | | 2031 | |
| 1957 | const then_src = token_starts[tree.lastToken(if_full.ast.then_expr)]; | 2032 | const then_src = token_starts[tree.lastToken(if_full.ast.then_expr)]; |
| ... | @@ -2016,7 +2091,7 @@ fn ifExpr( | ... | @@ -2016,7 +2091,7 @@ fn ifExpr( |
| 2016 | /// Expects to find exactly 1 .store_to_block_ptr instruction. | 2091 | /// Expects to find exactly 1 .store_to_block_ptr instruction. |
| 2017 | fn copyBodyWithElidedStoreBlockPtr(body: *zir.Body, scope: Module.Scope.GenZir) !void { | 2092 | fn copyBodyWithElidedStoreBlockPtr(body: *zir.Body, scope: Module.Scope.GenZir) !void { |
| 2018 | body.* = .{ | 2093 | body.* = .{ |
| 2019 | .instructions = try scope.arena.alloc(*zir.Inst, scope.instructions.items.len - 1), | 2094 | .instructions = try scope.arena.alloc(zir.Inst.Ref, scope.instructions.items.len - 1), |
| 2020 | }; | 2095 | }; |
| 2021 | var dst_index: usize = 0; | 2096 | var dst_index: usize = 0; |
| 2022 | for (scope.instructions.items) |src_inst| { | 2097 | for (scope.instructions.items) |src_inst| { |
| ... | @@ -2030,7 +2105,7 @@ fn copyBodyWithElidedStoreBlockPtr(body: *zir.Body, scope: Module.Scope.GenZir) | ... | @@ -2030,7 +2105,7 @@ fn copyBodyWithElidedStoreBlockPtr(body: *zir.Body, scope: Module.Scope.GenZir) |
| 2030 | | 2105 | |
| 2031 | fn copyBodyNoEliding(body: *zir.Body, scope: Module.Scope.GenZir) !void { | 2106 | fn copyBodyNoEliding(body: *zir.Body, scope: Module.Scope.GenZir) !void { |
| 2032 | body.* = .{ | 2107 | body.* = .{ |
| 2033 | .instructions = try scope.arena.dupe(*zir.Inst, scope.instructions.items), | 2108 | .instructions = try scope.arena.dupe(zir.Inst.Ref, scope.instructions.items), |
| 2034 | }; | 2109 | }; |
| 2035 | } | 2110 | } |
| 2036 | | 2111 | |
| ... | @@ -2039,7 +2114,8 @@ fn whileExpr( | ... | @@ -2039,7 +2114,8 @@ fn whileExpr( |
| 2039 | scope: *Scope, | 2114 | scope: *Scope, |
| 2040 | rl: ResultLoc, | 2115 | rl: ResultLoc, |
| 2041 | while_full: ast.full.While, | 2116 | while_full: ast.full.While, |
| 2042 | ) InnerError!*zir.Inst { | 2117 | ) InnerError!zir.Inst.Ref { |
| | 2118 | if (true) @panic("TODO update for zir-memory-layout"); |
| 2043 | if (while_full.label_token) |label_token| { | 2119 | if (while_full.label_token) |label_token| { |
| 2044 | try checkLabelRedefinition(mod, scope, label_token); | 2120 | try checkLabelRedefinition(mod, scope, label_token); |
| 2045 | } | 2121 | } |
| ... | @@ -2096,7 +2172,7 @@ fn whileExpr( | ... | @@ -2096,7 +2172,7 @@ fn whileExpr( |
| 2096 | .else_body = undefined, // populated below | 2172 | .else_body = undefined, // populated below |
| 2097 | }, .{}); | 2173 | }, .{}); |
| 2098 | const cond_block = try addZIRInstBlock(mod, &loop_scope.base, while_src, .block, .{ | 2174 | const cond_block = try addZIRInstBlock(mod, &loop_scope.base, while_src, .block, .{ |
| 2099 | .instructions = try loop_scope.arena.dupe(*zir.Inst, continue_scope.instructions.items), | 2175 | .instructions = try loop_scope.arena.dupe(zir.Inst.Ref, continue_scope.instructions.items), |
| 2100 | }); | 2176 | }); |
| 2101 | // TODO avoid emitting the continue expr when there | 2177 | // TODO avoid emitting the continue expr when there |
| 2102 | // are no jumps to it. This happens when the last statement of a while body is noreturn | 2178 | // are no jumps to it. This happens when the last statement of a while body is noreturn |
| ... | @@ -2113,13 +2189,13 @@ fn whileExpr( | ... | @@ -2113,13 +2189,13 @@ fn whileExpr( |
| 2113 | }, | 2189 | }, |
| 2114 | .positionals = .{ | 2190 | .positionals = .{ |
| 2115 | .body = .{ | 2191 | .body = .{ |
| 2116 | .instructions = try scope.arena().dupe(*zir.Inst, loop_scope.instructions.items), | 2192 | .instructions = try scope.arena().dupe(zir.Inst.Ref, loop_scope.instructions.items), |
| 2117 | }, | 2193 | }, |
| 2118 | }, | 2194 | }, |
| 2119 | .kw_args = .{}, | 2195 | .kw_args = .{}, |
| 2120 | }; | 2196 | }; |
| 2121 | const while_block = try addZIRInstBlock(mod, scope, while_src, .block, .{ | 2197 | const while_block = try addZIRInstBlock(mod, scope, while_src, .block, .{ |
| 2122 | .instructions = try scope.arena().dupe(*zir.Inst, &[1]*zir.Inst{&loop.base}), | 2198 | .instructions = try scope.arena().dupe(zir.Inst.Ref, &[1]zir.Inst.Ref{&loop.base}), |
| 2123 | }); | 2199 | }); |
| 2124 | loop_scope.break_block = while_block; | 2200 | loop_scope.break_block = while_block; |
| 2125 | loop_scope.continue_block = cond_block; | 2201 | loop_scope.continue_block = cond_block; |
| ... | @@ -2195,7 +2271,8 @@ fn forExpr( | ... | @@ -2195,7 +2271,8 @@ fn forExpr( |
| 2195 | scope: *Scope, | 2271 | scope: *Scope, |
| 2196 | rl: ResultLoc, | 2272 | rl: ResultLoc, |
| 2197 | for_full: ast.full.While, | 2273 | for_full: ast.full.While, |
| 2198 | ) InnerError!*zir.Inst { | 2274 | ) InnerError!zir.Inst.Ref { |
| | 2275 | if (true) @panic("TODO update for zir-memory-layout"); |
| 2199 | if (for_full.label_token) |label_token| { | 2276 | if (for_full.label_token) |label_token| { |
| 2200 | try checkLabelRedefinition(mod, scope, label_token); | 2277 | try checkLabelRedefinition(mod, scope, label_token); |
| 2201 | } | 2278 | } |
| ... | @@ -2258,7 +2335,7 @@ fn forExpr( | ... | @@ -2258,7 +2335,7 @@ fn forExpr( |
| 2258 | .else_body = undefined, // populated below | 2335 | .else_body = undefined, // populated below |
| 2259 | }, .{}); | 2336 | }, .{}); |
| 2260 | const cond_block = try addZIRInstBlock(mod, &loop_scope.base, for_src, .block, .{ | 2337 | const cond_block = try addZIRInstBlock(mod, &loop_scope.base, for_src, .block, .{ |
| 2261 | .instructions = try loop_scope.arena.dupe(*zir.Inst, cond_scope.instructions.items), | 2338 | .instructions = try loop_scope.arena.dupe(zir.Inst.Ref, cond_scope.instructions.items), |
| 2262 | }); | 2339 | }); |
| 2263 | | 2340 | |
| 2264 | // increment index variable | 2341 | // increment index variable |
| ... | @@ -2278,13 +2355,13 @@ fn forExpr( | ... | @@ -2278,13 +2355,13 @@ fn forExpr( |
| 2278 | }, | 2355 | }, |
| 2279 | .positionals = .{ | 2356 | .positionals = .{ |
| 2280 | .body = .{ | 2357 | .body = .{ |
| 2281 | .instructions = try scope.arena().dupe(*zir.Inst, loop_scope.instructions.items), | 2358 | .instructions = try scope.arena().dupe(zir.Inst.Ref, loop_scope.instructions.items), |
| 2282 | }, | 2359 | }, |
| 2283 | }, | 2360 | }, |
| 2284 | .kw_args = .{}, | 2361 | .kw_args = .{}, |
| 2285 | }; | 2362 | }; |
| 2286 | const for_block = try addZIRInstBlock(mod, scope, for_src, .block, .{ | 2363 | const for_block = try addZIRInstBlock(mod, scope, for_src, .block, .{ |
| 2287 | .instructions = try scope.arena().dupe(*zir.Inst, &[1]*zir.Inst{&loop.base}), | 2364 | .instructions = try scope.arena().dupe(zir.Inst.Ref, &[1]zir.Inst.Ref{&loop.base}), |
| 2288 | }); | 2365 | }); |
| 2289 | loop_scope.break_block = for_block; | 2366 | loop_scope.break_block = for_block; |
| 2290 | loop_scope.continue_block = cond_block; | 2367 | loop_scope.continue_block = cond_block; |
| ... | @@ -2407,7 +2484,8 @@ fn switchExpr( | ... | @@ -2407,7 +2484,8 @@ fn switchExpr( |
| 2407 | scope: *Scope, | 2484 | scope: *Scope, |
| 2408 | rl: ResultLoc, | 2485 | rl: ResultLoc, |
| 2409 | switch_node: ast.Node.Index, | 2486 | switch_node: ast.Node.Index, |
| 2410 | ) InnerError!*zir.Inst { | 2487 | ) InnerError!zir.Inst.Ref { |
| | 2488 | if (true) @panic("TODO update for zir-memory-layout"); |
| 2411 | const tree = scope.tree(); | 2489 | const tree = scope.tree(); |
| 2412 | const node_datas = tree.nodes.items(.data); | 2490 | const node_datas = tree.nodes.items(.data); |
| 2413 | const main_tokens = tree.nodes.items(.main_token); | 2491 | const main_tokens = tree.nodes.items(.main_token); |
| ... | @@ -2432,7 +2510,7 @@ fn switchExpr( | ... | @@ -2432,7 +2510,7 @@ fn switchExpr( |
| 2432 | setBlockResultLoc(&block_scope, rl); | 2510 | setBlockResultLoc(&block_scope, rl); |
| 2433 | defer block_scope.instructions.deinit(mod.gpa); | 2511 | defer block_scope.instructions.deinit(mod.gpa); |
| 2434 | | 2512 | |
| 2435 | var items = std.ArrayList(*zir.Inst).init(mod.gpa); | 2513 | var items = std.ArrayList(zir.Inst.Ref).init(mod.gpa); |
| 2436 | defer items.deinit(); | 2514 | defer items.deinit(); |
| 2437 | | 2515 | |
| 2438 | // First we gather all the switch items and check else/'_' prongs. | 2516 | // First we gather all the switch items and check else/'_' prongs. |
| ... | @@ -2549,13 +2627,13 @@ fn switchExpr( | ... | @@ -2549,13 +2627,13 @@ fn switchExpr( |
| 2549 | const switch_inst = try addZirInstT(mod, &block_scope.base, switch_src, zir.Inst.SwitchBr, rl_and_tag.tag, .{ | 2627 | const switch_inst = try addZirInstT(mod, &block_scope.base, switch_src, zir.Inst.SwitchBr, rl_and_tag.tag, .{ |
| 2550 | .target = target, | 2628 | .target = target, |
| 2551 | .cases = cases, | 2629 | .cases = cases, |
| 2552 | .items = try block_scope.arena.dupe(*zir.Inst, items.items), | 2630 | .items = try block_scope.arena.dupe(zir.Inst.Ref, items.items), |
| 2553 | .else_body = undefined, // populated below | 2631 | .else_body = undefined, // populated below |
| 2554 | .range = first_range, | 2632 | .range = first_range, |
| 2555 | .special_prong = special_prong, | 2633 | .special_prong = special_prong, |
| 2556 | }); | 2634 | }); |
| 2557 | const block = try addZIRInstBlock(mod, scope, switch_src, .block, .{ | 2635 | const block = try addZIRInstBlock(mod, scope, switch_src, .block, .{ |
| 2558 | .instructions = try block_scope.arena.dupe(*zir.Inst, block_scope.instructions.items), | 2636 | .instructions = try block_scope.arena.dupe(zir.Inst.Ref, block_scope.instructions.items), |
| 2559 | }); | 2637 | }); |
| 2560 | | 2638 | |
| 2561 | var case_scope: Scope.GenZir = .{ | 2639 | var case_scope: Scope.GenZir = .{ |
| ... | @@ -2611,7 +2689,7 @@ fn switchExpr( | ... | @@ -2611,7 +2689,7 @@ fn switchExpr( |
| 2611 | | 2689 | |
| 2612 | cases[case_index] = .{ | 2690 | cases[case_index] = .{ |
| 2613 | .item = item, | 2691 | .item = item, |
| 2614 | .body = .{ .instructions = try scope.arena().dupe(*zir.Inst, case_scope.instructions.items) }, | 2692 | .body = .{ .instructions = try scope.arena().dupe(zir.Inst.Ref, case_scope.instructions.items) }, |
| 2615 | }; | 2693 | }; |
| 2616 | case_index += 1; | 2694 | case_index += 1; |
| 2617 | continue; | 2695 | continue; |
| ... | @@ -2658,14 +2736,14 @@ fn switchExpr( | ... | @@ -2658,14 +2736,14 @@ fn switchExpr( |
| 2658 | .else_body = undefined, // populated below | 2736 | .else_body = undefined, // populated below |
| 2659 | }, .{}); | 2737 | }, .{}); |
| 2660 | const cond_block = try addZIRInstBlock(mod, &else_scope.base, case_src, .block, .{ | 2738 | const cond_block = try addZIRInstBlock(mod, &else_scope.base, case_src, .block, .{ |
| 2661 | .instructions = try scope.arena().dupe(*zir.Inst, case_scope.instructions.items), | 2739 | .instructions = try scope.arena().dupe(zir.Inst.Ref, case_scope.instructions.items), |
| 2662 | }); | 2740 | }); |
| 2663 | | 2741 | |
| 2664 | // reset cond_scope for then_body | 2742 | // reset cond_scope for then_body |
| 2665 | case_scope.instructions.items.len = 0; | 2743 | case_scope.instructions.items.len = 0; |
| 2666 | try switchCaseExpr(mod, &case_scope.base, block_scope.break_result_loc, block, case, target); | 2744 | try switchCaseExpr(mod, &case_scope.base, block_scope.break_result_loc, block, case, target); |
| 2667 | condbr.positionals.then_body = .{ | 2745 | condbr.positionals.then_body = .{ |
| 2668 | .instructions = try scope.arena().dupe(*zir.Inst, case_scope.instructions.items), | 2746 | .instructions = try scope.arena().dupe(zir.Inst.Ref, case_scope.instructions.items), |
| 2669 | }; | 2747 | }; |
| 2670 | | 2748 | |
| 2671 | // reset cond_scope for else_body | 2749 | // reset cond_scope for else_body |
| ... | @@ -2674,7 +2752,7 @@ fn switchExpr( | ... | @@ -2674,7 +2752,7 @@ fn switchExpr( |
| 2674 | .block = cond_block, | 2752 | .block = cond_block, |
| 2675 | }, .{}); | 2753 | }, .{}); |
| 2676 | condbr.positionals.else_body = .{ | 2754 | condbr.positionals.else_body = .{ |
| 2677 | .instructions = try scope.arena().dupe(*zir.Inst, case_scope.instructions.items), | 2755 | .instructions = try scope.arena().dupe(zir.Inst.Ref, case_scope.instructions.items), |
| 2678 | }; | 2756 | }; |
| 2679 | } | 2757 | } |
| 2680 | | 2758 | |
| ... | @@ -2686,7 +2764,7 @@ fn switchExpr( | ... | @@ -2686,7 +2764,7 @@ fn switchExpr( |
| 2686 | _ = try addZIRNoOp(mod, &else_scope.base, switch_src, .unreachable_unsafe); | 2764 | _ = try addZIRNoOp(mod, &else_scope.base, switch_src, .unreachable_unsafe); |
| 2687 | } | 2765 | } |
| 2688 | switch_inst.positionals.else_body = .{ | 2766 | switch_inst.positionals.else_body = .{ |
| 2689 | .instructions = try block_scope.arena.dupe(*zir.Inst, else_scope.instructions.items), | 2767 | .instructions = try block_scope.arena.dupe(zir.Inst.Ref, else_scope.instructions.items), |
| 2690 | }; | 2768 | }; |
| 2691 | | 2769 | |
| 2692 | return &block.base; | 2770 | return &block.base; |
| ... | @@ -2698,7 +2776,7 @@ fn switchCaseExpr( | ... | @@ -2698,7 +2776,7 @@ fn switchCaseExpr( |
| 2698 | rl: ResultLoc, | 2776 | rl: ResultLoc, |
| 2699 | block: *zir.Inst.Block, | 2777 | block: *zir.Inst.Block, |
| 2700 | case: ast.full.SwitchCase, | 2778 | case: ast.full.SwitchCase, |
| 2701 | target: *zir.Inst, | 2779 | target: zir.Inst.Ref, |
| 2702 | ) !void { | 2780 | ) !void { |
| 2703 | const tree = scope.tree(); | 2781 | const tree = scope.tree(); |
| 2704 | const node_datas = tree.nodes.items(.data); | 2782 | const node_datas = tree.nodes.items(.data); |
| ... | @@ -2733,27 +2811,22 @@ fn switchCaseExpr( | ... | @@ -2733,27 +2811,22 @@ fn switchCaseExpr( |
| 2733 | } | 2811 | } |
| 2734 | } | 2812 | } |
| 2735 | | 2813 | |
| 2736 | fn ret(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!*zir.Inst { | 2814 | fn ret(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!zir.Inst.Ref { |
| 2737 | const tree = scope.tree(); | 2815 | const tree = scope.tree(); |
| 2738 | const node_datas = tree.nodes.items(.data); | 2816 | const node_datas = tree.nodes.items(.data); |
| 2739 | const main_tokens = tree.nodes.items(.main_token); | 2817 | const main_tokens = tree.nodes.items(.main_token); |
| 2740 | const token_starts = tree.tokens.items(.start); | | |
| 2741 | | 2818 | |
| 2742 | const src = token_starts[main_tokens[node]]; | 2819 | const operand_node = node_datas[node].lhs; |
| 2743 | const rhs_node = node_datas[node].lhs; | 2820 | const gz = scope.getGenZir(); |
| 2744 | if (rhs_node != 0) { | 2821 | const operand: zir.Inst.Ref = if (operand_node != 0) operand: { |
| 2745 | if (nodeMayNeedMemoryLocation(scope, rhs_node)) { | 2822 | const rl: ResultLoc = if (nodeMayNeedMemoryLocation(scope, operand_node)) .{ |
| 2746 | const ret_ptr = try addZIRNoOp(mod, scope, src, .ret_ptr); | 2823 | .ptr = try gz.addNode(.ret_ptr, node), |
| 2747 | const operand = try expr(mod, scope, .{ .ptr = ret_ptr }, rhs_node); | 2824 | } else .{ |
| 2748 | return addZIRUnOp(mod, scope, src, .@"return", operand); | 2825 | .ty = try gz.addNode(.ret_type, node), |
| 2749 | } else { | 2826 | }; |
| 2750 | const fn_ret_ty = try addZIRNoOp(mod, scope, src, .ret_type); | 2827 | break :operand try expr(mod, scope, rl, operand_node); |
| 2751 | const operand = try expr(mod, scope, .{ .ty = fn_ret_ty }, rhs_node); | 2828 | } else void_inst; |
| 2752 | return addZIRUnOp(mod, scope, src, .@"return", operand); | 2829 | return gz.addUnNode(.ret_node, operand, node); |
| 2753 | } | | |
| 2754 | } else { | | |
| 2755 | return addZIRNoOp(mod, scope, src, .return_void); | | |
| 2756 | } | | |
| 2757 | } | 2830 | } |
| 2758 | | 2831 | |
| 2759 | fn identifier( | 2832 | fn identifier( |
| ... | @@ -2761,7 +2834,8 @@ fn identifier( | ... | @@ -2761,7 +2834,8 @@ fn identifier( |
| 2761 | scope: *Scope, | 2834 | scope: *Scope, |
| 2762 | rl: ResultLoc, | 2835 | rl: ResultLoc, |
| 2763 | ident: ast.Node.Index, | 2836 | ident: ast.Node.Index, |
| 2764 | ) InnerError!*zir.Inst { | 2837 | ) InnerError!zir.Inst.Ref { |
| | 2838 | if (true) @panic("TODO update for zir-memory-layout"); |
| 2765 | const tracy = trace(@src()); | 2839 | const tracy = trace(@src()); |
| 2766 | defer tracy.end(); | 2840 | defer tracy.end(); |
| 2767 | | 2841 | |
| ... | @@ -2882,7 +2956,8 @@ fn stringLiteral( | ... | @@ -2882,7 +2956,8 @@ fn stringLiteral( |
| 2882 | scope: *Scope, | 2956 | scope: *Scope, |
| 2883 | rl: ResultLoc, | 2957 | rl: ResultLoc, |
| 2884 | str_lit: ast.Node.Index, | 2958 | str_lit: ast.Node.Index, |
| 2885 | ) InnerError!*zir.Inst { | 2959 | ) InnerError!zir.Inst.Ref { |
| | 2960 | if (true) @panic("TODO update for zir-memory-layout"); |
| 2886 | const tree = scope.tree(); | 2961 | const tree = scope.tree(); |
| 2887 | const main_tokens = tree.nodes.items(.main_token); | 2962 | const main_tokens = tree.nodes.items(.main_token); |
| 2888 | const token_starts = tree.tokens.items(.start); | 2963 | const token_starts = tree.tokens.items(.start); |
| ... | @@ -2899,7 +2974,8 @@ fn multilineStringLiteral( | ... | @@ -2899,7 +2974,8 @@ fn multilineStringLiteral( |
| 2899 | scope: *Scope, | 2974 | scope: *Scope, |
| 2900 | rl: ResultLoc, | 2975 | rl: ResultLoc, |
| 2901 | str_lit: ast.Node.Index, | 2976 | str_lit: ast.Node.Index, |
| 2902 | ) InnerError!*zir.Inst { | 2977 | ) InnerError!zir.Inst.Ref { |
| | 2978 | if (true) @panic("TODO update for zir-memory-layout"); |
| 2903 | const tree = scope.tree(); | 2979 | const tree = scope.tree(); |
| 2904 | const node_datas = tree.nodes.items(.data); | 2980 | const node_datas = tree.nodes.items(.data); |
| 2905 | const main_tokens = tree.nodes.items(.main_token); | 2981 | const main_tokens = tree.nodes.items(.main_token); |
| ... | @@ -2943,7 +3019,8 @@ fn multilineStringLiteral( | ... | @@ -2943,7 +3019,8 @@ fn multilineStringLiteral( |
| 2943 | return rvalue(mod, scope, rl, str_inst); | 3019 | return rvalue(mod, scope, rl, str_inst); |
| 2944 | } | 3020 | } |
| 2945 | | 3021 | |
| 2946 | fn charLiteral(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) !*zir.Inst { | 3022 | fn charLiteral(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) !zir.Inst.Ref { |
| | 3023 | if (true) @panic("TODO update for zir-memory-layout"); |
| 2947 | const tree = scope.tree(); | 3024 | const tree = scope.tree(); |
| 2948 | const main_tokens = tree.nodes.items(.main_token); | 3025 | const main_tokens = tree.nodes.items(.main_token); |
| 2949 | const main_token = main_tokens[node]; | 3026 | const main_token = main_tokens[node]; |
| ... | @@ -2970,11 +3047,11 @@ fn integerLiteral( | ... | @@ -2970,11 +3047,11 @@ fn integerLiteral( |
| 2970 | mod: *Module, | 3047 | mod: *Module, |
| 2971 | scope: *Scope, | 3048 | scope: *Scope, |
| 2972 | rl: ResultLoc, | 3049 | rl: ResultLoc, |
| 2973 | int_lit: ast.Node.Index, | 3050 | node: ast.Node.Index, |
| 2974 | ) InnerError!*zir.Inst { | 3051 | ) InnerError!zir.Inst.Ref { |
| 2975 | const tree = scope.tree(); | 3052 | const tree = scope.tree(); |
| 2976 | const main_tokens = tree.nodes.items(.main_token); | 3053 | const main_tokens = tree.nodes.items(.main_token); |
| 2977 | const int_token = main_tokens[int_lit]; | 3054 | const int_token = main_tokens[node]; |
| 2978 | const prefixed_bytes = tree.tokenSlice(int_token); | 3055 | const prefixed_bytes = tree.tokenSlice(int_token); |
| 2979 | const gz = scope.getGenZir(); | 3056 | const gz = scope.getGenZir(); |
| 2980 | if (std.fmt.parseInt(u64, prefixed_bytes, 0)) |small_int| { | 3057 | if (std.fmt.parseInt(u64, prefixed_bytes, 0)) |small_int| { |
| ... | @@ -2983,9 +3060,9 @@ fn integerLiteral( | ... | @@ -2983,9 +3060,9 @@ fn integerLiteral( |
| 2983 | 1 => @enumToInt(zir.Const.one), | 3060 | 1 => @enumToInt(zir.Const.one), |
| 2984 | else => try gz.addInt(small_int), | 3061 | else => try gz.addInt(small_int), |
| 2985 | }; | 3062 | }; |
| 2986 | return rvalue(mod, scope, rl, result); | 3063 | return rvalue(mod, scope, rl, result, node); |
| 2987 | } else |err| { | 3064 | } else |err| { |
| 2988 | return mod.failTok(scope, int_token, "TODO implement int literals that don't fit in a u64", .{}); | 3065 | return mod.failNode(scope, node, "TODO implement int literals that don't fit in a u64", .{}); |
| 2989 | } | 3066 | } |
| 2990 | } | 3067 | } |
| 2991 | | 3068 | |
| ... | @@ -2994,7 +3071,8 @@ fn floatLiteral( | ... | @@ -2994,7 +3071,8 @@ fn floatLiteral( |
| 2994 | scope: *Scope, | 3071 | scope: *Scope, |
| 2995 | rl: ResultLoc, | 3072 | rl: ResultLoc, |
| 2996 | float_lit: ast.Node.Index, | 3073 | float_lit: ast.Node.Index, |
| 2997 | ) InnerError!*zir.Inst { | 3074 | ) InnerError!zir.Inst.Ref { |
| | 3075 | if (true) @panic("TODO update for zir-memory-layout"); |
| 2998 | const arena = scope.arena(); | 3076 | const arena = scope.arena(); |
| 2999 | const tree = scope.tree(); | 3077 | const tree = scope.tree(); |
| 3000 | const main_tokens = tree.nodes.items(.main_token); | 3078 | const main_tokens = tree.nodes.items(.main_token); |
| ... | @@ -3016,7 +3094,8 @@ fn floatLiteral( | ... | @@ -3016,7 +3094,8 @@ fn floatLiteral( |
| 3016 | return rvalue(mod, scope, rl, result); | 3094 | return rvalue(mod, scope, rl, result); |
| 3017 | } | 3095 | } |
| 3018 | | 3096 | |
| 3019 | fn asmExpr(mod: *Module, scope: *Scope, rl: ResultLoc, full: ast.full.Asm) InnerError!*zir.Inst { | 3097 | fn asmExpr(mod: *Module, scope: *Scope, rl: ResultLoc, full: ast.full.Asm) InnerError!zir.Inst.Ref { |
| | 3098 | if (true) @panic("TODO update for zir-memory-layout"); |
| 3020 | const arena = scope.arena(); | 3099 | const arena = scope.arena(); |
| 3021 | const tree = scope.tree(); | 3100 | const tree = scope.tree(); |
| 3022 | const main_tokens = tree.nodes.items(.main_token); | 3101 | const main_tokens = tree.nodes.items(.main_token); |
| ... | @@ -3028,7 +3107,7 @@ fn asmExpr(mod: *Module, scope: *Scope, rl: ResultLoc, full: ast.full.Asm) Inner | ... | @@ -3028,7 +3107,7 @@ fn asmExpr(mod: *Module, scope: *Scope, rl: ResultLoc, full: ast.full.Asm) Inner |
| 3028 | } | 3107 | } |
| 3029 | | 3108 | |
| 3030 | const inputs = try arena.alloc([]const u8, full.inputs.len); | 3109 | const inputs = try arena.alloc([]const u8, full.inputs.len); |
| 3031 | const args = try arena.alloc(*zir.Inst, full.inputs.len); | 3110 | const args = try arena.alloc(zir.Inst.Ref, full.inputs.len); |
| 3032 | | 3111 | |
| 3033 | const src = token_starts[full.ast.asm_token]; | 3112 | const src = token_starts[full.ast.asm_token]; |
| 3034 | const str_type = try addZIRInstConst(mod, scope, src, .{ | 3113 | const str_type = try addZIRInstConst(mod, scope, src, .{ |
| ... | @@ -3068,7 +3147,7 @@ fn as( | ... | @@ -3068,7 +3147,7 @@ fn as( |
| 3068 | src: usize, | 3147 | src: usize, |
| 3069 | lhs: ast.Node.Index, | 3148 | lhs: ast.Node.Index, |
| 3070 | rhs: ast.Node.Index, | 3149 | rhs: ast.Node.Index, |
| 3071 | ) InnerError!*zir.Inst { | 3150 | ) InnerError!zir.Inst.Ref { |
| 3072 | const dest_type = try typeExpr(mod, scope, lhs); | 3151 | const dest_type = try typeExpr(mod, scope, lhs); |
| 3073 | switch (rl) { | 3152 | switch (rl) { |
| 3074 | .none, .discard, .ref, .ty => { | 3153 | .none, .discard, .ref, .ty => { |
| ... | @@ -3099,10 +3178,10 @@ fn asRlPtr( | ... | @@ -3099,10 +3178,10 @@ fn asRlPtr( |
| 3099 | scope: *Scope, | 3178 | scope: *Scope, |
| 3100 | rl: ResultLoc, | 3179 | rl: ResultLoc, |
| 3101 | src: usize, | 3180 | src: usize, |
| 3102 | result_ptr: *zir.Inst, | 3181 | result_ptr: zir.Inst.Ref, |
| 3103 | operand_node: ast.Node.Index, | 3182 | operand_node: ast.Node.Index, |
| 3104 | dest_type: *zir.Inst, | 3183 | dest_type: zir.Inst.Ref, |
| 3105 | ) InnerError!*zir.Inst { | 3184 | ) InnerError!zir.Inst.Ref { |
| 3106 | // Detect whether this expr() call goes into rvalue() to store the result into the | 3185 | // Detect whether this expr() call goes into rvalue() to store the result into the |
| 3107 | // result location. If it does, elide the coerce_result_ptr instruction | 3186 | // result location. If it does, elide the coerce_result_ptr instruction |
| 3108 | // as well as the store instruction, instead passing the result as an rvalue. | 3187 | // as well as the store instruction, instead passing the result as an rvalue. |
| ... | @@ -3146,7 +3225,7 @@ fn bitCast( | ... | @@ -3146,7 +3225,7 @@ fn bitCast( |
| 3146 | src: usize, | 3225 | src: usize, |
| 3147 | lhs: ast.Node.Index, | 3226 | lhs: ast.Node.Index, |
| 3148 | rhs: ast.Node.Index, | 3227 | rhs: ast.Node.Index, |
| 3149 | ) InnerError!*zir.Inst { | 3228 | ) InnerError!zir.Inst.Ref { |
| 3150 | const dest_type = try typeExpr(mod, scope, lhs); | 3229 | const dest_type = try typeExpr(mod, scope, lhs); |
| 3151 | switch (rl) { | 3230 | switch (rl) { |
| 3152 | .none => { | 3231 | .none => { |
| ... | @@ -3193,7 +3272,7 @@ fn typeOf( | ... | @@ -3193,7 +3272,7 @@ fn typeOf( |
| 3193 | builtin_token: ast.TokenIndex, | 3272 | builtin_token: ast.TokenIndex, |
| 3194 | src: usize, | 3273 | src: usize, |
| 3195 | params: []const ast.Node.Index, | 3274 | params: []const ast.Node.Index, |
| 3196 | ) InnerError!*zir.Inst { | 3275 | ) InnerError!zir.Inst.Ref { |
| 3197 | if (params.len < 1) { | 3276 | if (params.len < 1) { |
| 3198 | return mod.failTok(scope, builtin_token, "expected at least 1 argument, found 0", .{}); | 3277 | return mod.failTok(scope, builtin_token, "expected at least 1 argument, found 0", .{}); |
| 3199 | } | 3278 | } |
| ... | @@ -3201,7 +3280,7 @@ fn typeOf( | ... | @@ -3201,7 +3280,7 @@ fn typeOf( |
| 3201 | return rvalue(mod, scope, rl, try addZIRUnOp(mod, scope, src, .typeof, try expr(mod, scope, .none, params[0]))); | 3280 | return rvalue(mod, scope, rl, try addZIRUnOp(mod, scope, src, .typeof, try expr(mod, scope, .none, params[0]))); |
| 3202 | } | 3281 | } |
| 3203 | const arena = scope.arena(); | 3282 | const arena = scope.arena(); |
| 3204 | var items = try arena.alloc(*zir.Inst, params.len); | 3283 | var items = try arena.alloc(zir.Inst.Ref, params.len); |
| 3205 | for (params) |param, param_i| | 3284 | for (params) |param, param_i| |
| 3206 | items[param_i] = try expr(mod, scope, .none, param); | 3285 | items[param_i] = try expr(mod, scope, .none, param); |
| 3207 | return rvalue(mod, scope, rl, try addZIRInst(mod, scope, src, zir.Inst.TypeOfPeer, .{ .items = items }, .{})); | 3286 | return rvalue(mod, scope, rl, try addZIRInst(mod, scope, src, zir.Inst.TypeOfPeer, .{ .items = items }, .{})); |
| ... | @@ -3213,7 +3292,8 @@ fn builtinCall( | ... | @@ -3213,7 +3292,8 @@ fn builtinCall( |
| 3213 | rl: ResultLoc, | 3292 | rl: ResultLoc, |
| 3214 | call: ast.Node.Index, | 3293 | call: ast.Node.Index, |
| 3215 | params: []const ast.Node.Index, | 3294 | params: []const ast.Node.Index, |
| 3216 | ) InnerError!*zir.Inst { | 3295 | ) InnerError!zir.Inst.Ref { |
| | 3296 | if (true) @panic("TODO update for zir-memory-layout"); |
| 3217 | const tree = scope.tree(); | 3297 | const tree = scope.tree(); |
| 3218 | const main_tokens = tree.nodes.items(.main_token); | 3298 | const main_tokens = tree.nodes.items(.main_token); |
| 3219 | const token_starts = tree.tokens.items(.start); | 3299 | const token_starts = tree.tokens.items(.start); |
| ... | @@ -3284,7 +3364,7 @@ fn builtinCall( | ... | @@ -3284,7 +3364,7 @@ fn builtinCall( |
| 3284 | }, | 3364 | }, |
| 3285 | .compile_log => { | 3365 | .compile_log => { |
| 3286 | const arena = scope.arena(); | 3366 | const arena = scope.arena(); |
| 3287 | var targets = try arena.alloc(*zir.Inst, params.len); | 3367 | var targets = try arena.alloc(zir.Inst.Ref, params.len); |
| 3288 | for (params) |param, param_i| | 3368 | for (params) |param, param_i| |
| 3289 | targets[param_i] = try expr(mod, scope, .none, param); | 3369 | targets[param_i] = try expr(mod, scope, .none, param); |
| 3290 | const result = try addZIRInst(mod, scope, src, zir.Inst.CompileLog, .{ .to_log = targets }, .{}); | 3370 | const result = try addZIRInst(mod, scope, src, zir.Inst.CompileLog, .{ .to_log = targets }, .{}); |
| ... | @@ -3414,7 +3494,7 @@ fn callExpr( | ... | @@ -3414,7 +3494,7 @@ fn callExpr( |
| 3414 | rl: ResultLoc, | 3494 | rl: ResultLoc, |
| 3415 | node: ast.Node.Index, | 3495 | node: ast.Node.Index, |
| 3416 | call: ast.full.Call, | 3496 | call: ast.full.Call, |
| 3417 | ) InnerError!*zir.Inst { | 3497 | ) InnerError!zir.Inst.Ref { |
| 3418 | if (true) { | 3498 | if (true) { |
| 3419 | @panic("TODO update for zir-memory-layout branch"); | 3499 | @panic("TODO update for zir-memory-layout branch"); |
| 3420 | } | 3500 | } |
| ... | @@ -3459,7 +3539,7 @@ fn callExpr( | ... | @@ -3459,7 +3539,7 @@ fn callExpr( |
| 3459 | return rvalue(mod, scope, rl, result); // TODO function call with result location | 3539 | return rvalue(mod, scope, rl, result); // TODO function call with result location |
| 3460 | } | 3540 | } |
| 3461 | | 3541 | |
| 3462 | fn suspendExpr(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!*zir.Inst { | 3542 | fn suspendExpr(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!zir.Inst.Ref { |
| 3463 | const tree = scope.tree(); | 3543 | const tree = scope.tree(); |
| 3464 | const src = tree.tokens.items(.start)[tree.nodes.items(.main_token)[node]]; | 3544 | const src = tree.tokens.items(.start)[tree.nodes.items(.main_token)[node]]; |
| 3465 | | 3545 | |
| ... | @@ -3504,12 +3584,13 @@ fn suspendExpr(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!*zi | ... | @@ -3504,12 +3584,13 @@ fn suspendExpr(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!*zi |
| 3504 | } | 3584 | } |
| 3505 | | 3585 | |
| 3506 | const block = try addZIRInstBlock(mod, scope, src, .suspend_block, .{ | 3586 | const block = try addZIRInstBlock(mod, scope, src, .suspend_block, .{ |
| 3507 | .instructions = try scope.arena().dupe(*zir.Inst, suspend_scope.instructions.items), | 3587 | .instructions = try scope.arena().dupe(zir.Inst.Ref, suspend_scope.instructions.items), |
| 3508 | }); | 3588 | }); |
| 3509 | return &block.base; | 3589 | return &block.base; |
| 3510 | } | 3590 | } |
| 3511 | | 3591 | |
| 3512 | fn nosuspendExpr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerError!*zir.Inst { | 3592 | fn nosuspendExpr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerError!zir.Inst.Ref { |
| | 3593 | if (true) @panic("TODO update for zir-memory-layout"); |
| 3513 | const tree = scope.tree(); | 3594 | const tree = scope.tree(); |
| 3514 | var child_scope = Scope.Nosuspend{ | 3595 | var child_scope = Scope.Nosuspend{ |
| 3515 | .parent = scope, | 3596 | .parent = scope, |
| ... | @@ -3520,7 +3601,8 @@ fn nosuspendExpr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Inde | ... | @@ -3520,7 +3601,8 @@ fn nosuspendExpr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Inde |
| 3520 | return expr(mod, &child_scope.base, rl, tree.nodes.items(.data)[node].lhs); | 3601 | return expr(mod, &child_scope.base, rl, tree.nodes.items(.data)[node].lhs); |
| 3521 | } | 3602 | } |
| 3522 | | 3603 | |
| 3523 | fn awaitExpr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerError!*zir.Inst { | 3604 | fn awaitExpr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerError!zir.Inst.Ref { |
| | 3605 | if (true) @panic("TODO update for zir-memory-layout"); |
| 3524 | const tree = scope.tree(); | 3606 | const tree = scope.tree(); |
| 3525 | const src = tree.tokens.items(.start)[tree.nodes.items(.main_token)[node]]; | 3607 | const src = tree.tokens.items(.start)[tree.nodes.items(.main_token)[node]]; |
| 3526 | const is_nosuspend = scope.getNosuspend() != null; | 3608 | const is_nosuspend = scope.getNosuspend() != null; |
| ... | @@ -3542,7 +3624,7 @@ fn awaitExpr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) I | ... | @@ -3542,7 +3624,7 @@ fn awaitExpr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) I |
| 3542 | return addZIRUnOp(mod, scope, src, if (is_nosuspend) .nosuspend_await else .@"await", operand); | 3624 | return addZIRUnOp(mod, scope, src, if (is_nosuspend) .nosuspend_await else .@"await", operand); |
| 3543 | } | 3625 | } |
| 3544 | | 3626 | |
| 3545 | fn resumeExpr(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!*zir.Inst { | 3627 | fn resumeExpr(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!zir.Inst.Ref { |
| 3546 | const tree = scope.tree(); | 3628 | const tree = scope.tree(); |
| 3547 | const src = tree.tokens.items(.start)[tree.nodes.items(.main_token)[node]]; | 3629 | const src = tree.tokens.items(.start)[tree.nodes.items(.main_token)[node]]; |
| 3548 | | 3630 | |
| ... | @@ -3828,7 +3910,7 @@ fn rvalue( | ... | @@ -3828,7 +3910,7 @@ fn rvalue( |
| 3828 | // We need a pointer but we have a value. | 3910 | // We need a pointer but we have a value. |
| 3829 | const tree = scope.tree(); | 3911 | const tree = scope.tree(); |
| 3830 | const src_token = tree.firstToken(src_node); | 3912 | const src_token = tree.firstToken(src_node); |
| 3831 | return gz.addUnTok(.ref, result, src_tok); | 3913 | return gz.addUnTok(.ref, result, src_token); |
| 3832 | }, | 3914 | }, |
| 3833 | .ty => |ty_inst| return gz.addBin(.as, ty_inst, result), | 3915 | .ty => |ty_inst| return gz.addBin(.as, ty_inst, result), |
| 3834 | .ptr => |ptr_inst| { | 3916 | .ptr => |ptr_inst| { |
| ... | @@ -3844,31 +3926,12 @@ fn rvalue( | ... | @@ -3844,31 +3926,12 @@ fn rvalue( |
| 3844 | }, | 3926 | }, |
| 3845 | .block_ptr => |block_scope| { | 3927 | .block_ptr => |block_scope| { |
| 3846 | block_scope.rvalue_rl_count += 1; | 3928 | block_scope.rvalue_rl_count += 1; |
| 3847 | _ = try gz.addBin(.store_to_block_ptr, block_scope.rl_ptr.?, result); | 3929 | _ = try gz.addBin(.store_to_block_ptr, block_scope.rl_ptr, result); |
| 3848 | return result; | 3930 | return result; |
| 3849 | }, | 3931 | }, |
| 3850 | } | 3932 | } |
| 3851 | } | 3933 | } |
| 3852 | | 3934 | |
| 3853 | /// TODO when reworking ZIR memory layout, make the void value correspond to a hard coded | | |
| 3854 | /// index; that way this does not actually need to allocate anything. | | |
| 3855 | fn rvalueVoid( | | |
| 3856 | mod: *Module, | | |
| 3857 | scope: *Scope, | | |
| 3858 | rl: ResultLoc, | | |
| 3859 | node: ast.Node.Index, | | |
| 3860 | result: void, | | |
| 3861 | ) InnerError!*zir.Inst { | | |
| 3862 | const tree = scope.tree(); | | |
| 3863 | const main_tokens = tree.nodes.items(.main_token); | | |
| 3864 | const src = tree.tokens.items(.start)[tree.firstToken(node)]; | | |
| 3865 | const void_inst = try addZIRInstConst(mod, scope, src, .{ | | |
| 3866 | .ty = Type.initTag(.void), | | |
| 3867 | .val = Value.initTag(.void_value), | | |
| 3868 | }); | | |
| 3869 | return rvalue(mod, scope, rl, void_inst); | | |
| 3870 | } | | |
| 3871 | | | |
| 3872 | fn rlStrategy(rl: ResultLoc, block_scope: *Scope.GenZir) ResultLoc.Strategy { | 3935 | fn rlStrategy(rl: ResultLoc, block_scope: *Scope.GenZir) ResultLoc.Strategy { |
| 3873 | var elide_store_to_block_ptr_instructions = false; | 3936 | var elide_store_to_block_ptr_instructions = false; |
| 3874 | switch (rl) { | 3937 | switch (rl) { |
| ... | @@ -3953,190 +4016,3 @@ fn setBlockResultLoc(block_scope: *Scope.GenZir, parent_rl: ResultLoc) void { | ... | @@ -3953,190 +4016,3 @@ fn setBlockResultLoc(block_scope: *Scope.GenZir, parent_rl: ResultLoc) void { |
| 3953 | }, | 4016 | }, |
| 3954 | } | 4017 | } |
| 3955 | } | 4018 | } |
| 3956 | | | |
| 3957 | pub fn addZirInstTag( | | |
| 3958 | mod: *Module, | | |
| 3959 | scope: *Scope, | | |
| 3960 | src: usize, | | |
| 3961 | comptime tag: zir.Inst.Tag, | | |
| 3962 | positionals: std.meta.fieldInfo(tag.Type(), .positionals).field_type, | | |
| 3963 | ) !*zir.Inst { | | |
| 3964 | const gen_zir = scope.getGenZir(); | | |
| 3965 | try gen_zir.instructions.ensureCapacity(mod.gpa, gen_zir.instructions.items.len + 1); | | |
| 3966 | const inst = try gen_zir.arena.create(tag.Type()); | | |
| 3967 | inst.* = .{ | | |
| 3968 | .base = .{ | | |
| 3969 | .tag = tag, | | |
| 3970 | .src = src, | | |
| 3971 | }, | | |
| 3972 | .positionals = positionals, | | |
| 3973 | .kw_args = .{}, | | |
| 3974 | }; | | |
| 3975 | gen_zir.instructions.appendAssumeCapacity(&inst.base); | | |
| 3976 | return &inst.base; | | |
| 3977 | } | | |
| 3978 | | | |
| 3979 | pub fn addZirInstT( | | |
| 3980 | mod: *Module, | | |
| 3981 | scope: *Scope, | | |
| 3982 | src: usize, | | |
| 3983 | comptime T: type, | | |
| 3984 | tag: zir.Inst.Tag, | | |
| 3985 | positionals: std.meta.fieldInfo(T, .positionals).field_type, | | |
| 3986 | ) !*T { | | |
| 3987 | const gen_zir = scope.getGenZir(); | | |
| 3988 | try gen_zir.instructions.ensureCapacity(mod.gpa, gen_zir.instructions.items.len + 1); | | |
| 3989 | const inst = try gen_zir.arena.create(T); | | |
| 3990 | inst.* = .{ | | |
| 3991 | .base = .{ | | |
| 3992 | .tag = tag, | | |
| 3993 | .src = src, | | |
| 3994 | }, | | |
| 3995 | .positionals = positionals, | | |
| 3996 | .kw_args = .{}, | | |
| 3997 | }; | | |
| 3998 | gen_zir.instructions.appendAssumeCapacity(&inst.base); | | |
| 3999 | return inst; | | |
| 4000 | } | | |
| 4001 | | | |
| 4002 | pub fn addZIRInstSpecial( | | |
| 4003 | mod: *Module, | | |
| 4004 | scope: *Scope, | | |
| 4005 | src: usize, | | |
| 4006 | comptime T: type, | | |
| 4007 | positionals: std.meta.fieldInfo(T, .positionals).field_type, | | |
| 4008 | kw_args: std.meta.fieldInfo(T, .kw_args).field_type, | | |
| 4009 | ) !*T { | | |
| 4010 | const gen_zir = scope.getGenZir(); | | |
| 4011 | try gen_zir.instructions.ensureCapacity(mod.gpa, gen_zir.instructions.items.len + 1); | | |
| 4012 | const inst = try gen_zir.arena.create(T); | | |
| 4013 | inst.* = .{ | | |
| 4014 | .base = .{ | | |
| 4015 | .tag = T.base_tag, | | |
| 4016 | .src = src, | | |
| 4017 | }, | | |
| 4018 | .positionals = positionals, | | |
| 4019 | .kw_args = kw_args, | | |
| 4020 | }; | | |
| 4021 | gen_zir.instructions.appendAssumeCapacity(&inst.base); | | |
| 4022 | return inst; | | |
| 4023 | } | | |
| 4024 | | | |
| 4025 | pub fn addZIRNoOpT(mod: *Module, scope: *Scope, src: usize, tag: zir.Inst.Tag) !*zir.Inst.NoOp { | | |
| 4026 | const gen_zir = scope.getGenZir(); | | |
| 4027 | try gen_zir.instructions.ensureCapacity(mod.gpa, gen_zir.instructions.items.len + 1); | | |
| 4028 | const inst = try gen_zir.arena.create(zir.Inst.NoOp); | | |
| 4029 | inst.* = .{ | | |
| 4030 | .base = .{ | | |
| 4031 | .tag = tag, | | |
| 4032 | .src = src, | | |
| 4033 | }, | | |
| 4034 | .positionals = .{}, | | |
| 4035 | .kw_args = .{}, | | |
| 4036 | }; | | |
| 4037 | gen_zir.instructions.appendAssumeCapacity(&inst.base); | | |
| 4038 | return inst; | | |
| 4039 | } | | |
| 4040 | | | |
| 4041 | pub fn addZIRNoOp(mod: *Module, scope: *Scope, src: usize, tag: zir.Inst.Tag) !*zir.Inst { | | |
| 4042 | const inst = try addZIRNoOpT(mod, scope, src, tag); | | |
| 4043 | return &inst.base; | | |
| 4044 | } | | |
| 4045 | | | |
| 4046 | pub fn addZIRUnOp( | | |
| 4047 | mod: *Module, | | |
| 4048 | scope: *Scope, | | |
| 4049 | src: usize, | | |
| 4050 | tag: zir.Inst.Tag, | | |
| 4051 | operand: *zir.Inst, | | |
| 4052 | ) !*zir.Inst { | | |
| 4053 | const gen_zir = scope.getGenZir(); | | |
| 4054 | try gen_zir.instructions.ensureCapacity(mod.gpa, gen_zir.instructions.items.len + 1); | | |
| 4055 | const inst = try gen_zir.arena.create(zir.Inst.UnOp); | | |
| 4056 | inst.* = .{ | | |
| 4057 | .base = .{ | | |
| 4058 | .tag = tag, | | |
| 4059 | .src = src, | | |
| 4060 | }, | | |
| 4061 | .positionals = .{ | | |
| 4062 | .operand = operand, | | |
| 4063 | }, | | |
| 4064 | .kw_args = .{}, | | |
| 4065 | }; | | |
| 4066 | gen_zir.instructions.appendAssumeCapacity(&inst.base); | | |
| 4067 | return &inst.base; | | |
| 4068 | } | | |
| 4069 | | | |
| 4070 | pub fn addZIRBinOp( | | |
| 4071 | mod: *Module, | | |
| 4072 | scope: *Scope, | | |
| 4073 | src: usize, | | |
| 4074 | tag: zir.Inst.Tag, | | |
| 4075 | lhs: *zir.Inst, | | |
| 4076 | rhs: *zir.Inst, | | |
| 4077 | ) !*zir.Inst { | | |
| 4078 | const gen_zir = scope.getGenZir(); | | |
| 4079 | try gen_zir.instructions.ensureCapacity(mod.gpa, gen_zir.instructions.items.len + 1); | | |
| 4080 | const inst = try gen_zir.arena.create(zir.Inst.BinOp); | | |
| 4081 | inst.* = .{ | | |
| 4082 | .base = .{ | | |
| 4083 | .tag = tag, | | |
| 4084 | .src = src, | | |
| 4085 | }, | | |
| 4086 | .positionals = .{ | | |
| 4087 | .lhs = lhs, | | |
| 4088 | .rhs = rhs, | | |
| 4089 | }, | | |
| 4090 | .kw_args = .{}, | | |
| 4091 | }; | | |
| 4092 | gen_zir.instructions.appendAssumeCapacity(&inst.base); | | |
| 4093 | return &inst.base; | | |
| 4094 | } | | |
| 4095 | | | |
| 4096 | pub fn addZIRInstBlock( | | |
| 4097 | mod: *Module, | | |
| 4098 | scope: *Scope, | | |
| 4099 | src: usize, | | |
| 4100 | tag: zir.Inst.Tag, | | |
| 4101 | body: zir.Body, | | |
| 4102 | ) !*zir.Inst.Block { | | |
| 4103 | const gen_zir = scope.getGenZir(); | | |
| 4104 | try gen_zir.instructions.ensureCapacity(mod.gpa, gen_zir.instructions.items.len + 1); | | |
| 4105 | const inst = try gen_zir.arena.create(zir.Inst.Block); | | |
| 4106 | inst.* = .{ | | |
| 4107 | .base = .{ | | |
| 4108 | .tag = tag, | | |
| 4109 | .src = src, | | |
| 4110 | }, | | |
| 4111 | .positionals = .{ | | |
| 4112 | .body = body, | | |
| 4113 | }, | | |
| 4114 | .kw_args = .{}, | | |
| 4115 | }; | | |
| 4116 | gen_zir.instructions.appendAssumeCapacity(&inst.base); | | |
| 4117 | return inst; | | |
| 4118 | } | | |
| 4119 | | | |
| 4120 | pub fn addZIRInst( | | |
| 4121 | mod: *Module, | | |
| 4122 | scope: *Scope, | | |
| 4123 | src: usize, | | |
| 4124 | comptime T: type, | | |
| 4125 | positionals: std.meta.fieldInfo(T, .positionals).field_type, | | |
| 4126 | kw_args: std.meta.fieldInfo(T, .kw_args).field_type, | | |
| 4127 | ) !*zir.Inst { | | |
| 4128 | const inst_special = try addZIRInstSpecial(mod, scope, src, T, positionals, kw_args); | | |
| 4129 | return &inst_special.base; | | |
| 4130 | } | | |
| 4131 | | | |
| 4132 | /// TODO The existence of this function is a workaround for a bug in stage1. | | |
| 4133 | pub fn addZIRInstConst(mod: *Module, scope: *Scope, src: usize, typed_value: TypedValue) !*zir.Inst { | | |
| 4134 | const P = std.meta.fieldInfo(zir.Inst.Const, .positionals).field_type; | | |
| 4135 | return addZIRInst(mod, scope, src, zir.Inst.Const, P{ .typed_value = typed_value }, .{}); | | |
| 4136 | } | | |
| 4137 | | | |
| 4138 | /// TODO The existence of this function is a workaround for a bug in stage1. | | |
| 4139 | pub fn addZIRInstLoop(mod: *Module, scope: *Scope, src: usize, body: zir.Body) !*zir.Inst.Loop { | | |
| 4140 | const P = std.meta.fieldInfo(zir.Inst.Loop, .positionals).field_type; | | |
| 4141 | return addZIRInstSpecial(mod, scope, src, zir.Inst.Loop, P{ .body = body }, .{}); | | |
| 4142 | } | | |