| ... | @@ -31,8 +31,7 @@ struct IrAnalyze { | ... | @@ -31,8 +31,7 @@ struct IrAnalyze { |
| 31 | IrBuilder old_irb; | 31 | IrBuilder old_irb; |
| 32 | IrBuilder new_irb; | 32 | IrBuilder new_irb; |
| 33 | IrExecContext exec_context; | 33 | IrExecContext exec_context; |
| 34 | ZigList<IrBasicBlock *> old_bb_queue; | 34 | size_t old_bb_index; |
| 35 | size_t block_queue_index; | | |
| 36 | size_t instruction_index; | 35 | size_t instruction_index; |
| 37 | TypeTableEntry *explicit_return_type; | 36 | TypeTableEntry *explicit_return_type; |
| 38 | ZigList<IrInstruction *> implicit_return_type_list; | 37 | ZigList<IrInstruction *> implicit_return_type_list; |
| ... | @@ -159,12 +158,6 @@ static IrBasicBlock *ir_create_basic_block(IrBuilder *irb, Scope *scope, const c | ... | @@ -159,12 +158,6 @@ static IrBasicBlock *ir_create_basic_block(IrBuilder *irb, Scope *scope, const c |
| 159 | return result; | 158 | return result; |
| 160 | } | 159 | } |
| 161 | | 160 | |
| 162 | static IrBasicBlock *ir_build_basic_block(IrBuilder *irb, Scope *scope, const char *name_hint) { | | |
| 163 | IrBasicBlock *result = ir_create_basic_block(irb, scope, name_hint); | | |
| 164 | irb->exec->basic_block_list.append(result); | | |
| 165 | return result; | | |
| 166 | } | | |
| 167 | | | |
| 168 | static IrBasicBlock *ir_build_bb_from(IrBuilder *irb, IrBasicBlock *other_bb) { | 161 | static IrBasicBlock *ir_build_bb_from(IrBuilder *irb, IrBasicBlock *other_bb) { |
| 169 | IrBasicBlock *new_bb = ir_create_basic_block(irb, other_bb->scope, other_bb->name_hint); | 162 | IrBasicBlock *new_bb = ir_create_basic_block(irb, other_bb->scope, other_bb->name_hint); |
| 170 | ir_link_new_bb(new_bb, other_bb); | 163 | ir_link_new_bb(new_bb, other_bb); |
| ... | @@ -2258,1031 +2251,58 @@ static IrInstruction *ir_build_type_id(IrBuilder *irb, Scope *scope, AstNode *so | ... | @@ -2258,1031 +2251,58 @@ static IrInstruction *ir_build_type_id(IrBuilder *irb, Scope *scope, AstNode *so |
| 2258 | return &instruction->base; | 2251 | return &instruction->base; |
| 2259 | } | 2252 | } |
| 2260 | | 2253 | |
| 2261 | static IrInstruction *ir_build_set_eval_branch_quota(IrBuilder *irb, Scope *scope, AstNode *source_node, | 2254 | static IrInstruction *ir_build_set_eval_branch_quota(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2262 | IrInstruction *new_quota) | 2255 | IrInstruction *new_quota) |
| 2263 | { | 2256 | { |
| 2264 | IrInstructionSetEvalBranchQuota *instruction = ir_build_instruction<IrInstructionSetEvalBranchQuota>(irb, scope, source_node); | 2257 | IrInstructionSetEvalBranchQuota *instruction = ir_build_instruction<IrInstructionSetEvalBranchQuota>(irb, scope, source_node); |
| 2265 | instruction->new_quota = new_quota; | 2258 | instruction->new_quota = new_quota; |
| 2266 | | | |
| 2267 | ir_ref_instruction(new_quota, irb->current_basic_block); | | |
| 2268 | | | |
| 2269 | return &instruction->base; | | |
| 2270 | } | | |
| 2271 | | | |
| 2272 | static IrInstruction *ir_build_align_cast(IrBuilder *irb, Scope *scope, AstNode *source_node, | | |
| 2273 | IrInstruction *align_bytes, IrInstruction *target) | | |
| 2274 | { | | |
| 2275 | IrInstructionAlignCast *instruction = ir_build_instruction<IrInstructionAlignCast>(irb, scope, source_node); | | |
| 2276 | instruction->align_bytes = align_bytes; | | |
| 2277 | instruction->target = target; | | |
| 2278 | | | |
| 2279 | if (align_bytes) ir_ref_instruction(align_bytes, irb->current_basic_block); | | |
| 2280 | ir_ref_instruction(target, irb->current_basic_block); | | |
| 2281 | | | |
| 2282 | return &instruction->base; | | |
| 2283 | } | | |
| 2284 | | | |
| 2285 | static IrInstruction *ir_build_opaque_type(IrBuilder *irb, Scope *scope, AstNode *source_node) { | | |
| 2286 | IrInstructionOpaqueType *instruction = ir_build_instruction<IrInstructionOpaqueType>(irb, scope, source_node); | | |
| 2287 | | | |
| 2288 | return &instruction->base; | | |
| 2289 | } | | |
| 2290 | | | |
| 2291 | static IrInstruction *ir_build_set_align_stack(IrBuilder *irb, Scope *scope, AstNode *source_node, | | |
| 2292 | IrInstruction *align_bytes) | | |
| 2293 | { | | |
| 2294 | IrInstructionSetAlignStack *instruction = ir_build_instruction<IrInstructionSetAlignStack>(irb, scope, source_node); | | |
| 2295 | instruction->align_bytes = align_bytes; | | |
| 2296 | | | |
| 2297 | ir_ref_instruction(align_bytes, irb->current_basic_block); | | |
| 2298 | | | |
| 2299 | return &instruction->base; | | |
| 2300 | } | | |
| 2301 | | | |
| 2302 | static IrInstruction *ir_build_arg_type(IrBuilder *irb, Scope *scope, AstNode *source_node, | | |
| 2303 | IrInstruction *fn_type, IrInstruction *arg_index) | | |
| 2304 | { | | |
| 2305 | IrInstructionArgType *instruction = ir_build_instruction<IrInstructionArgType>(irb, scope, source_node); | | |
| 2306 | instruction->fn_type = fn_type; | | |
| 2307 | instruction->arg_index = arg_index; | | |
| 2308 | | | |
| 2309 | ir_ref_instruction(fn_type, irb->current_basic_block); | | |
| 2310 | ir_ref_instruction(arg_index, irb->current_basic_block); | | |
| 2311 | | | |
| 2312 | return &instruction->base; | | |
| 2313 | } | | |
| 2314 | | | |
| 2315 | static IrInstruction *ir_instruction_br_get_dep(IrInstructionBr *instruction, size_t index) { | | |
| 2316 | return nullptr; | | |
| 2317 | } | | |
| 2318 | | | |
| 2319 | static IrInstruction *ir_instruction_condbr_get_dep(IrInstructionCondBr *instruction, size_t index) { | | |
| 2320 | switch (index) { | | |
| 2321 | case 0: return instruction->condition; | | |
| 2322 | default: return nullptr; | | |
| 2323 | } | | |
| 2324 | } | | |
| 2325 | | | |
| 2326 | static IrInstruction *ir_instruction_switchbr_get_dep(IrInstructionSwitchBr *instruction, size_t index) { | | |
| 2327 | switch (index) { | | |
| 2328 | case 0: return instruction->target_value; | | |
| 2329 | } | | |
| 2330 | size_t case_index = index - 2; | | |
| 2331 | if (case_index < instruction->case_count) return instruction->cases[case_index].value; | | |
| 2332 | return nullptr; | | |
| 2333 | } | | |
| 2334 | | | |
| 2335 | static IrInstruction *ir_instruction_switchvar_get_dep(IrInstructionSwitchVar *instruction, size_t index) { | | |
| 2336 | switch (index) { | | |
| 2337 | case 0: return instruction->target_value_ptr; | | |
| 2338 | case 1: return instruction->prong_value; | | |
| 2339 | default: return nullptr; | | |
| 2340 | } | | |
| 2341 | } | | |
| 2342 | | | |
| 2343 | static IrInstruction *ir_instruction_switchtarget_get_dep(IrInstructionSwitchTarget *instruction, size_t index) { | | |
| 2344 | switch (index) { | | |
| 2345 | case 0: return instruction->target_value_ptr; | | |
| 2346 | default: return nullptr; | | |
| 2347 | } | | |
| 2348 | } | | |
| 2349 | | | |
| 2350 | static IrInstruction *ir_instruction_phi_get_dep(IrInstructionPhi *instruction, size_t index) { | | |
| 2351 | if (index < instruction->incoming_count) return instruction->incoming_values[index]; | | |
| 2352 | return nullptr; | | |
| 2353 | } | | |
| 2354 | | | |
| 2355 | static IrInstruction *ir_instruction_unop_get_dep(IrInstructionUnOp *instruction, size_t index) { | | |
| 2356 | switch (index) { | | |
| 2357 | case 0: return instruction->value; | | |
| 2358 | default: return nullptr; | | |
| 2359 | } | | |
| 2360 | } | | |
| 2361 | | | |
| 2362 | static IrInstruction *ir_instruction_binop_get_dep(IrInstructionBinOp *instruction, size_t index) { | | |
| 2363 | switch (index) { | | |
| 2364 | case 0: return instruction->op1; | | |
| 2365 | case 1: return instruction->op2; | | |
| 2366 | default: return nullptr; | | |
| 2367 | } | | |
| 2368 | } | | |
| 2369 | | | |
| 2370 | static IrInstruction *ir_instruction_declvar_get_dep(IrInstructionDeclVar *instruction, size_t index) { | | |
| 2371 | if (index == 0) return instruction->init_value; | | |
| 2372 | index -= 1; | | |
| 2373 | | | |
| 2374 | if (instruction->align_value != nullptr) { | | |
| 2375 | if (index == 0) return instruction->align_value; | | |
| 2376 | index -= 1; | | |
| 2377 | } | | |
| 2378 | | | |
| 2379 | if (instruction->var_type != nullptr) { | | |
| 2380 | if (index == 0) return instruction->var_type; | | |
| 2381 | index -= 1; | | |
| 2382 | } | | |
| 2383 | | | |
| 2384 | return nullptr; | | |
| 2385 | } | | |
| 2386 | | | |
| 2387 | static IrInstruction *ir_instruction_export_get_dep(IrInstructionExport *instruction, size_t index) { | | |
| 2388 | if (index < 1) return instruction->name; | | |
| 2389 | index -= 1; | | |
| 2390 | | | |
| 2391 | if (index < 1) return instruction->target; | | |
| 2392 | index -= 1; | | |
| 2393 | | | |
| 2394 | if (instruction->linkage != nullptr) { | | |
| 2395 | if (index < 1) return instruction->linkage; | | |
| 2396 | index -= 1; | | |
| 2397 | } | | |
| 2398 | | | |
| 2399 | return nullptr; | | |
| 2400 | } | | |
| 2401 | | | |
| 2402 | static IrInstruction *ir_instruction_loadptr_get_dep(IrInstructionLoadPtr *instruction, size_t index) { | | |
| 2403 | switch (index) { | | |
| 2404 | case 0: return instruction->ptr; | | |
| 2405 | default: return nullptr; | | |
| 2406 | } | | |
| 2407 | } | | |
| 2408 | | | |
| 2409 | static IrInstruction *ir_instruction_storeptr_get_dep(IrInstructionStorePtr *instruction, size_t index) { | | |
| 2410 | switch (index) { | | |
| 2411 | case 0: return instruction->ptr; | | |
| 2412 | case 1: return instruction->value; | | |
| 2413 | default: return nullptr; | | |
| 2414 | } | | |
| 2415 | } | | |
| 2416 | | | |
| 2417 | static IrInstruction *ir_instruction_fieldptr_get_dep(IrInstructionFieldPtr *instruction, size_t index) { | | |
| 2418 | switch (index) { | | |
| 2419 | case 0: return instruction->container_ptr; | | |
| 2420 | default: return nullptr; | | |
| 2421 | } | | |
| 2422 | } | | |
| 2423 | | | |
| 2424 | static IrInstruction *ir_instruction_structfieldptr_get_dep(IrInstructionStructFieldPtr *instruction, size_t index) { | | |
| 2425 | switch (index) { | | |
| 2426 | case 0: return instruction->struct_ptr; | | |
| 2427 | default: return nullptr; | | |
| 2428 | } | | |
| 2429 | } | | |
| 2430 | | | |
| 2431 | static IrInstruction *ir_instruction_unionfieldptr_get_dep(IrInstructionUnionFieldPtr *instruction, size_t index) { | | |
| 2432 | switch (index) { | | |
| 2433 | case 0: return instruction->union_ptr; | | |
| 2434 | default: return nullptr; | | |
| 2435 | } | | |
| 2436 | } | | |
| 2437 | | | |
| 2438 | static IrInstruction *ir_instruction_elemptr_get_dep(IrInstructionElemPtr *instruction, size_t index) { | | |
| 2439 | switch (index) { | | |
| 2440 | case 0: return instruction->array_ptr; | | |
| 2441 | case 1: return instruction->elem_index; | | |
| 2442 | default: return nullptr; | | |
| 2443 | } | | |
| 2444 | } | | |
| 2445 | | | |
| 2446 | static IrInstruction *ir_instruction_varptr_get_dep(IrInstructionVarPtr *instruction, size_t index) { | | |
| 2447 | switch (index) { | | |
| 2448 | case 0: return instruction->var->decl_instruction; // can be null | | |
| 2449 | default: return nullptr; | | |
| 2450 | } | | |
| 2451 | } | | |
| 2452 | | | |
| 2453 | static IrInstruction *ir_instruction_call_get_dep(IrInstructionCall *instruction, size_t index) { | | |
| 2454 | if (index == 0) return instruction->fn_ref; | | |
| 2455 | size_t arg_index = index - 1; | | |
| 2456 | if (arg_index < instruction->arg_count) return instruction->args[arg_index]; | | |
| 2457 | return nullptr; | | |
| 2458 | } | | |
| 2459 | | | |
| 2460 | static IrInstruction *ir_instruction_const_get_dep(IrInstructionConst *instruction, size_t index) { | | |
| 2461 | return nullptr; | | |
| 2462 | } | | |
| 2463 | | | |
| 2464 | static IrInstruction *ir_instruction_return_get_dep(IrInstructionReturn *instruction, size_t index) { | | |
| 2465 | switch (index) { | | |
| 2466 | case 0: return instruction->value; | | |
| 2467 | default: return nullptr; | | |
| 2468 | } | | |
| 2469 | } | | |
| 2470 | | | |
| 2471 | static IrInstruction *ir_instruction_cast_get_dep(IrInstructionCast *instruction, size_t index) { | | |
| 2472 | switch (index) { | | |
| 2473 | case 0: return instruction->value; | | |
| 2474 | default: return nullptr; | | |
| 2475 | } | | |
| 2476 | } | | |
| 2477 | | | |
| 2478 | static IrInstruction *ir_instruction_containerinitlist_get_dep(IrInstructionContainerInitList *instruction, | | |
| 2479 | size_t index) | | |
| 2480 | { | | |
| 2481 | if (index == 0) return instruction->container_type; | | |
| 2482 | size_t item_index = index - 1; | | |
| 2483 | if (item_index < instruction->item_count) return instruction->items[item_index]; | | |
| 2484 | return nullptr; | | |
| 2485 | } | | |
| 2486 | | | |
| 2487 | static IrInstruction *ir_instruction_containerinitfields_get_dep(IrInstructionContainerInitFields *instruction, | | |
| 2488 | size_t index) | | |
| 2489 | { | | |
| 2490 | if (index == 0) return instruction->container_type; | | |
| 2491 | size_t field_index = index - 1; | | |
| 2492 | if (field_index < instruction->field_count) return instruction->fields[field_index].value; | | |
| 2493 | return nullptr; | | |
| 2494 | } | | |
| 2495 | | | |
| 2496 | static IrInstruction *ir_instruction_structinit_get_dep(IrInstructionStructInit *instruction, size_t index) { | | |
| 2497 | if (index < instruction->field_count) return instruction->fields[index].value; | | |
| 2498 | return nullptr; | | |
| 2499 | } | | |
| 2500 | | | |
| 2501 | static IrInstruction *ir_instruction_unioninit_get_dep(IrInstructionUnionInit *instruction, size_t index) { | | |
| 2502 | switch (index) { | | |
| 2503 | case 0: return instruction->init_value; | | |
| 2504 | default: return nullptr; | | |
| 2505 | } | | |
| 2506 | } | | |
| 2507 | | | |
| 2508 | static IrInstruction *ir_instruction_unreachable_get_dep(IrInstructionUnreachable *instruction, size_t index) { | | |
| 2509 | return nullptr; | | |
| 2510 | } | | |
| 2511 | | | |
| 2512 | static IrInstruction *ir_instruction_typeof_get_dep(IrInstructionTypeOf *instruction, size_t index) { | | |
| 2513 | switch (index) { | | |
| 2514 | case 0: return instruction->value; | | |
| 2515 | default: return nullptr; | | |
| 2516 | } | | |
| 2517 | } | | |
| 2518 | | | |
| 2519 | static IrInstruction *ir_instruction_toptrtype_get_dep(IrInstructionToPtrType *instruction, size_t index) { | | |
| 2520 | switch (index) { | | |
| 2521 | case 0: return instruction->value; | | |
| 2522 | default: return nullptr; | | |
| 2523 | } | | |
| 2524 | } | | |
| 2525 | | | |
| 2526 | static IrInstruction *ir_instruction_ptrtypechild_get_dep(IrInstructionPtrTypeChild *instruction, size_t index) { | | |
| 2527 | switch (index) { | | |
| 2528 | case 0: return instruction->value; | | |
| 2529 | default: return nullptr; | | |
| 2530 | } | | |
| 2531 | } | | |
| 2532 | | | |
| 2533 | static IrInstruction *ir_instruction_setdebugsafety_get_dep(IrInstructionSetDebugSafety *instruction, size_t index) { | | |
| 2534 | switch (index) { | | |
| 2535 | case 0: return instruction->scope_value; | | |
| 2536 | case 1: return instruction->debug_safety_on; | | |
| 2537 | default: return nullptr; | | |
| 2538 | } | | |
| 2539 | } | | |
| 2540 | | | |
| 2541 | static IrInstruction *ir_instruction_setfloatmode_get_dep(IrInstructionSetFloatMode *instruction, size_t index) { | | |
| 2542 | switch (index) { | | |
| 2543 | case 0: return instruction->scope_value; | | |
| 2544 | case 1: return instruction->mode_value; | | |
| 2545 | default: return nullptr; | | |
| 2546 | } | | |
| 2547 | } | | |
| 2548 | | | |
| 2549 | static IrInstruction *ir_instruction_arraytype_get_dep(IrInstructionArrayType *instruction, size_t index) { | | |
| 2550 | switch (index) { | | |
| 2551 | case 0: return instruction->size; | | |
| 2552 | case 1: return instruction->child_type; | | |
| 2553 | default: return nullptr; | | |
| 2554 | } | | |
| 2555 | } | | |
| 2556 | | | |
| 2557 | static IrInstruction *ir_instruction_slicetype_get_dep(IrInstructionSliceType *instruction, size_t index) { | | |
| 2558 | switch (index) { | | |
| 2559 | case 0: return instruction->child_type; | | |
| 2560 | default: return nullptr; | | |
| 2561 | } | | |
| 2562 | } | | |
| 2563 | | | |
| 2564 | static IrInstruction *ir_instruction_asm_get_dep(IrInstructionAsm *instruction, size_t index) { | | |
| 2565 | AstNode *asm_node = instruction->base.source_node; | | |
| 2566 | if (index < asm_node->data.asm_expr.output_list.length) return instruction->output_types[index]; | | |
| 2567 | size_t input_index = index - asm_node->data.asm_expr.output_list.length; | | |
| 2568 | if (input_index < asm_node->data.asm_expr.input_list.length) return instruction->input_list[input_index]; | | |
| 2569 | return nullptr; | | |
| 2570 | } | | |
| 2571 | | | |
| 2572 | static IrInstruction *ir_instruction_sizeof_get_dep(IrInstructionSizeOf *instruction, size_t index) { | | |
| 2573 | switch (index) { | | |
| 2574 | case 0: return instruction->type_value; | | |
| 2575 | default: return nullptr; | | |
| 2576 | } | | |
| 2577 | } | | |
| 2578 | | | |
| 2579 | static IrInstruction *ir_instruction_testnonnull_get_dep(IrInstructionTestNonNull *instruction, size_t index) { | | |
| 2580 | switch (index) { | | |
| 2581 | case 0: return instruction->value; | | |
| 2582 | default: return nullptr; | | |
| 2583 | } | | |
| 2584 | } | | |
| 2585 | | | |
| 2586 | static IrInstruction *ir_instruction_unwrapmaybe_get_dep(IrInstructionUnwrapMaybe *instruction, size_t index) { | | |
| 2587 | switch (index) { | | |
| 2588 | case 0: return instruction->value; | | |
| 2589 | default: return nullptr; | | |
| 2590 | } | | |
| 2591 | } | | |
| 2592 | | | |
| 2593 | static IrInstruction *ir_instruction_maybewrap_get_dep(IrInstructionMaybeWrap *instruction, size_t index) { | | |
| 2594 | switch (index) { | | |
| 2595 | case 0: return instruction->value; | | |
| 2596 | default: return nullptr; | | |
| 2597 | } | | |
| 2598 | } | | |
| 2599 | | | |
| 2600 | static IrInstruction *ir_instruction_uniontag_get_dep(IrInstructionUnionTag *instruction, size_t index) { | | |
| 2601 | switch (index) { | | |
| 2602 | case 0: return instruction->value; | | |
| 2603 | default: return nullptr; | | |
| 2604 | } | | |
| 2605 | } | | |
| 2606 | | | |
| 2607 | static IrInstruction *ir_instruction_clz_get_dep(IrInstructionClz *instruction, size_t index) { | | |
| 2608 | switch (index) { | | |
| 2609 | case 0: return instruction->value; | | |
| 2610 | default: return nullptr; | | |
| 2611 | } | | |
| 2612 | } | | |
| 2613 | | | |
| 2614 | static IrInstruction *ir_instruction_ctz_get_dep(IrInstructionCtz *instruction, size_t index) { | | |
| 2615 | switch (index) { | | |
| 2616 | case 0: return instruction->value; | | |
| 2617 | default: return nullptr; | | |
| 2618 | } | | |
| 2619 | } | | |
| 2620 | | | |
| 2621 | static IrInstruction *ir_instruction_import_get_dep(IrInstructionImport *instruction, size_t index) { | | |
| 2622 | switch (index) { | | |
| 2623 | case 0: return instruction->name; | | |
| 2624 | default: return nullptr; | | |
| 2625 | } | | |
| 2626 | } | | |
| 2627 | | | |
| 2628 | static IrInstruction *ir_instruction_cimport_get_dep(IrInstructionCImport *instruction, size_t index) { | | |
| 2629 | return nullptr; | | |
| 2630 | } | | |
| 2631 | | | |
| 2632 | static IrInstruction *ir_instruction_cinclude_get_dep(IrInstructionCInclude *instruction, size_t index) { | | |
| 2633 | switch (index) { | | |
| 2634 | case 0: return instruction->name; | | |
| 2635 | default: return nullptr; | | |
| 2636 | } | | |
| 2637 | } | | |
| 2638 | | | |
| 2639 | static IrInstruction *ir_instruction_cdefine_get_dep(IrInstructionCDefine *instruction, size_t index) { | | |
| 2640 | switch (index) { | | |
| 2641 | case 0: return instruction->name; | | |
| 2642 | case 1: return instruction->value; | | |
| 2643 | default: return nullptr; | | |
| 2644 | } | | |
| 2645 | } | | |
| 2646 | | | |
| 2647 | static IrInstruction *ir_instruction_cundef_get_dep(IrInstructionCUndef *instruction, size_t index) { | | |
| 2648 | switch (index) { | | |
| 2649 | case 0: return instruction->name; | | |
| 2650 | default: return nullptr; | | |
| 2651 | } | | |
| 2652 | } | | |
| 2653 | | | |
| 2654 | static IrInstruction *ir_instruction_arraylen_get_dep(IrInstructionArrayLen *instruction, size_t index) { | | |
| 2655 | switch (index) { | | |
| 2656 | case 0: return instruction->array_value; | | |
| 2657 | default: return nullptr; | | |
| 2658 | } | | |
| 2659 | } | | |
| 2660 | | | |
| 2661 | static IrInstruction *ir_instruction_ref_get_dep(IrInstructionRef *instruction, size_t index) { | | |
| 2662 | switch (index) { | | |
| 2663 | case 0: return instruction->value; | | |
| 2664 | default: return nullptr; | | |
| 2665 | } | | |
| 2666 | } | | |
| 2667 | | | |
| 2668 | static IrInstruction *ir_instruction_minvalue_get_dep(IrInstructionMinValue *instruction, size_t index) { | | |
| 2669 | switch (index) { | | |
| 2670 | case 0: return instruction->value; | | |
| 2671 | default: return nullptr; | | |
| 2672 | } | | |
| 2673 | } | | |
| 2674 | | | |
| 2675 | static IrInstruction *ir_instruction_maxvalue_get_dep(IrInstructionMaxValue *instruction, size_t index) { | | |
| 2676 | switch (index) { | | |
| 2677 | case 0: return instruction->value; | | |
| 2678 | default: return nullptr; | | |
| 2679 | } | | |
| 2680 | } | | |
| 2681 | | | |
| 2682 | static IrInstruction *ir_instruction_compileerr_get_dep(IrInstructionCompileErr *instruction, size_t index) { | | |
| 2683 | switch (index) { | | |
| 2684 | case 0: return instruction->msg; | | |
| 2685 | default: return nullptr; | | |
| 2686 | } | | |
| 2687 | } | | |
| 2688 | | | |
| 2689 | static IrInstruction *ir_instruction_compilelog_get_dep(IrInstructionCompileLog *instruction, size_t index) { | | |
| 2690 | if (index < instruction->msg_count) | | |
| 2691 | return instruction->msg_list[index]; | | |
| 2692 | return nullptr; | | |
| 2693 | } | | |
| 2694 | | | |
| 2695 | static IrInstruction *ir_instruction_errname_get_dep(IrInstructionErrName *instruction, size_t index) { | | |
| 2696 | switch (index) { | | |
| 2697 | case 0: return instruction->value; | | |
| 2698 | default: return nullptr; | | |
| 2699 | } | | |
| 2700 | } | | |
| 2701 | | | |
| 2702 | static IrInstruction *ir_instruction_embedfile_get_dep(IrInstructionEmbedFile *instruction, size_t index) { | | |
| 2703 | switch (index) { | | |
| 2704 | case 0: return instruction->name; | | |
| 2705 | default: return nullptr; | | |
| 2706 | } | | |
| 2707 | } | | |
| 2708 | | | |
| 2709 | static IrInstruction *ir_instruction_cmpxchg_get_dep(IrInstructionCmpxchg *instruction, size_t index) { | | |
| 2710 | switch (index) { | | |
| 2711 | case 0: return instruction->ptr; | | |
| 2712 | case 1: return instruction->cmp_value; | | |
| 2713 | case 2: return instruction->new_value; | | |
| 2714 | case 3: return instruction->success_order_value; | | |
| 2715 | case 4: return instruction->failure_order_value; | | |
| 2716 | default: return nullptr; | | |
| 2717 | } | | |
| 2718 | } | | |
| 2719 | | | |
| 2720 | static IrInstruction *ir_instruction_fence_get_dep(IrInstructionFence *instruction, size_t index) { | | |
| 2721 | switch (index) { | | |
| 2722 | case 0: return instruction->order_value; | | |
| 2723 | default: return nullptr; | | |
| 2724 | } | | |
| 2725 | } | | |
| 2726 | | | |
| 2727 | static IrInstruction *ir_instruction_truncate_get_dep(IrInstructionTruncate *instruction, size_t index) { | | |
| 2728 | switch (index) { | | |
| 2729 | case 0: return instruction->dest_type; | | |
| 2730 | case 1: return instruction->target; | | |
| 2731 | default: return nullptr; | | |
| 2732 | } | | |
| 2733 | } | | |
| 2734 | | | |
| 2735 | static IrInstruction *ir_instruction_inttype_get_dep(IrInstructionIntType *instruction, size_t index) { | | |
| 2736 | switch (index) { | | |
| 2737 | case 0: return instruction->is_signed; | | |
| 2738 | case 1: return instruction->bit_count; | | |
| 2739 | default: return nullptr; | | |
| 2740 | } | | |
| 2741 | } | | |
| 2742 | | | |
| 2743 | static IrInstruction *ir_instruction_boolnot_get_dep(IrInstructionBoolNot *instruction, size_t index) { | | |
| 2744 | switch (index) { | | |
| 2745 | case 0: return instruction->value; | | |
| 2746 | default: return nullptr; | | |
| 2747 | } | | |
| 2748 | } | | |
| 2749 | | | |
| 2750 | static IrInstruction *ir_instruction_memset_get_dep(IrInstructionMemset *instruction, size_t index) { | | |
| 2751 | switch (index) { | | |
| 2752 | case 0: return instruction->dest_ptr; | | |
| 2753 | case 1: return instruction->byte; | | |
| 2754 | case 2: return instruction->count; | | |
| 2755 | default: return nullptr; | | |
| 2756 | } | | |
| 2757 | } | | |
| 2758 | | | |
| 2759 | static IrInstruction *ir_instruction_memcpy_get_dep(IrInstructionMemcpy *instruction, size_t index) { | | |
| 2760 | switch (index) { | | |
| 2761 | case 0: return instruction->dest_ptr; | | |
| 2762 | case 1: return instruction->src_ptr; | | |
| 2763 | case 2: return instruction->count; | | |
| 2764 | default: return nullptr; | | |
| 2765 | } | | |
| 2766 | } | | |
| 2767 | | | |
| 2768 | static IrInstruction *ir_instruction_slice_get_dep(IrInstructionSlice *instruction, size_t index) { | | |
| 2769 | switch (index) { | | |
| 2770 | case 0: return instruction->ptr; | | |
| 2771 | case 1: return instruction->start; | | |
| 2772 | case 2: return instruction->end; | | |
| 2773 | default: return nullptr; | | |
| 2774 | } | | |
| 2775 | } | | |
| 2776 | | | |
| 2777 | static IrInstruction *ir_instruction_membercount_get_dep(IrInstructionMemberCount *instruction, size_t index) { | | |
| 2778 | switch (index) { | | |
| 2779 | case 0: return instruction->container; | | |
| 2780 | default: return nullptr; | | |
| 2781 | } | | |
| 2782 | } | | |
| 2783 | | | |
| 2784 | static IrInstruction *ir_instruction_membertype_get_dep(IrInstructionMemberType *instruction, size_t index) { | | |
| 2785 | switch (index) { | | |
| 2786 | case 0: return instruction->container_type; | | |
| 2787 | case 1: return instruction->member_index; | | |
| 2788 | default: return nullptr; | | |
| 2789 | } | | |
| 2790 | } | | |
| 2791 | | | |
| 2792 | static IrInstruction *ir_instruction_membername_get_dep(IrInstructionMemberName *instruction, size_t index) { | | |
| 2793 | switch (index) { | | |
| 2794 | case 0: return instruction->container_type; | | |
| 2795 | case 1: return instruction->member_index; | | |
| 2796 | default: return nullptr; | | |
| 2797 | } | | |
| 2798 | } | | |
| 2799 | | | |
| 2800 | static IrInstruction *ir_instruction_breakpoint_get_dep(IrInstructionBreakpoint *instruction, size_t index) { | | |
| 2801 | return nullptr; | | |
| 2802 | } | | |
| 2803 | | | |
| 2804 | static IrInstruction *ir_instruction_returnaddress_get_dep(IrInstructionReturnAddress *instruction, size_t index) { | | |
| 2805 | return nullptr; | | |
| 2806 | } | | |
| 2807 | | | |
| 2808 | static IrInstruction *ir_instruction_frameaddress_get_dep(IrInstructionFrameAddress *instruction, size_t index) { | | |
| 2809 | return nullptr; | | |
| 2810 | } | | |
| 2811 | | | |
| 2812 | static IrInstruction *ir_instruction_alignof_get_dep(IrInstructionAlignOf *instruction, size_t index) { | | |
| 2813 | switch (index) { | | |
| 2814 | case 0: return instruction->type_value; | | |
| 2815 | default: return nullptr; | | |
| 2816 | } | | |
| 2817 | } | | |
| 2818 | | | |
| 2819 | static IrInstruction *ir_instruction_overflowop_get_dep(IrInstructionOverflowOp *instruction, size_t index) { | | |
| 2820 | switch (index) { | | |
| 2821 | case 0: return instruction->type_value; | | |
| 2822 | case 1: return instruction->op1; | | |
| 2823 | case 2: return instruction->op2; | | |
| 2824 | case 3: return instruction->result_ptr; | | |
| 2825 | default: return nullptr; | | |
| 2826 | } | | |
| 2827 | } | | |
| 2828 | | | |
| 2829 | static IrInstruction *ir_instruction_testerr_get_dep(IrInstructionTestErr *instruction, size_t index) { | | |
| 2830 | switch (index) { | | |
| 2831 | case 0: return instruction->value; | | |
| 2832 | default: return nullptr; | | |
| 2833 | } | | |
| 2834 | } | | |
| 2835 | | | |
| 2836 | static IrInstruction *ir_instruction_unwraperrcode_get_dep(IrInstructionUnwrapErrCode *instruction, size_t index) { | | |
| 2837 | switch (index) { | | |
| 2838 | case 0: return instruction->value; | | |
| 2839 | default: return nullptr; | | |
| 2840 | } | | |
| 2841 | } | | |
| 2842 | | | |
| 2843 | static IrInstruction *ir_instruction_unwraperrpayload_get_dep(IrInstructionUnwrapErrPayload *instruction, | | |
| 2844 | size_t index) | | |
| 2845 | { | | |
| 2846 | switch (index) { | | |
| 2847 | case 0: return instruction->value; | | |
| 2848 | default: return nullptr; | | |
| 2849 | } | | |
| 2850 | } | | |
| 2851 | | | |
| 2852 | static IrInstruction *ir_instruction_errwrapcode_get_dep(IrInstructionErrWrapCode *instruction, size_t index) { | | |
| 2853 | switch (index) { | | |
| 2854 | case 0: return instruction->value; | | |
| 2855 | default: return nullptr; | | |
| 2856 | } | | |
| 2857 | } | | |
| 2858 | | | |
| 2859 | static IrInstruction *ir_instruction_errwrappayload_get_dep(IrInstructionErrWrapPayload *instruction, size_t index) { | | |
| 2860 | switch (index) { | | |
| 2861 | case 0: return instruction->value; | | |
| 2862 | default: return nullptr; | | |
| 2863 | } | | |
| 2864 | } | | |
| 2865 | | | |
| 2866 | static IrInstruction *ir_instruction_fnproto_get_dep(IrInstructionFnProto *instruction, size_t index) { | | |
| 2867 | if (index == 0) return instruction->return_type; | | |
| 2868 | size_t param_index = index - 1; | | |
| 2869 | if (param_index < instruction->base.source_node->data.fn_proto.params.length) { | | |
| 2870 | return instruction->param_types[param_index]; | | |
| 2871 | } | | |
| 2872 | size_t next_index = param_index - instruction->base.source_node->data.fn_proto.params.length; | | |
| 2873 | if (next_index == 0 && instruction->align_value != nullptr) { | | |
| 2874 | return instruction->align_value; | | |
| 2875 | } | | |
| 2876 | return nullptr; | | |
| 2877 | } | | |
| 2878 | | | |
| 2879 | static IrInstruction *ir_instruction_testcomptime_get_dep(IrInstructionTestComptime *instruction, size_t index) { | | |
| 2880 | switch (index) { | | |
| 2881 | case 0: return instruction->value; | | |
| 2882 | default: return nullptr; | | |
| 2883 | } | | |
| 2884 | } | | |
| 2885 | | | |
| 2886 | static IrInstruction *ir_instruction_ptrcast_get_dep(IrInstructionPtrCast *instruction, | | |
| 2887 | size_t index) | | |
| 2888 | { | | |
| 2889 | switch (index) { | | |
| 2890 | case 0: return instruction->ptr; | | |
| 2891 | case 1: return instruction->dest_type; | | |
| 2892 | default: return nullptr; | | |
| 2893 | } | | |
| 2894 | } | | |
| 2895 | | | |
| 2896 | static IrInstruction *ir_instruction_bitcast_get_dep(IrInstructionBitCast *instruction, | | |
| 2897 | size_t index) | | |
| 2898 | { | | |
| 2899 | switch (index) { | | |
| 2900 | case 0: return instruction->value; | | |
| 2901 | case 1: return instruction->dest_type; | | |
| 2902 | default: return nullptr; | | |
| 2903 | } | | |
| 2904 | } | | |
| 2905 | | | |
| 2906 | static IrInstruction *ir_instruction_widenorshorten_get_dep(IrInstructionWidenOrShorten *instruction, size_t index) { | | |
| 2907 | switch (index) { | | |
| 2908 | case 0: return instruction->target; | | |
| 2909 | default: return nullptr; | | |
| 2910 | } | | |
| 2911 | } | | |
| 2912 | | | |
| 2913 | static IrInstruction *ir_instruction_inttoptr_get_dep(IrInstructionIntToPtr *instruction, size_t index) { | | |
| 2914 | switch (index) { | | |
| 2915 | case 0: return instruction->target; | | |
| 2916 | case 1: return instruction->dest_type; | | |
| 2917 | default: return nullptr; | | |
| 2918 | } | | |
| 2919 | } | | |
| 2920 | | | |
| 2921 | static IrInstruction *ir_instruction_ptrtoint_get_dep(IrInstructionPtrToInt *instruction, size_t index) { | | |
| 2922 | switch (index) { | | |
| 2923 | case 0: return instruction->target; | | |
| 2924 | default: return nullptr; | | |
| 2925 | } | | |
| 2926 | } | | |
| 2927 | | | |
| 2928 | static IrInstruction *ir_instruction_inttoenum_get_dep(IrInstructionIntToEnum *instruction, size_t index) { | | |
| 2929 | switch (index) { | | |
| 2930 | case 0: return instruction->target; | | |
| 2931 | default: return nullptr; | | |
| 2932 | } | | |
| 2933 | } | | |
| 2934 | | | |
| 2935 | static IrInstruction *ir_instruction_inttoerr_get_dep(IrInstructionIntToErr *instruction, size_t index) { | | |
| 2936 | switch (index) { | | |
| 2937 | case 0: return instruction->target; | | |
| 2938 | default: return nullptr; | | |
| 2939 | } | | |
| 2940 | } | | |
| 2941 | | | |
| 2942 | static IrInstruction *ir_instruction_errtoint_get_dep(IrInstructionErrToInt *instruction, size_t index) { | | |
| 2943 | switch (index) { | | |
| 2944 | case 0: return instruction->target; | | |
| 2945 | default: return nullptr; | | |
| 2946 | } | | |
| 2947 | } | | |
| 2948 | | | |
| 2949 | static IrInstruction *ir_instruction_checkswitchprongs_get_dep(IrInstructionCheckSwitchProngs *instruction, | | |
| 2950 | size_t index) | | |
| 2951 | { | | |
| 2952 | if (index == 0) return instruction->target_value; | | |
| 2953 | size_t range_index = index - 1; | | |
| 2954 | if (range_index < instruction->range_count * 2) { | | |
| 2955 | IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_index / 2]; | | |
| 2956 | return (range_index % 2 == 0) ? range->start : range->end; | | |
| 2957 | } | | |
| 2958 | return nullptr; | | |
| 2959 | } | | |
| 2960 | | | |
| 2961 | static IrInstruction *ir_instruction_checkstatementisvoid_get_dep(IrInstructionCheckStatementIsVoid *instruction, | | |
| 2962 | size_t index) | | |
| 2963 | { | | |
| 2964 | switch (index) { | | |
| 2965 | case 0: return instruction->statement_value; | | |
| 2966 | default: return nullptr; | | |
| 2967 | } | | |
| 2968 | } | | |
| 2969 | | | |
| 2970 | static IrInstruction *ir_instruction_typename_get_dep(IrInstructionTypeName *instruction, size_t index) { | | |
| 2971 | switch (index) { | | |
| 2972 | case 0: return instruction->type_value; | | |
| 2973 | default: return nullptr; | | |
| 2974 | } | | |
| 2975 | } | | |
| 2976 | | | |
| 2977 | static IrInstruction *ir_instruction_canimplicitcast_get_dep(IrInstructionCanImplicitCast *instruction, size_t index) { | | |
| 2978 | switch (index) { | | |
| 2979 | case 0: return instruction->type_value; | | |
| 2980 | case 1: return instruction->target_value; | | |
| 2981 | default: return nullptr; | | |
| 2982 | } | | |
| 2983 | } | | |
| 2984 | | | |
| 2985 | static IrInstruction *ir_instruction_declref_get_dep(IrInstructionDeclRef *instruction, size_t index) { | | |
| 2986 | return nullptr; | | |
| 2987 | } | | |
| 2988 | | 2259 | |
| 2989 | static IrInstruction *ir_instruction_panic_get_dep(IrInstructionPanic *instruction, size_t index) { | 2260 | ir_ref_instruction(new_quota, irb->current_basic_block); |
| 2990 | switch (index) { | | |
| 2991 | case 0: return instruction->msg; | | |
| 2992 | default: return nullptr; | | |
| 2993 | } | | |
| 2994 | } | | |
| 2995 | | 2261 | |
| 2996 | static IrInstruction *ir_instruction_enumtagname_get_dep(IrInstructionTagName *instruction, size_t index) { | 2262 | return &instruction->base; |
| 2997 | switch (index) { | | |
| 2998 | case 0: return instruction->target; | | |
| 2999 | default: return nullptr; | | |
| 3000 | } | | |
| 3001 | } | 2263 | } |
| 3002 | | 2264 | |
| 3003 | static IrInstruction *ir_instruction_enumtagtype_get_dep(IrInstructionTagType *instruction, size_t index) { | 2265 | static IrInstruction *ir_build_align_cast(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3004 | switch (index) { | 2266 | IrInstruction *align_bytes, IrInstruction *target) |
| 3005 | case 0: return instruction->target; | 2267 | { |
| 3006 | default: return nullptr; | 2268 | IrInstructionAlignCast *instruction = ir_build_instruction<IrInstructionAlignCast>(irb, scope, source_node); |
| 3007 | } | 2269 | instruction->align_bytes = align_bytes; |
| 3008 | } | 2270 | instruction->target = target; |
| 3009 | | 2271 | |
| 3010 | static IrInstruction *ir_instruction_fieldparentptr_get_dep(IrInstructionFieldParentPtr *instruction, size_t index) { | 2272 | if (align_bytes) ir_ref_instruction(align_bytes, irb->current_basic_block); |
| 3011 | switch (index) { | 2273 | ir_ref_instruction(target, irb->current_basic_block); |
| 3012 | case 0: return instruction->type_value; | | |
| 3013 | case 1: return instruction->field_name; | | |
| 3014 | case 2: return instruction->field_ptr; | | |
| 3015 | default: return nullptr; | | |
| 3016 | } | | |
| 3017 | } | | |
| 3018 | | 2274 | |
| 3019 | static IrInstruction *ir_instruction_offsetof_get_dep(IrInstructionOffsetOf *instruction, size_t index) { | 2275 | return &instruction->base; |
| 3020 | switch (index) { | | |
| 3021 | case 0: return instruction->type_value; | | |
| 3022 | case 1: return instruction->field_name; | | |
| 3023 | default: return nullptr; | | |
| 3024 | } | | |
| 3025 | } | 2276 | } |
| 3026 | | 2277 | |
| 3027 | static IrInstruction *ir_instruction_typeid_get_dep(IrInstructionTypeId *instruction, size_t index) { | 2278 | static IrInstruction *ir_build_opaque_type(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 3028 | switch (index) { | 2279 | IrInstructionOpaqueType *instruction = ir_build_instruction<IrInstructionOpaqueType>(irb, scope, source_node); |
| 3029 | case 0: return instruction->type_value; | | |
| 3030 | default: return nullptr; | | |
| 3031 | } | | |
| 3032 | } | | |
| 3033 | | 2280 | |
| 3034 | static IrInstruction *ir_instruction_setevalbranchquota_get_dep(IrInstructionSetEvalBranchQuota *instruction, size_t index) { | 2281 | return &instruction->base; |
| 3035 | switch (index) { | | |
| 3036 | case 0: return instruction->new_quota; | | |
| 3037 | default: return nullptr; | | |
| 3038 | } | | |
| 3039 | } | 2282 | } |
| 3040 | | 2283 | |
| 3041 | static IrInstruction *ir_instruction_ptrtypeof_get_dep(IrInstructionPtrTypeOf *instruction, size_t index) { | 2284 | static IrInstruction *ir_build_set_align_stack(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3042 | switch (index) { | 2285 | IrInstruction *align_bytes) |
| 3043 | case 0: return instruction->align_value; | 2286 | { |
| 3044 | case 1: return instruction->child_type; | 2287 | IrInstructionSetAlignStack *instruction = ir_build_instruction<IrInstructionSetAlignStack>(irb, scope, source_node); |
| 3045 | default: return nullptr; | 2288 | instruction->align_bytes = align_bytes; |
| 3046 | } | | |
| 3047 | } | | |
| 3048 | | 2289 | |
| 3049 | static IrInstruction *ir_instruction_aligncast_get_dep(IrInstructionAlignCast *instruction, size_t index) { | 2290 | ir_ref_instruction(align_bytes, irb->current_basic_block); |
| 3050 | switch (index) { | | |
| 3051 | case 0: return instruction->target; | | |
| 3052 | case 1: return instruction->align_bytes; // can be null | | |
| 3053 | default: return nullptr; | | |
| 3054 | } | | |
| 3055 | } | | |
| 3056 | | 2291 | |
| 3057 | static IrInstruction *ir_instruction_opaquetype_get_dep(IrInstructionOpaqueType *instruction, size_t index) { | 2292 | return &instruction->base; |
| 3058 | return nullptr; | | |
| 3059 | } | 2293 | } |
| 3060 | | 2294 | |
| 3061 | static IrInstruction *ir_instruction_setalignstack_get_dep(IrInstructionSetAlignStack *instruction, size_t index) { | 2295 | static IrInstruction *ir_build_arg_type(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3062 | switch (index) { | 2296 | IrInstruction *fn_type, IrInstruction *arg_index) |
| 3063 | case 0: return instruction->align_bytes; | 2297 | { |
| 3064 | default: return nullptr; | 2298 | IrInstructionArgType *instruction = ir_build_instruction<IrInstructionArgType>(irb, scope, source_node); |
| 3065 | } | 2299 | instruction->fn_type = fn_type; |
| 3066 | } | 2300 | instruction->arg_index = arg_index; |
| 3067 | | 2301 | |
| 3068 | static IrInstruction *ir_instruction_argtype_get_dep(IrInstructionArgType *instruction, size_t index) { | 2302 | ir_ref_instruction(fn_type, irb->current_basic_block); |
| 3069 | switch (index) { | 2303 | ir_ref_instruction(arg_index, irb->current_basic_block); |
| 3070 | case 0: return instruction->fn_type; | | |
| 3071 | case 1: return instruction->arg_index; | | |
| 3072 | default: return nullptr; | | |
| 3073 | } | | |
| 3074 | } | | |
| 3075 | | 2304 | |
| 3076 | static IrInstruction *ir_instruction_get_dep(IrInstruction *instruction, size_t index) { | 2305 | return &instruction->base; |
| 3077 | switch (instruction->id) { | | |
| 3078 | case IrInstructionIdInvalid: | | |
| 3079 | zig_unreachable(); | | |
| 3080 | case IrInstructionIdBr: | | |
| 3081 | return ir_instruction_br_get_dep((IrInstructionBr *) instruction, index); | | |
| 3082 | case IrInstructionIdCondBr: | | |
| 3083 | return ir_instruction_condbr_get_dep((IrInstructionCondBr *) instruction, index); | | |
| 3084 | case IrInstructionIdSwitchBr: | | |
| 3085 | return ir_instruction_switchbr_get_dep((IrInstructionSwitchBr *) instruction, index); | | |
| 3086 | case IrInstructionIdSwitchVar: | | |
| 3087 | return ir_instruction_switchvar_get_dep((IrInstructionSwitchVar *) instruction, index); | | |
| 3088 | case IrInstructionIdSwitchTarget: | | |
| 3089 | return ir_instruction_switchtarget_get_dep((IrInstructionSwitchTarget *) instruction, index); | | |
| 3090 | case IrInstructionIdPhi: | | |
| 3091 | return ir_instruction_phi_get_dep((IrInstructionPhi *) instruction, index); | | |
| 3092 | case IrInstructionIdUnOp: | | |
| 3093 | return ir_instruction_unop_get_dep((IrInstructionUnOp *) instruction, index); | | |
| 3094 | case IrInstructionIdBinOp: | | |
| 3095 | return ir_instruction_binop_get_dep((IrInstructionBinOp *) instruction, index); | | |
| 3096 | case IrInstructionIdDeclVar: | | |
| 3097 | return ir_instruction_declvar_get_dep((IrInstructionDeclVar *) instruction, index); | | |
| 3098 | case IrInstructionIdExport: | | |
| 3099 | return ir_instruction_export_get_dep((IrInstructionExport *) instruction, index); | | |
| 3100 | case IrInstructionIdLoadPtr: | | |
| 3101 | return ir_instruction_loadptr_get_dep((IrInstructionLoadPtr *) instruction, index); | | |
| 3102 | case IrInstructionIdStorePtr: | | |
| 3103 | return ir_instruction_storeptr_get_dep((IrInstructionStorePtr *) instruction, index); | | |
| 3104 | case IrInstructionIdFieldPtr: | | |
| 3105 | return ir_instruction_fieldptr_get_dep((IrInstructionFieldPtr *) instruction, index); | | |
| 3106 | case IrInstructionIdStructFieldPtr: | | |
| 3107 | return ir_instruction_structfieldptr_get_dep((IrInstructionStructFieldPtr *) instruction, index); | | |
| 3108 | case IrInstructionIdUnionFieldPtr: | | |
| 3109 | return ir_instruction_unionfieldptr_get_dep((IrInstructionUnionFieldPtr *) instruction, index); | | |
| 3110 | case IrInstructionIdElemPtr: | | |
| 3111 | return ir_instruction_elemptr_get_dep((IrInstructionElemPtr *) instruction, index); | | |
| 3112 | case IrInstructionIdVarPtr: | | |
| 3113 | return ir_instruction_varptr_get_dep((IrInstructionVarPtr *) instruction, index); | | |
| 3114 | case IrInstructionIdCall: | | |
| 3115 | return ir_instruction_call_get_dep((IrInstructionCall *) instruction, index); | | |
| 3116 | case IrInstructionIdConst: | | |
| 3117 | return ir_instruction_const_get_dep((IrInstructionConst *) instruction, index); | | |
| 3118 | case IrInstructionIdReturn: | | |
| 3119 | return ir_instruction_return_get_dep((IrInstructionReturn *) instruction, index); | | |
| 3120 | case IrInstructionIdCast: | | |
| 3121 | return ir_instruction_cast_get_dep((IrInstructionCast *) instruction, index); | | |
| 3122 | case IrInstructionIdContainerInitList: | | |
| 3123 | return ir_instruction_containerinitlist_get_dep((IrInstructionContainerInitList *) instruction, index); | | |
| 3124 | case IrInstructionIdContainerInitFields: | | |
| 3125 | return ir_instruction_containerinitfields_get_dep((IrInstructionContainerInitFields *) instruction, index); | | |
| 3126 | case IrInstructionIdStructInit: | | |
| 3127 | return ir_instruction_structinit_get_dep((IrInstructionStructInit *) instruction, index); | | |
| 3128 | case IrInstructionIdUnionInit: | | |
| 3129 | return ir_instruction_unioninit_get_dep((IrInstructionUnionInit *) instruction, index); | | |
| 3130 | case IrInstructionIdUnreachable: | | |
| 3131 | return ir_instruction_unreachable_get_dep((IrInstructionUnreachable *) instruction, index); | | |
| 3132 | case IrInstructionIdTypeOf: | | |
| 3133 | return ir_instruction_typeof_get_dep((IrInstructionTypeOf *) instruction, index); | | |
| 3134 | case IrInstructionIdToPtrType: | | |
| 3135 | return ir_instruction_toptrtype_get_dep((IrInstructionToPtrType *) instruction, index); | | |
| 3136 | case IrInstructionIdPtrTypeChild: | | |
| 3137 | return ir_instruction_ptrtypechild_get_dep((IrInstructionPtrTypeChild *) instruction, index); | | |
| 3138 | case IrInstructionIdSetDebugSafety: | | |
| 3139 | return ir_instruction_setdebugsafety_get_dep((IrInstructionSetDebugSafety *) instruction, index); | | |
| 3140 | case IrInstructionIdSetFloatMode: | | |
| 3141 | return ir_instruction_setfloatmode_get_dep((IrInstructionSetFloatMode *) instruction, index); | | |
| 3142 | case IrInstructionIdArrayType: | | |
| 3143 | return ir_instruction_arraytype_get_dep((IrInstructionArrayType *) instruction, index); | | |
| 3144 | case IrInstructionIdSliceType: | | |
| 3145 | return ir_instruction_slicetype_get_dep((IrInstructionSliceType *) instruction, index); | | |
| 3146 | case IrInstructionIdAsm: | | |
| 3147 | return ir_instruction_asm_get_dep((IrInstructionAsm *) instruction, index); | | |
| 3148 | case IrInstructionIdSizeOf: | | |
| 3149 | return ir_instruction_sizeof_get_dep((IrInstructionSizeOf *) instruction, index); | | |
| 3150 | case IrInstructionIdTestNonNull: | | |
| 3151 | return ir_instruction_testnonnull_get_dep((IrInstructionTestNonNull *) instruction, index); | | |
| 3152 | case IrInstructionIdUnwrapMaybe: | | |
| 3153 | return ir_instruction_unwrapmaybe_get_dep((IrInstructionUnwrapMaybe *) instruction, index); | | |
| 3154 | case IrInstructionIdMaybeWrap: | | |
| 3155 | return ir_instruction_maybewrap_get_dep((IrInstructionMaybeWrap *) instruction, index); | | |
| 3156 | case IrInstructionIdUnionTag: | | |
| 3157 | return ir_instruction_uniontag_get_dep((IrInstructionUnionTag *) instruction, index); | | |
| 3158 | case IrInstructionIdClz: | | |
| 3159 | return ir_instruction_clz_get_dep((IrInstructionClz *) instruction, index); | | |
| 3160 | case IrInstructionIdCtz: | | |
| 3161 | return ir_instruction_ctz_get_dep((IrInstructionCtz *) instruction, index); | | |
| 3162 | case IrInstructionIdImport: | | |
| 3163 | return ir_instruction_import_get_dep((IrInstructionImport *) instruction, index); | | |
| 3164 | case IrInstructionIdCImport: | | |
| 3165 | return ir_instruction_cimport_get_dep((IrInstructionCImport *) instruction, index); | | |
| 3166 | case IrInstructionIdCInclude: | | |
| 3167 | return ir_instruction_cinclude_get_dep((IrInstructionCInclude *) instruction, index); | | |
| 3168 | case IrInstructionIdCDefine: | | |
| 3169 | return ir_instruction_cdefine_get_dep((IrInstructionCDefine *) instruction, index); | | |
| 3170 | case IrInstructionIdCUndef: | | |
| 3171 | return ir_instruction_cundef_get_dep((IrInstructionCUndef *) instruction, index); | | |
| 3172 | case IrInstructionIdArrayLen: | | |
| 3173 | return ir_instruction_arraylen_get_dep((IrInstructionArrayLen *) instruction, index); | | |
| 3174 | case IrInstructionIdRef: | | |
| 3175 | return ir_instruction_ref_get_dep((IrInstructionRef *) instruction, index); | | |
| 3176 | case IrInstructionIdMinValue: | | |
| 3177 | return ir_instruction_minvalue_get_dep((IrInstructionMinValue *) instruction, index); | | |
| 3178 | case IrInstructionIdMaxValue: | | |
| 3179 | return ir_instruction_maxvalue_get_dep((IrInstructionMaxValue *) instruction, index); | | |
| 3180 | case IrInstructionIdCompileErr: | | |
| 3181 | return ir_instruction_compileerr_get_dep((IrInstructionCompileErr *) instruction, index); | | |
| 3182 | case IrInstructionIdCompileLog: | | |
| 3183 | return ir_instruction_compilelog_get_dep((IrInstructionCompileLog *) instruction, index); | | |
| 3184 | case IrInstructionIdErrName: | | |
| 3185 | return ir_instruction_errname_get_dep((IrInstructionErrName *) instruction, index); | | |
| 3186 | case IrInstructionIdEmbedFile: | | |
| 3187 | return ir_instruction_embedfile_get_dep((IrInstructionEmbedFile *) instruction, index); | | |
| 3188 | case IrInstructionIdCmpxchg: | | |
| 3189 | return ir_instruction_cmpxchg_get_dep((IrInstructionCmpxchg *) instruction, index); | | |
| 3190 | case IrInstructionIdFence: | | |
| 3191 | return ir_instruction_fence_get_dep((IrInstructionFence *) instruction, index); | | |
| 3192 | case IrInstructionIdTruncate: | | |
| 3193 | return ir_instruction_truncate_get_dep((IrInstructionTruncate *) instruction, index); | | |
| 3194 | case IrInstructionIdIntType: | | |
| 3195 | return ir_instruction_inttype_get_dep((IrInstructionIntType *) instruction, index); | | |
| 3196 | case IrInstructionIdBoolNot: | | |
| 3197 | return ir_instruction_boolnot_get_dep((IrInstructionBoolNot *) instruction, index); | | |
| 3198 | case IrInstructionIdMemset: | | |
| 3199 | return ir_instruction_memset_get_dep((IrInstructionMemset *) instruction, index); | | |
| 3200 | case IrInstructionIdMemcpy: | | |
| 3201 | return ir_instruction_memcpy_get_dep((IrInstructionMemcpy *) instruction, index); | | |
| 3202 | case IrInstructionIdSlice: | | |
| 3203 | return ir_instruction_slice_get_dep((IrInstructionSlice *) instruction, index); | | |
| 3204 | case IrInstructionIdMemberCount: | | |
| 3205 | return ir_instruction_membercount_get_dep((IrInstructionMemberCount *) instruction, index); | | |
| 3206 | case IrInstructionIdMemberType: | | |
| 3207 | return ir_instruction_membertype_get_dep((IrInstructionMemberType *) instruction, index); | | |
| 3208 | case IrInstructionIdMemberName: | | |
| 3209 | return ir_instruction_membername_get_dep((IrInstructionMemberName *) instruction, index); | | |
| 3210 | case IrInstructionIdBreakpoint: | | |
| 3211 | return ir_instruction_breakpoint_get_dep((IrInstructionBreakpoint *) instruction, index); | | |
| 3212 | case IrInstructionIdReturnAddress: | | |
| 3213 | return ir_instruction_returnaddress_get_dep((IrInstructionReturnAddress *) instruction, index); | | |
| 3214 | case IrInstructionIdFrameAddress: | | |
| 3215 | return ir_instruction_frameaddress_get_dep((IrInstructionFrameAddress *) instruction, index); | | |
| 3216 | case IrInstructionIdAlignOf: | | |
| 3217 | return ir_instruction_alignof_get_dep((IrInstructionAlignOf *) instruction, index); | | |
| 3218 | case IrInstructionIdOverflowOp: | | |
| 3219 | return ir_instruction_overflowop_get_dep((IrInstructionOverflowOp *) instruction, index); | | |
| 3220 | case IrInstructionIdTestErr: | | |
| 3221 | return ir_instruction_testerr_get_dep((IrInstructionTestErr *) instruction, index); | | |
| 3222 | case IrInstructionIdUnwrapErrCode: | | |
| 3223 | return ir_instruction_unwraperrcode_get_dep((IrInstructionUnwrapErrCode *) instruction, index); | | |
| 3224 | case IrInstructionIdUnwrapErrPayload: | | |
| 3225 | return ir_instruction_unwraperrpayload_get_dep((IrInstructionUnwrapErrPayload *) instruction, index); | | |
| 3226 | case IrInstructionIdErrWrapCode: | | |
| 3227 | return ir_instruction_errwrapcode_get_dep((IrInstructionErrWrapCode *) instruction, index); | | |
| 3228 | case IrInstructionIdErrWrapPayload: | | |
| 3229 | return ir_instruction_errwrappayload_get_dep((IrInstructionErrWrapPayload *) instruction, index); | | |
| 3230 | case IrInstructionIdFnProto: | | |
| 3231 | return ir_instruction_fnproto_get_dep((IrInstructionFnProto *) instruction, index); | | |
| 3232 | case IrInstructionIdTestComptime: | | |
| 3233 | return ir_instruction_testcomptime_get_dep((IrInstructionTestComptime *) instruction, index); | | |
| 3234 | case IrInstructionIdPtrCast: | | |
| 3235 | return ir_instruction_ptrcast_get_dep((IrInstructionPtrCast *) instruction, index); | | |
| 3236 | case IrInstructionIdBitCast: | | |
| 3237 | return ir_instruction_bitcast_get_dep((IrInstructionBitCast *) instruction, index); | | |
| 3238 | case IrInstructionIdWidenOrShorten: | | |
| 3239 | return ir_instruction_widenorshorten_get_dep((IrInstructionWidenOrShorten *) instruction, index); | | |
| 3240 | case IrInstructionIdIntToPtr: | | |
| 3241 | return ir_instruction_inttoptr_get_dep((IrInstructionIntToPtr *) instruction, index); | | |
| 3242 | case IrInstructionIdPtrToInt: | | |
| 3243 | return ir_instruction_ptrtoint_get_dep((IrInstructionPtrToInt *) instruction, index); | | |
| 3244 | case IrInstructionIdIntToEnum: | | |
| 3245 | return ir_instruction_inttoenum_get_dep((IrInstructionIntToEnum *) instruction, index); | | |
| 3246 | case IrInstructionIdIntToErr: | | |
| 3247 | return ir_instruction_inttoerr_get_dep((IrInstructionIntToErr *) instruction, index); | | |
| 3248 | case IrInstructionIdErrToInt: | | |
| 3249 | return ir_instruction_errtoint_get_dep((IrInstructionErrToInt *) instruction, index); | | |
| 3250 | case IrInstructionIdCheckSwitchProngs: | | |
| 3251 | return ir_instruction_checkswitchprongs_get_dep((IrInstructionCheckSwitchProngs *) instruction, index); | | |
| 3252 | case IrInstructionIdCheckStatementIsVoid: | | |
| 3253 | return ir_instruction_checkstatementisvoid_get_dep((IrInstructionCheckStatementIsVoid *) instruction, index); | | |
| 3254 | case IrInstructionIdTypeName: | | |
| 3255 | return ir_instruction_typename_get_dep((IrInstructionTypeName *) instruction, index); | | |
| 3256 | case IrInstructionIdCanImplicitCast: | | |
| 3257 | return ir_instruction_canimplicitcast_get_dep((IrInstructionCanImplicitCast *) instruction, index); | | |
| 3258 | case IrInstructionIdDeclRef: | | |
| 3259 | return ir_instruction_declref_get_dep((IrInstructionDeclRef *) instruction, index); | | |
| 3260 | case IrInstructionIdPanic: | | |
| 3261 | return ir_instruction_panic_get_dep((IrInstructionPanic *) instruction, index); | | |
| 3262 | case IrInstructionIdTagName: | | |
| 3263 | return ir_instruction_enumtagname_get_dep((IrInstructionTagName *) instruction, index); | | |
| 3264 | case IrInstructionIdTagType: | | |
| 3265 | return ir_instruction_enumtagtype_get_dep((IrInstructionTagType *) instruction, index); | | |
| 3266 | case IrInstructionIdFieldParentPtr: | | |
| 3267 | return ir_instruction_fieldparentptr_get_dep((IrInstructionFieldParentPtr *) instruction, index); | | |
| 3268 | case IrInstructionIdOffsetOf: | | |
| 3269 | return ir_instruction_offsetof_get_dep((IrInstructionOffsetOf *) instruction, index); | | |
| 3270 | case IrInstructionIdTypeId: | | |
| 3271 | return ir_instruction_typeid_get_dep((IrInstructionTypeId *) instruction, index); | | |
| 3272 | case IrInstructionIdSetEvalBranchQuota: | | |
| 3273 | return ir_instruction_setevalbranchquota_get_dep((IrInstructionSetEvalBranchQuota *) instruction, index); | | |
| 3274 | case IrInstructionIdPtrTypeOf: | | |
| 3275 | return ir_instruction_ptrtypeof_get_dep((IrInstructionPtrTypeOf *) instruction, index); | | |
| 3276 | case IrInstructionIdAlignCast: | | |
| 3277 | return ir_instruction_aligncast_get_dep((IrInstructionAlignCast *) instruction, index); | | |
| 3278 | case IrInstructionIdOpaqueType: | | |
| 3279 | return ir_instruction_opaquetype_get_dep((IrInstructionOpaqueType *) instruction, index); | | |
| 3280 | case IrInstructionIdSetAlignStack: | | |
| 3281 | return ir_instruction_setalignstack_get_dep((IrInstructionSetAlignStack *) instruction, index); | | |
| 3282 | case IrInstructionIdArgType: | | |
| 3283 | return ir_instruction_argtype_get_dep((IrInstructionArgType *) instruction, index); | | |
| 3284 | } | | |
| 3285 | zig_unreachable(); | | |
| 3286 | } | 2306 | } |
| 3287 | | 2307 | |
| 3288 | static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_scope, size_t *results) { | 2308 | static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_scope, size_t *results) { |
| ... | @@ -3340,6 +2360,11 @@ static void ir_set_cursor_at_end(IrBuilder *irb, IrBasicBlock *basic_block) { | ... | @@ -3340,6 +2360,11 @@ static void ir_set_cursor_at_end(IrBuilder *irb, IrBasicBlock *basic_block) { |
| 3340 | irb->current_basic_block = basic_block; | 2360 | irb->current_basic_block = basic_block; |
| 3341 | } | 2361 | } |
| 3342 | | 2362 | |
| | 2363 | static void ir_set_cursor_at_end_and_append_block(IrBuilder *irb, IrBasicBlock *basic_block) { |
| | 2364 | irb->exec->basic_block_list.append(basic_block); |
| | 2365 | ir_set_cursor_at_end(irb, basic_block); |
| | 2366 | } |
| | 2367 | |
| 3343 | static ScopeDeferExpr *get_scope_defer_expr(Scope *scope) { | 2368 | static ScopeDeferExpr *get_scope_defer_expr(Scope *scope) { |
| 3344 | while (scope) { | 2369 | while (scope) { |
| 3345 | if (scope->id == ScopeIdDeferExpr) | 2370 | if (scope->id == ScopeIdDeferExpr) |
| ... | @@ -3388,8 +2413,8 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, | ... | @@ -3388,8 +2413,8 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, |
| 3388 | size_t defer_counts[2]; | 2413 | size_t defer_counts[2]; |
| 3389 | ir_count_defers(irb, scope, outer_scope, defer_counts); | 2414 | ir_count_defers(irb, scope, outer_scope, defer_counts); |
| 3390 | if (defer_counts[ReturnKindError] > 0) { | 2415 | if (defer_counts[ReturnKindError] > 0) { |
| 3391 | IrBasicBlock *err_block = ir_build_basic_block(irb, scope, "ErrRetErr"); | 2416 | IrBasicBlock *err_block = ir_create_basic_block(irb, scope, "ErrRetErr"); |
| 3392 | IrBasicBlock *ok_block = ir_build_basic_block(irb, scope, "ErrRetOk"); | 2417 | IrBasicBlock *ok_block = ir_create_basic_block(irb, scope, "ErrRetOk"); |
| 3393 | | 2418 | |
| 3394 | IrInstruction *is_err = ir_build_test_err(irb, scope, node, return_value); | 2419 | IrInstruction *is_err = ir_build_test_err(irb, scope, node, return_value); |
| 3395 | | 2420 | |
| ... | @@ -3402,11 +2427,11 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, | ... | @@ -3402,11 +2427,11 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, |
| 3402 | | 2427 | |
| 3403 | ir_mark_gen(ir_build_cond_br(irb, scope, node, is_err, err_block, ok_block, is_comptime)); | 2428 | ir_mark_gen(ir_build_cond_br(irb, scope, node, is_err, err_block, ok_block, is_comptime)); |
| 3404 | | 2429 | |
| 3405 | ir_set_cursor_at_end(irb, err_block); | 2430 | ir_set_cursor_at_end_and_append_block(irb, err_block); |
| 3406 | ir_gen_defers_for_block(irb, scope, outer_scope, true); | 2431 | ir_gen_defers_for_block(irb, scope, outer_scope, true); |
| 3407 | ir_build_return(irb, scope, node, return_value); | 2432 | ir_build_return(irb, scope, node, return_value); |
| 3408 | | 2433 | |
| 3409 | ir_set_cursor_at_end(irb, ok_block); | 2434 | ir_set_cursor_at_end_and_append_block(irb, ok_block); |
| 3410 | ir_gen_defers_for_block(irb, scope, outer_scope, false); | 2435 | ir_gen_defers_for_block(irb, scope, outer_scope, false); |
| 3411 | return ir_build_return(irb, scope, node, return_value); | 2436 | return ir_build_return(irb, scope, node, return_value); |
| 3412 | } else { | 2437 | } else { |
| ... | @@ -3424,17 +2449,17 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, | ... | @@ -3424,17 +2449,17 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, |
| 3424 | IrInstruction *err_union_val = ir_build_load_ptr(irb, scope, node, err_union_ptr); | 2449 | IrInstruction *err_union_val = ir_build_load_ptr(irb, scope, node, err_union_ptr); |
| 3425 | IrInstruction *is_err_val = ir_build_test_err(irb, scope, node, err_union_val); | 2450 | IrInstruction *is_err_val = ir_build_test_err(irb, scope, node, err_union_val); |
| 3426 | | 2451 | |
| 3427 | IrBasicBlock *return_block = ir_build_basic_block(irb, scope, "ErrRetReturn"); | 2452 | IrBasicBlock *return_block = ir_create_basic_block(irb, scope, "ErrRetReturn"); |
| 3428 | IrBasicBlock *continue_block = ir_build_basic_block(irb, scope, "ErrRetContinue"); | 2453 | IrBasicBlock *continue_block = ir_create_basic_block(irb, scope, "ErrRetContinue"); |
| 3429 | IrInstruction *is_comptime = ir_build_const_bool(irb, scope, node, ir_should_inline(irb->exec, scope)); | 2454 | IrInstruction *is_comptime = ir_build_const_bool(irb, scope, node, ir_should_inline(irb->exec, scope)); |
| 3430 | ir_mark_gen(ir_build_cond_br(irb, scope, node, is_err_val, return_block, continue_block, is_comptime)); | 2455 | ir_mark_gen(ir_build_cond_br(irb, scope, node, is_err_val, return_block, continue_block, is_comptime)); |
| 3431 | | 2456 | |
| 3432 | ir_set_cursor_at_end(irb, return_block); | 2457 | ir_set_cursor_at_end_and_append_block(irb, return_block); |
| 3433 | ir_gen_defers_for_block(irb, scope, outer_scope, true); | 2458 | ir_gen_defers_for_block(irb, scope, outer_scope, true); |
| 3434 | IrInstruction *err_val = ir_build_unwrap_err_code(irb, scope, node, err_union_ptr); | 2459 | IrInstruction *err_val = ir_build_unwrap_err_code(irb, scope, node, err_union_ptr); |
| 3435 | ir_build_return(irb, scope, node, err_val); | 2460 | ir_build_return(irb, scope, node, err_val); |
| 3436 | | 2461 | |
| 3437 | ir_set_cursor_at_end(irb, continue_block); | 2462 | ir_set_cursor_at_end_and_append_block(irb, continue_block); |
| 3438 | IrInstruction *unwrapped_ptr = ir_build_unwrap_err_payload(irb, scope, node, err_union_ptr, false); | 2463 | IrInstruction *unwrapped_ptr = ir_build_unwrap_err_payload(irb, scope, node, err_union_ptr, false); |
| 3439 | if (lval.is_ptr) | 2464 | if (lval.is_ptr) |
| 3440 | return unwrapped_ptr; | 2465 | return unwrapped_ptr; |
| ... | @@ -3529,13 +2554,13 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode | ... | @@ -3529,13 +2554,13 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode |
| 3529 | | 2554 | |
| 3530 | if (block_node->data.block.statements.length == 0) { | 2555 | if (block_node->data.block.statements.length == 0) { |
| 3531 | // {} | 2556 | // {} |
| 3532 | return ir_mark_gen(ir_build_const_void(irb, child_scope, block_node)); | 2557 | return ir_build_const_void(irb, child_scope, block_node); |
| 3533 | } | 2558 | } |
| 3534 | | 2559 | |
| 3535 | if (block_node->data.block.name != nullptr) { | 2560 | if (block_node->data.block.name != nullptr) { |
| 3536 | scope_block->incoming_blocks = &incoming_blocks; | 2561 | scope_block->incoming_blocks = &incoming_blocks; |
| 3537 | scope_block->incoming_values = &incoming_values; | 2562 | scope_block->incoming_values = &incoming_values; |
| 3538 | scope_block->end_block = ir_build_basic_block(irb, parent_scope, "BlockEnd"); | 2563 | scope_block->end_block = ir_create_basic_block(irb, parent_scope, "BlockEnd"); |
| 3539 | scope_block->is_comptime = ir_build_const_bool(irb, parent_scope, block_node, ir_should_inline(irb->exec, parent_scope)); | 2564 | scope_block->is_comptime = ir_build_const_bool(irb, parent_scope, block_node, ir_should_inline(irb->exec, parent_scope)); |
| 3540 | } | 2565 | } |
| 3541 | | 2566 | |
| ... | @@ -3558,7 +2583,7 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode | ... | @@ -3558,7 +2583,7 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode |
| 3558 | // variable declarations start a new scope | 2583 | // variable declarations start a new scope |
| 3559 | IrInstructionDeclVar *decl_var_instruction = (IrInstructionDeclVar *)statement_value; | 2584 | IrInstructionDeclVar *decl_var_instruction = (IrInstructionDeclVar *)statement_value; |
| 3560 | child_scope = decl_var_instruction->var->child_scope; | 2585 | child_scope = decl_var_instruction->var->child_scope; |
| 3561 | } else if (statement_value != irb->codegen->invalid_instruction) { | 2586 | } else if (statement_value != irb->codegen->invalid_instruction && !is_continuation_unreachable) { |
| 3562 | // this statement's value must be void | 2587 | // this statement's value must be void |
| 3563 | ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, statement_node, statement_value)); | 2588 | ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, statement_node, statement_value)); |
| 3564 | } | 2589 | } |
| ... | @@ -3577,7 +2602,7 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode | ... | @@ -3577,7 +2602,7 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode |
| 3577 | if (block_node->data.block.name != nullptr) { | 2602 | if (block_node->data.block.name != nullptr) { |
| 3578 | ir_gen_defers_for_block(irb, child_scope, outer_block_scope, false); | 2603 | ir_gen_defers_for_block(irb, child_scope, outer_block_scope, false); |
| 3579 | ir_mark_gen(ir_build_br(irb, parent_scope, block_node, scope_block->end_block, scope_block->is_comptime)); | 2604 | ir_mark_gen(ir_build_br(irb, parent_scope, block_node, scope_block->end_block, scope_block->is_comptime)); |
| 3580 | ir_set_cursor_at_end(irb, scope_block->end_block); | 2605 | ir_set_cursor_at_end_and_append_block(irb, scope_block->end_block); |
| 3581 | return ir_build_phi(irb, parent_scope, block_node, incoming_blocks.length, incoming_blocks.items, incoming_values.items); | 2606 | return ir_build_phi(irb, parent_scope, block_node, incoming_blocks.length, incoming_blocks.items, incoming_values.items); |
| 3582 | } else { | 2607 | } else { |
| 3583 | ir_gen_defers_for_block(irb, child_scope, outer_block_scope, false); | 2608 | ir_gen_defers_for_block(irb, child_scope, outer_block_scope, false); |
| ... | @@ -3635,13 +2660,13 @@ static IrInstruction *ir_gen_bool_or(IrBuilder *irb, Scope *scope, AstNode *node | ... | @@ -3635,13 +2660,13 @@ static IrInstruction *ir_gen_bool_or(IrBuilder *irb, Scope *scope, AstNode *node |
| 3635 | } | 2660 | } |
| 3636 | | 2661 | |
| 3637 | // block for when val1 == false | 2662 | // block for when val1 == false |
| 3638 | IrBasicBlock *false_block = ir_build_basic_block(irb, scope, "BoolOrFalse"); | 2663 | IrBasicBlock *false_block = ir_create_basic_block(irb, scope, "BoolOrFalse"); |
| 3639 | // block for when val1 == true (don't even evaluate the second part) | 2664 | // block for when val1 == true (don't even evaluate the second part) |
| 3640 | IrBasicBlock *true_block = ir_build_basic_block(irb, scope, "BoolOrTrue"); | 2665 | IrBasicBlock *true_block = ir_create_basic_block(irb, scope, "BoolOrTrue"); |
| 3641 | | 2666 | |
| 3642 | ir_build_cond_br(irb, scope, node, val1, true_block, false_block, is_comptime); | 2667 | ir_build_cond_br(irb, scope, node, val1, true_block, false_block, is_comptime); |
| 3643 | | 2668 | |
| 3644 | ir_set_cursor_at_end(irb, false_block); | 2669 | ir_set_cursor_at_end_and_append_block(irb, false_block); |
| 3645 | IrInstruction *val2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope); | 2670 | IrInstruction *val2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope); |
| 3646 | if (val2 == irb->codegen->invalid_instruction) | 2671 | if (val2 == irb->codegen->invalid_instruction) |
| 3647 | return irb->codegen->invalid_instruction; | 2672 | return irb->codegen->invalid_instruction; |
| ... | @@ -3649,7 +2674,7 @@ static IrInstruction *ir_gen_bool_or(IrBuilder *irb, Scope *scope, AstNode *node | ... | @@ -3649,7 +2674,7 @@ static IrInstruction *ir_gen_bool_or(IrBuilder *irb, Scope *scope, AstNode *node |
| 3649 | | 2674 | |
| 3650 | ir_build_br(irb, scope, node, true_block, is_comptime); | 2675 | ir_build_br(irb, scope, node, true_block, is_comptime); |
| 3651 | | 2676 | |
| 3652 | ir_set_cursor_at_end(irb, true_block); | 2677 | ir_set_cursor_at_end_and_append_block(irb, true_block); |
| 3653 | | 2678 | |
| 3654 | IrInstruction **incoming_values = allocate<IrInstruction *>(2); | 2679 | IrInstruction **incoming_values = allocate<IrInstruction *>(2); |
| 3655 | incoming_values[0] = val1; | 2680 | incoming_values[0] = val1; |
| ... | @@ -3677,13 +2702,13 @@ static IrInstruction *ir_gen_bool_and(IrBuilder *irb, Scope *scope, AstNode *nod | ... | @@ -3677,13 +2702,13 @@ static IrInstruction *ir_gen_bool_and(IrBuilder *irb, Scope *scope, AstNode *nod |
| 3677 | } | 2702 | } |
| 3678 | | 2703 | |
| 3679 | // block for when val1 == true | 2704 | // block for when val1 == true |
| 3680 | IrBasicBlock *true_block = ir_build_basic_block(irb, scope, "BoolAndTrue"); | 2705 | IrBasicBlock *true_block = ir_create_basic_block(irb, scope, "BoolAndTrue"); |
| 3681 | // block for when val1 == false (don't even evaluate the second part) | 2706 | // block for when val1 == false (don't even evaluate the second part) |
| 3682 | IrBasicBlock *false_block = ir_build_basic_block(irb, scope, "BoolAndFalse"); | 2707 | IrBasicBlock *false_block = ir_create_basic_block(irb, scope, "BoolAndFalse"); |
| 3683 | | 2708 | |
| 3684 | ir_build_cond_br(irb, scope, node, val1, true_block, false_block, is_comptime); | 2709 | ir_build_cond_br(irb, scope, node, val1, true_block, false_block, is_comptime); |
| 3685 | | 2710 | |
| 3686 | ir_set_cursor_at_end(irb, true_block); | 2711 | ir_set_cursor_at_end_and_append_block(irb, true_block); |
| 3687 | IrInstruction *val2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope); | 2712 | IrInstruction *val2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope); |
| 3688 | if (val2 == irb->codegen->invalid_instruction) | 2713 | if (val2 == irb->codegen->invalid_instruction) |
| 3689 | return irb->codegen->invalid_instruction; | 2714 | return irb->codegen->invalid_instruction; |
| ... | @@ -3691,7 +2716,7 @@ static IrInstruction *ir_gen_bool_and(IrBuilder *irb, Scope *scope, AstNode *nod | ... | @@ -3691,7 +2716,7 @@ static IrInstruction *ir_gen_bool_and(IrBuilder *irb, Scope *scope, AstNode *nod |
| 3691 | | 2716 | |
| 3692 | ir_build_br(irb, scope, node, false_block, is_comptime); | 2717 | ir_build_br(irb, scope, node, false_block, is_comptime); |
| 3693 | | 2718 | |
| 3694 | ir_set_cursor_at_end(irb, false_block); | 2719 | ir_set_cursor_at_end_and_append_block(irb, false_block); |
| 3695 | | 2720 | |
| 3696 | IrInstruction **incoming_values = allocate<IrInstruction *>(2); | 2721 | IrInstruction **incoming_values = allocate<IrInstruction *>(2); |
| 3697 | incoming_values[0] = val1; | 2722 | incoming_values[0] = val1; |
| ... | @@ -3723,12 +2748,12 @@ static IrInstruction *ir_gen_maybe_ok_or(IrBuilder *irb, Scope *parent_scope, As | ... | @@ -3723,12 +2748,12 @@ static IrInstruction *ir_gen_maybe_ok_or(IrBuilder *irb, Scope *parent_scope, As |
| 3723 | is_comptime = ir_build_test_comptime(irb, parent_scope, node, is_non_null); | 2748 | is_comptime = ir_build_test_comptime(irb, parent_scope, node, is_non_null); |
| 3724 | } | 2749 | } |
| 3725 | | 2750 | |
| 3726 | IrBasicBlock *ok_block = ir_build_basic_block(irb, parent_scope, "MaybeNonNull"); | 2751 | IrBasicBlock *ok_block = ir_create_basic_block(irb, parent_scope, "MaybeNonNull"); |
| 3727 | IrBasicBlock *null_block = ir_build_basic_block(irb, parent_scope, "MaybeNull"); | 2752 | IrBasicBlock *null_block = ir_create_basic_block(irb, parent_scope, "MaybeNull"); |
| 3728 | IrBasicBlock *end_block = ir_build_basic_block(irb, parent_scope, "MaybeEnd"); | 2753 | IrBasicBlock *end_block = ir_create_basic_block(irb, parent_scope, "MaybeEnd"); |
| 3729 | ir_build_cond_br(irb, parent_scope, node, is_non_null, ok_block, null_block, is_comptime); | 2754 | ir_build_cond_br(irb, parent_scope, node, is_non_null, ok_block, null_block, is_comptime); |
| 3730 | | 2755 | |
| 3731 | ir_set_cursor_at_end(irb, null_block); | 2756 | ir_set_cursor_at_end_and_append_block(irb, null_block); |
| 3732 | IrInstruction *null_result = ir_gen_node(irb, op2_node, parent_scope); | 2757 | IrInstruction *null_result = ir_gen_node(irb, op2_node, parent_scope); |
| 3733 | if (null_result == irb->codegen->invalid_instruction) | 2758 | if (null_result == irb->codegen->invalid_instruction) |
| 3734 | return irb->codegen->invalid_instruction; | 2759 | return irb->codegen->invalid_instruction; |
| ... | @@ -3736,13 +2761,13 @@ static IrInstruction *ir_gen_maybe_ok_or(IrBuilder *irb, Scope *parent_scope, As | ... | @@ -3736,13 +2761,13 @@ static IrInstruction *ir_gen_maybe_ok_or(IrBuilder *irb, Scope *parent_scope, As |
| 3736 | if (!instr_is_unreachable(null_result)) | 2761 | if (!instr_is_unreachable(null_result)) |
| 3737 | ir_mark_gen(ir_build_br(irb, parent_scope, node, end_block, is_comptime)); | 2762 | ir_mark_gen(ir_build_br(irb, parent_scope, node, end_block, is_comptime)); |
| 3738 | | 2763 | |
| 3739 | ir_set_cursor_at_end(irb, ok_block); | 2764 | ir_set_cursor_at_end_and_append_block(irb, ok_block); |
| 3740 | IrInstruction *unwrapped_ptr = ir_build_unwrap_maybe(irb, parent_scope, node, maybe_ptr, false); | 2765 | IrInstruction *unwrapped_ptr = ir_build_unwrap_maybe(irb, parent_scope, node, maybe_ptr, false); |
| 3741 | IrInstruction *unwrapped_payload = ir_build_load_ptr(irb, parent_scope, node, unwrapped_ptr); | 2766 | IrInstruction *unwrapped_payload = ir_build_load_ptr(irb, parent_scope, node, unwrapped_ptr); |
| 3742 | IrBasicBlock *after_ok_block = irb->current_basic_block; | 2767 | IrBasicBlock *after_ok_block = irb->current_basic_block; |
| 3743 | ir_build_br(irb, parent_scope, node, end_block, is_comptime); | 2768 | ir_build_br(irb, parent_scope, node, end_block, is_comptime); |
| 3744 | | 2769 | |
| 3745 | ir_set_cursor_at_end(irb, end_block); | 2770 | ir_set_cursor_at_end_and_append_block(irb, end_block); |
| 3746 | IrInstruction **incoming_values = allocate<IrInstruction *>(2); | 2771 | IrInstruction **incoming_values = allocate<IrInstruction *>(2); |
| 3747 | incoming_values[0] = null_result; | 2772 | incoming_values[0] = null_result; |
| 3748 | incoming_values[1] = unwrapped_payload; | 2773 | incoming_values[1] = unwrapped_payload; |
| ... | @@ -4748,13 +3773,14 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode | ... | @@ -4748,13 +3773,14 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode |
| 4748 | AstNode *then_node = node->data.if_bool_expr.then_block; | 3773 | AstNode *then_node = node->data.if_bool_expr.then_block; |
| 4749 | AstNode *else_node = node->data.if_bool_expr.else_node; | 3774 | AstNode *else_node = node->data.if_bool_expr.else_node; |
| 4750 | | 3775 | |
| 4751 | IrBasicBlock *then_block = ir_build_basic_block(irb, scope, "Then"); | 3776 | IrBasicBlock *then_block = ir_create_basic_block(irb, scope, "Then"); |
| 4752 | IrBasicBlock *else_block = ir_build_basic_block(irb, scope, "Else"); | 3777 | IrBasicBlock *else_block = ir_create_basic_block(irb, scope, "Else"); |
| 4753 | IrBasicBlock *endif_block = ir_build_basic_block(irb, scope, "EndIf"); | 3778 | IrBasicBlock *endif_block = ir_create_basic_block(irb, scope, "EndIf"); |
| 4754 | | 3779 | |
| 4755 | ir_build_cond_br(irb, scope, condition->source_node, condition, then_block, else_block, is_comptime); | 3780 | ir_build_cond_br(irb, scope, condition->source_node, condition, then_block, else_block, is_comptime); |
| 4756 | | 3781 | |
| 4757 | ir_set_cursor_at_end(irb, then_block); | 3782 | ir_set_cursor_at_end_and_append_block(irb, then_block); |
| | 3783 | |
| 4758 | IrInstruction *then_expr_result = ir_gen_node(irb, then_node, scope); | 3784 | IrInstruction *then_expr_result = ir_gen_node(irb, then_node, scope); |
| 4759 | if (then_expr_result == irb->codegen->invalid_instruction) | 3785 | if (then_expr_result == irb->codegen->invalid_instruction) |
| 4760 | return then_expr_result; | 3786 | return then_expr_result; |
| ... | @@ -4762,7 +3788,7 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode | ... | @@ -4762,7 +3788,7 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode |
| 4762 | if (!instr_is_unreachable(then_expr_result)) | 3788 | if (!instr_is_unreachable(then_expr_result)) |
| 4763 | ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime)); | 3789 | ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime)); |
| 4764 | | 3790 | |
| 4765 | ir_set_cursor_at_end(irb, else_block); | 3791 | ir_set_cursor_at_end_and_append_block(irb, else_block); |
| 4766 | IrInstruction *else_expr_result; | 3792 | IrInstruction *else_expr_result; |
| 4767 | if (else_node) { | 3793 | if (else_node) { |
| 4768 | else_expr_result = ir_gen_node(irb, else_node, scope); | 3794 | else_expr_result = ir_gen_node(irb, else_node, scope); |
| ... | @@ -4775,7 +3801,7 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode | ... | @@ -4775,7 +3801,7 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode |
| 4775 | if (!instr_is_unreachable(else_expr_result)) | 3801 | if (!instr_is_unreachable(else_expr_result)) |
| 4776 | ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime)); | 3802 | ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime)); |
| 4777 | | 3803 | |
| 4778 | ir_set_cursor_at_end(irb, endif_block); | 3804 | ir_set_cursor_at_end_and_append_block(irb, endif_block); |
| 4779 | IrInstruction **incoming_values = allocate<IrInstruction *>(2); | 3805 | IrInstruction **incoming_values = allocate<IrInstruction *>(2); |
| 4780 | incoming_values[0] = then_expr_result; | 3806 | incoming_values[0] = then_expr_result; |
| 4781 | incoming_values[1] = else_expr_result; | 3807 | incoming_values[1] = else_expr_result; |
| ... | @@ -5044,13 +4070,13 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n | ... | @@ -5044,13 +4070,13 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 5044 | AstNode *continue_expr_node = node->data.while_expr.continue_expr; | 4070 | AstNode *continue_expr_node = node->data.while_expr.continue_expr; |
| 5045 | AstNode *else_node = node->data.while_expr.else_node; | 4071 | AstNode *else_node = node->data.while_expr.else_node; |
| 5046 | | 4072 | |
| 5047 | IrBasicBlock *cond_block = ir_build_basic_block(irb, scope, "WhileCond"); | 4073 | IrBasicBlock *cond_block = ir_create_basic_block(irb, scope, "WhileCond"); |
| 5048 | IrBasicBlock *body_block = ir_build_basic_block(irb, scope, "WhileBody"); | 4074 | IrBasicBlock *body_block = ir_create_basic_block(irb, scope, "WhileBody"); |
| 5049 | IrBasicBlock *continue_block = continue_expr_node ? | 4075 | IrBasicBlock *continue_block = continue_expr_node ? |
| 5050 | ir_build_basic_block(irb, scope, "WhileContinue") : cond_block; | 4076 | ir_create_basic_block(irb, scope, "WhileContinue") : cond_block; |
| 5051 | IrBasicBlock *end_block = ir_build_basic_block(irb, scope, "WhileEnd"); | 4077 | IrBasicBlock *end_block = ir_create_basic_block(irb, scope, "WhileEnd"); |
| 5052 | IrBasicBlock *else_block = else_node ? | 4078 | IrBasicBlock *else_block = else_node ? |
| 5053 | ir_build_basic_block(irb, scope, "WhileElse") : end_block; | 4079 | ir_create_basic_block(irb, scope, "WhileElse") : end_block; |
| 5054 | | 4080 | |
| 5055 | IrInstruction *is_comptime = ir_build_const_bool(irb, scope, node, | 4081 | IrInstruction *is_comptime = ir_build_const_bool(irb, scope, node, |
| 5056 | ir_should_inline(irb->exec, scope) || node->data.while_expr.is_inline); | 4082 | ir_should_inline(irb->exec, scope) || node->data.while_expr.is_inline); |
| ... | @@ -5059,7 +4085,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n | ... | @@ -5059,7 +4085,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 5059 | Buf *var_symbol = node->data.while_expr.var_symbol; | 4085 | Buf *var_symbol = node->data.while_expr.var_symbol; |
| 5060 | Buf *err_symbol = node->data.while_expr.err_symbol; | 4086 | Buf *err_symbol = node->data.while_expr.err_symbol; |
| 5061 | if (err_symbol != nullptr) { | 4087 | if (err_symbol != nullptr) { |
| 5062 | ir_set_cursor_at_end(irb, cond_block); | 4088 | ir_set_cursor_at_end_and_append_block(irb, cond_block); |
| 5063 | | 4089 | |
| 5064 | Scope *payload_scope; | 4090 | Scope *payload_scope; |
| 5065 | AstNode *symbol_node = node; // TODO make more accurate | 4091 | AstNode *symbol_node = node; // TODO make more accurate |
| ... | @@ -5084,7 +4110,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n | ... | @@ -5084,7 +4110,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 5084 | else_block, body_block, is_comptime)); | 4110 | else_block, body_block, is_comptime)); |
| 5085 | } | 4111 | } |
| 5086 | | 4112 | |
| 5087 | ir_set_cursor_at_end(irb, body_block); | 4113 | ir_set_cursor_at_end_and_append_block(irb, body_block); |
| 5088 | if (var_symbol) { | 4114 | if (var_symbol) { |
| 5089 | IrInstruction *var_ptr_value = ir_build_unwrap_err_payload(irb, payload_scope, symbol_node, | 4115 | IrInstruction *var_ptr_value = ir_build_unwrap_err_payload(irb, payload_scope, symbol_node, |
| 5090 | err_val_ptr, false); | 4116 | err_val_ptr, false); |
| ... | @@ -5111,7 +4137,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n | ... | @@ -5111,7 +4137,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 5111 | ir_mark_gen(ir_build_br(irb, payload_scope, node, continue_block, is_comptime)); | 4137 | ir_mark_gen(ir_build_br(irb, payload_scope, node, continue_block, is_comptime)); |
| 5112 | | 4138 | |
| 5113 | if (continue_expr_node) { | 4139 | if (continue_expr_node) { |
| 5114 | ir_set_cursor_at_end(irb, continue_block); | 4140 | ir_set_cursor_at_end_and_append_block(irb, continue_block); |
| 5115 | IrInstruction *expr_result = ir_gen_node(irb, continue_expr_node, payload_scope); | 4141 | IrInstruction *expr_result = ir_gen_node(irb, continue_expr_node, payload_scope); |
| 5116 | if (expr_result == irb->codegen->invalid_instruction) | 4142 | if (expr_result == irb->codegen->invalid_instruction) |
| 5117 | return expr_result; | 4143 | return expr_result; |
| ... | @@ -5121,7 +4147,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n | ... | @@ -5121,7 +4147,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 5121 | | 4147 | |
| 5122 | IrInstruction *else_result = nullptr; | 4148 | IrInstruction *else_result = nullptr; |
| 5123 | if (else_node) { | 4149 | if (else_node) { |
| 5124 | ir_set_cursor_at_end(irb, else_block); | 4150 | ir_set_cursor_at_end_and_append_block(irb, else_block); |
| 5125 | | 4151 | |
| 5126 | // TODO make it an error to write to error variable | 4152 | // TODO make it an error to write to error variable |
| 5127 | AstNode *err_symbol_node = else_node; // TODO make more accurate | 4153 | AstNode *err_symbol_node = else_node; // TODO make more accurate |
| ... | @@ -5138,7 +4164,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n | ... | @@ -5138,7 +4164,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 5138 | ir_mark_gen(ir_build_br(irb, scope, node, end_block, is_comptime)); | 4164 | ir_mark_gen(ir_build_br(irb, scope, node, end_block, is_comptime)); |
| 5139 | } | 4165 | } |
| 5140 | IrBasicBlock *after_else_block = irb->current_basic_block; | 4166 | IrBasicBlock *after_else_block = irb->current_basic_block; |
| 5141 | ir_set_cursor_at_end(irb, end_block); | 4167 | ir_set_cursor_at_end_and_append_block(irb, end_block); |
| 5142 | if (else_result) { | 4168 | if (else_result) { |
| 5143 | incoming_blocks.append(after_else_block); | 4169 | incoming_blocks.append(after_else_block); |
| 5144 | incoming_values.append(else_result); | 4170 | incoming_values.append(else_result); |
| ... | @@ -5149,7 +4175,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n | ... | @@ -5149,7 +4175,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 5149 | | 4175 | |
| 5150 | return ir_build_phi(irb, scope, node, incoming_blocks.length, incoming_blocks.items, incoming_values.items); | 4176 | return ir_build_phi(irb, scope, node, incoming_blocks.length, incoming_blocks.items, incoming_values.items); |
| 5151 | } else if (var_symbol != nullptr) { | 4177 | } else if (var_symbol != nullptr) { |
| 5152 | ir_set_cursor_at_end(irb, cond_block); | 4178 | ir_set_cursor_at_end_and_append_block(irb, cond_block); |
| 5153 | // TODO make it an error to write to payload variable | 4179 | // TODO make it an error to write to payload variable |
| 5154 | AstNode *symbol_node = node; // TODO make more accurate | 4180 | AstNode *symbol_node = node; // TODO make more accurate |
| 5155 | VariableTableEntry *payload_var = ir_create_var(irb, symbol_node, scope, var_symbol, | 4181 | VariableTableEntry *payload_var = ir_create_var(irb, symbol_node, scope, var_symbol, |
| ... | @@ -5167,7 +4193,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n | ... | @@ -5167,7 +4193,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 5167 | body_block, else_block, is_comptime)); | 4193 | body_block, else_block, is_comptime)); |
| 5168 | } | 4194 | } |
| 5169 | | 4195 | |
| 5170 | ir_set_cursor_at_end(irb, body_block); | 4196 | ir_set_cursor_at_end_and_append_block(irb, body_block); |
| 5171 | IrInstruction *var_ptr_value = ir_build_unwrap_maybe(irb, child_scope, symbol_node, maybe_val_ptr, false); | 4197 | IrInstruction *var_ptr_value = ir_build_unwrap_maybe(irb, child_scope, symbol_node, maybe_val_ptr, false); |
| 5172 | IrInstruction *var_value = node->data.while_expr.var_is_ptr ? | 4198 | IrInstruction *var_value = node->data.while_expr.var_is_ptr ? |
| 5173 | var_ptr_value : ir_build_load_ptr(irb, child_scope, symbol_node, var_ptr_value); | 4199 | var_ptr_value : ir_build_load_ptr(irb, child_scope, symbol_node, var_ptr_value); |
| ... | @@ -5191,7 +4217,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n | ... | @@ -5191,7 +4217,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 5191 | ir_mark_gen(ir_build_br(irb, child_scope, node, continue_block, is_comptime)); | 4217 | ir_mark_gen(ir_build_br(irb, child_scope, node, continue_block, is_comptime)); |
| 5192 | | 4218 | |
| 5193 | if (continue_expr_node) { | 4219 | if (continue_expr_node) { |
| 5194 | ir_set_cursor_at_end(irb, continue_block); | 4220 | ir_set_cursor_at_end_and_append_block(irb, continue_block); |
| 5195 | IrInstruction *expr_result = ir_gen_node(irb, continue_expr_node, child_scope); | 4221 | IrInstruction *expr_result = ir_gen_node(irb, continue_expr_node, child_scope); |
| 5196 | if (expr_result == irb->codegen->invalid_instruction) | 4222 | if (expr_result == irb->codegen->invalid_instruction) |
| 5197 | return expr_result; | 4223 | return expr_result; |
| ... | @@ -5201,7 +4227,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n | ... | @@ -5201,7 +4227,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 5201 | | 4227 | |
| 5202 | IrInstruction *else_result = nullptr; | 4228 | IrInstruction *else_result = nullptr; |
| 5203 | if (else_node) { | 4229 | if (else_node) { |
| 5204 | ir_set_cursor_at_end(irb, else_block); | 4230 | ir_set_cursor_at_end_and_append_block(irb, else_block); |
| 5205 | | 4231 | |
| 5206 | else_result = ir_gen_node(irb, else_node, scope); | 4232 | else_result = ir_gen_node(irb, else_node, scope); |
| 5207 | if (else_result == irb->codegen->invalid_instruction) | 4233 | if (else_result == irb->codegen->invalid_instruction) |
| ... | @@ -5210,7 +4236,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n | ... | @@ -5210,7 +4236,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 5210 | ir_mark_gen(ir_build_br(irb, scope, node, end_block, is_comptime)); | 4236 | ir_mark_gen(ir_build_br(irb, scope, node, end_block, is_comptime)); |
| 5211 | } | 4237 | } |
| 5212 | IrBasicBlock *after_else_block = irb->current_basic_block; | 4238 | IrBasicBlock *after_else_block = irb->current_basic_block; |
| 5213 | ir_set_cursor_at_end(irb, end_block); | 4239 | ir_set_cursor_at_end_and_append_block(irb, end_block); |
| 5214 | if (else_result) { | 4240 | if (else_result) { |
| 5215 | incoming_blocks.append(after_else_block); | 4241 | incoming_blocks.append(after_else_block); |
| 5216 | incoming_values.append(else_result); | 4242 | incoming_values.append(else_result); |
| ... | @@ -5221,16 +4247,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n | ... | @@ -5221,16 +4247,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 5221 | | 4247 | |
| 5222 | return ir_build_phi(irb, scope, node, incoming_blocks.length, incoming_blocks.items, incoming_values.items); | 4248 | return ir_build_phi(irb, scope, node, incoming_blocks.length, incoming_blocks.items, incoming_values.items); |
| 5223 | } else { | 4249 | } else { |
| 5224 | if (continue_expr_node) { | 4250 | ir_set_cursor_at_end_and_append_block(irb, cond_block); |
| 5225 | ir_set_cursor_at_end(irb, continue_block); | | |
| 5226 | IrInstruction *expr_result = ir_gen_node(irb, continue_expr_node, scope); | | |
| 5227 | if (expr_result == irb->codegen->invalid_instruction) | | |
| 5228 | return expr_result; | | |
| 5229 | if (!instr_is_unreachable(expr_result)) | | |
| 5230 | ir_mark_gen(ir_build_br(irb, scope, node, cond_block, is_comptime)); | | |
| 5231 | } | | |
| 5232 | | | |
| 5233 | ir_set_cursor_at_end(irb, cond_block); | | |
| 5234 | IrInstruction *cond_val = ir_gen_node(irb, node->data.while_expr.condition, scope); | 4251 | IrInstruction *cond_val = ir_gen_node(irb, node->data.while_expr.condition, scope); |
| 5235 | if (cond_val == irb->codegen->invalid_instruction) | 4252 | if (cond_val == irb->codegen->invalid_instruction) |
| 5236 | return cond_val; | 4253 | return cond_val; |
| ... | @@ -5241,7 +4258,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n | ... | @@ -5241,7 +4258,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 5241 | body_block, else_block, is_comptime)); | 4258 | body_block, else_block, is_comptime)); |
| 5242 | } | 4259 | } |
| 5243 | | 4260 | |
| 5244 | ir_set_cursor_at_end(irb, body_block); | 4261 | ir_set_cursor_at_end_and_append_block(irb, body_block); |
| 5245 | | 4262 | |
| 5246 | ZigList<IrInstruction *> incoming_values = {0}; | 4263 | ZigList<IrInstruction *> incoming_values = {0}; |
| 5247 | ZigList<IrBasicBlock *> incoming_blocks = {0}; | 4264 | ZigList<IrBasicBlock *> incoming_blocks = {0}; |
| ... | @@ -5260,9 +4277,18 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n | ... | @@ -5260,9 +4277,18 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 5260 | if (!instr_is_unreachable(body_result)) | 4277 | if (!instr_is_unreachable(body_result)) |
| 5261 | ir_mark_gen(ir_build_br(irb, scope, node, continue_block, is_comptime)); | 4278 | ir_mark_gen(ir_build_br(irb, scope, node, continue_block, is_comptime)); |
| 5262 | | 4279 | |
| | 4280 | if (continue_expr_node) { |
| | 4281 | ir_set_cursor_at_end_and_append_block(irb, continue_block); |
| | 4282 | IrInstruction *expr_result = ir_gen_node(irb, continue_expr_node, scope); |
| | 4283 | if (expr_result == irb->codegen->invalid_instruction) |
| | 4284 | return expr_result; |
| | 4285 | if (!instr_is_unreachable(expr_result)) |
| | 4286 | ir_mark_gen(ir_build_br(irb, scope, node, cond_block, is_comptime)); |
| | 4287 | } |
| | 4288 | |
| 5263 | IrInstruction *else_result = nullptr; | 4289 | IrInstruction *else_result = nullptr; |
| 5264 | if (else_node) { | 4290 | if (else_node) { |
| 5265 | ir_set_cursor_at_end(irb, else_block); | 4291 | ir_set_cursor_at_end_and_append_block(irb, else_block); |
| 5266 | | 4292 | |
| 5267 | else_result = ir_gen_node(irb, else_node, scope); | 4293 | else_result = ir_gen_node(irb, else_node, scope); |
| 5268 | if (else_result == irb->codegen->invalid_instruction) | 4294 | if (else_result == irb->codegen->invalid_instruction) |
| ... | @@ -5271,7 +4297,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n | ... | @@ -5271,7 +4297,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 5271 | ir_mark_gen(ir_build_br(irb, scope, node, end_block, is_comptime)); | 4297 | ir_mark_gen(ir_build_br(irb, scope, node, end_block, is_comptime)); |
| 5272 | } | 4298 | } |
| 5273 | IrBasicBlock *after_else_block = irb->current_basic_block; | 4299 | IrBasicBlock *after_else_block = irb->current_basic_block; |
| 5274 | ir_set_cursor_at_end(irb, end_block); | 4300 | ir_set_cursor_at_end_and_append_block(irb, end_block); |
| 5275 | if (else_result) { | 4301 | if (else_result) { |
| 5276 | incoming_blocks.append(after_else_block); | 4302 | incoming_blocks.append(after_else_block); |
| 5277 | incoming_values.append(else_result); | 4303 | incoming_values.append(else_result); |
| ... | @@ -5344,23 +4370,23 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo | ... | @@ -5344,23 +4370,23 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo |
| 5344 | IrInstruction *index_ptr = ir_build_var_ptr(irb, child_scope, node, index_var, false, false); | 4370 | IrInstruction *index_ptr = ir_build_var_ptr(irb, child_scope, node, index_var, false, false); |
| 5345 | | 4371 | |
| 5346 | | 4372 | |
| 5347 | IrBasicBlock *cond_block = ir_build_basic_block(irb, child_scope, "ForCond"); | 4373 | IrBasicBlock *cond_block = ir_create_basic_block(irb, child_scope, "ForCond"); |
| 5348 | IrBasicBlock *body_block = ir_build_basic_block(irb, child_scope, "ForBody"); | 4374 | IrBasicBlock *body_block = ir_create_basic_block(irb, child_scope, "ForBody"); |
| 5349 | IrBasicBlock *end_block = ir_build_basic_block(irb, child_scope, "ForEnd"); | 4375 | IrBasicBlock *end_block = ir_create_basic_block(irb, child_scope, "ForEnd"); |
| 5350 | IrBasicBlock *else_block = else_node ? ir_build_basic_block(irb, child_scope, "ForElse") : end_block; | 4376 | IrBasicBlock *else_block = else_node ? ir_create_basic_block(irb, child_scope, "ForElse") : end_block; |
| 5351 | IrBasicBlock *continue_block = ir_build_basic_block(irb, child_scope, "ForContinue"); | 4377 | IrBasicBlock *continue_block = ir_create_basic_block(irb, child_scope, "ForContinue"); |
| 5352 | | 4378 | |
| 5353 | IrInstruction *len_val = ir_build_array_len(irb, child_scope, node, array_val); | 4379 | IrInstruction *len_val = ir_build_array_len(irb, child_scope, node, array_val); |
| 5354 | ir_build_br(irb, child_scope, node, cond_block, is_comptime); | 4380 | ir_build_br(irb, child_scope, node, cond_block, is_comptime); |
| 5355 | | 4381 | |
| 5356 | ir_set_cursor_at_end(irb, cond_block); | 4382 | ir_set_cursor_at_end_and_append_block(irb, cond_block); |
| 5357 | IrInstruction *index_val = ir_build_load_ptr(irb, child_scope, node, index_ptr); | 4383 | IrInstruction *index_val = ir_build_load_ptr(irb, child_scope, node, index_ptr); |
| 5358 | IrInstruction *cond = ir_build_bin_op(irb, child_scope, node, IrBinOpCmpLessThan, index_val, len_val, false); | 4384 | IrInstruction *cond = ir_build_bin_op(irb, child_scope, node, IrBinOpCmpLessThan, index_val, len_val, false); |
| 5359 | IrBasicBlock *after_cond_block = irb->current_basic_block; | 4385 | IrBasicBlock *after_cond_block = irb->current_basic_block; |
| 5360 | IrInstruction *void_else_value = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, parent_scope, node)); | 4386 | IrInstruction *void_else_value = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, parent_scope, node)); |
| 5361 | ir_mark_gen(ir_build_cond_br(irb, child_scope, node, cond, body_block, else_block, is_comptime)); | 4387 | ir_mark_gen(ir_build_cond_br(irb, child_scope, node, cond, body_block, else_block, is_comptime)); |
| 5362 | | 4388 | |
| 5363 | ir_set_cursor_at_end(irb, body_block); | 4389 | ir_set_cursor_at_end_and_append_block(irb, body_block); |
| 5364 | IrInstruction *elem_ptr = ir_build_elem_ptr(irb, child_scope, node, array_val_ptr, index_val, false); | 4390 | IrInstruction *elem_ptr = ir_build_elem_ptr(irb, child_scope, node, array_val_ptr, index_val, false); |
| 5365 | IrInstruction *elem_val; | 4391 | IrInstruction *elem_val; |
| 5366 | if (node->data.for_expr.elem_is_ptr) { | 4392 | if (node->data.for_expr.elem_is_ptr) { |
| ... | @@ -5384,14 +4410,14 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo | ... | @@ -5384,14 +4410,14 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo |
| 5384 | if (!instr_is_unreachable(body_result)) | 4410 | if (!instr_is_unreachable(body_result)) |
| 5385 | ir_mark_gen(ir_build_br(irb, child_scope, node, continue_block, is_comptime)); | 4411 | ir_mark_gen(ir_build_br(irb, child_scope, node, continue_block, is_comptime)); |
| 5386 | | 4412 | |
| 5387 | ir_set_cursor_at_end(irb, continue_block); | 4413 | ir_set_cursor_at_end_and_append_block(irb, continue_block); |
| 5388 | IrInstruction *new_index_val = ir_build_bin_op(irb, child_scope, node, IrBinOpAdd, index_val, one, false); | 4414 | IrInstruction *new_index_val = ir_build_bin_op(irb, child_scope, node, IrBinOpAdd, index_val, one, false); |
| 5389 | ir_mark_gen(ir_build_store_ptr(irb, child_scope, node, index_ptr, new_index_val)); | 4415 | ir_mark_gen(ir_build_store_ptr(irb, child_scope, node, index_ptr, new_index_val)); |
| 5390 | ir_build_br(irb, child_scope, node, cond_block, is_comptime); | 4416 | ir_build_br(irb, child_scope, node, cond_block, is_comptime); |
| 5391 | | 4417 | |
| 5392 | IrInstruction *else_result = nullptr; | 4418 | IrInstruction *else_result = nullptr; |
| 5393 | if (else_node) { | 4419 | if (else_node) { |
| 5394 | ir_set_cursor_at_end(irb, else_block); | 4420 | ir_set_cursor_at_end_and_append_block(irb, else_block); |
| 5395 | | 4421 | |
| 5396 | else_result = ir_gen_node(irb, else_node, parent_scope); | 4422 | else_result = ir_gen_node(irb, else_node, parent_scope); |
| 5397 | if (else_result == irb->codegen->invalid_instruction) | 4423 | if (else_result == irb->codegen->invalid_instruction) |
| ... | @@ -5400,7 +4426,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo | ... | @@ -5400,7 +4426,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo |
| 5400 | ir_mark_gen(ir_build_br(irb, parent_scope, node, end_block, is_comptime)); | 4426 | ir_mark_gen(ir_build_br(irb, parent_scope, node, end_block, is_comptime)); |
| 5401 | } | 4427 | } |
| 5402 | IrBasicBlock *after_else_block = irb->current_basic_block; | 4428 | IrBasicBlock *after_else_block = irb->current_basic_block; |
| 5403 | ir_set_cursor_at_end(irb, end_block); | 4429 | ir_set_cursor_at_end_and_append_block(irb, end_block); |
| 5404 | | 4430 | |
| 5405 | if (else_result) { | 4431 | if (else_result) { |
| 5406 | incoming_blocks.append(after_else_block); | 4432 | incoming_blocks.append(after_else_block); |
| ... | @@ -5577,9 +4603,9 @@ static IrInstruction *ir_gen_test_expr(IrBuilder *irb, Scope *scope, AstNode *no | ... | @@ -5577,9 +4603,9 @@ static IrInstruction *ir_gen_test_expr(IrBuilder *irb, Scope *scope, AstNode *no |
| 5577 | IrInstruction *maybe_val = ir_build_load_ptr(irb, scope, node, maybe_val_ptr); | 4603 | IrInstruction *maybe_val = ir_build_load_ptr(irb, scope, node, maybe_val_ptr); |
| 5578 | IrInstruction *is_non_null = ir_build_test_nonnull(irb, scope, node, maybe_val); | 4604 | IrInstruction *is_non_null = ir_build_test_nonnull(irb, scope, node, maybe_val); |
| 5579 | | 4605 | |
| 5580 | IrBasicBlock *then_block = ir_build_basic_block(irb, scope, "MaybeThen"); | 4606 | IrBasicBlock *then_block = ir_create_basic_block(irb, scope, "MaybeThen"); |
| 5581 | IrBasicBlock *else_block = ir_build_basic_block(irb, scope, "MaybeElse"); | 4607 | IrBasicBlock *else_block = ir_create_basic_block(irb, scope, "MaybeElse"); |
| 5582 | IrBasicBlock *endif_block = ir_build_basic_block(irb, scope, "MaybeEndIf"); | 4608 | IrBasicBlock *endif_block = ir_create_basic_block(irb, scope, "MaybeEndIf"); |
| 5583 | | 4609 | |
| 5584 | IrInstruction *is_comptime; | 4610 | IrInstruction *is_comptime; |
| 5585 | if (ir_should_inline(irb->exec, scope)) { | 4611 | if (ir_should_inline(irb->exec, scope)) { |
| ... | @@ -5589,7 +4615,7 @@ static IrInstruction *ir_gen_test_expr(IrBuilder *irb, Scope *scope, AstNode *no | ... | @@ -5589,7 +4615,7 @@ static IrInstruction *ir_gen_test_expr(IrBuilder *irb, Scope *scope, AstNode *no |
| 5589 | } | 4615 | } |
| 5590 | ir_build_cond_br(irb, scope, node, is_non_null, then_block, else_block, is_comptime); | 4616 | ir_build_cond_br(irb, scope, node, is_non_null, then_block, else_block, is_comptime); |
| 5591 | | 4617 | |
| 5592 | ir_set_cursor_at_end(irb, then_block); | 4618 | ir_set_cursor_at_end_and_append_block(irb, then_block); |
| 5593 | | 4619 | |
| 5594 | Scope *var_scope; | 4620 | Scope *var_scope; |
| 5595 | if (var_symbol) { | 4621 | if (var_symbol) { |
| ... | @@ -5613,7 +4639,7 @@ static IrInstruction *ir_gen_test_expr(IrBuilder *irb, Scope *scope, AstNode *no | ... | @@ -5613,7 +4639,7 @@ static IrInstruction *ir_gen_test_expr(IrBuilder *irb, Scope *scope, AstNode *no |
| 5613 | if (!instr_is_unreachable(then_expr_result)) | 4639 | if (!instr_is_unreachable(then_expr_result)) |
| 5614 | ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime)); | 4640 | ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime)); |
| 5615 | | 4641 | |
| 5616 | ir_set_cursor_at_end(irb, else_block); | 4642 | ir_set_cursor_at_end_and_append_block(irb, else_block); |
| 5617 | IrInstruction *else_expr_result; | 4643 | IrInstruction *else_expr_result; |
| 5618 | if (else_node) { | 4644 | if (else_node) { |
| 5619 | else_expr_result = ir_gen_node(irb, else_node, scope); | 4645 | else_expr_result = ir_gen_node(irb, else_node, scope); |
| ... | @@ -5626,7 +4652,7 @@ static IrInstruction *ir_gen_test_expr(IrBuilder *irb, Scope *scope, AstNode *no | ... | @@ -5626,7 +4652,7 @@ static IrInstruction *ir_gen_test_expr(IrBuilder *irb, Scope *scope, AstNode *no |
| 5626 | if (!instr_is_unreachable(else_expr_result)) | 4652 | if (!instr_is_unreachable(else_expr_result)) |
| 5627 | ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime)); | 4653 | ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime)); |
| 5628 | | 4654 | |
| 5629 | ir_set_cursor_at_end(irb, endif_block); | 4655 | ir_set_cursor_at_end_and_append_block(irb, endif_block); |
| 5630 | IrInstruction **incoming_values = allocate<IrInstruction *>(2); | 4656 | IrInstruction **incoming_values = allocate<IrInstruction *>(2); |
| 5631 | incoming_values[0] = then_expr_result; | 4657 | incoming_values[0] = then_expr_result; |
| 5632 | incoming_values[1] = else_expr_result; | 4658 | incoming_values[1] = else_expr_result; |
| ... | @@ -5655,9 +4681,9 @@ static IrInstruction *ir_gen_try_expr(IrBuilder *irb, Scope *scope, AstNode *nod | ... | @@ -5655,9 +4681,9 @@ static IrInstruction *ir_gen_try_expr(IrBuilder *irb, Scope *scope, AstNode *nod |
| 5655 | IrInstruction *err_val = ir_build_load_ptr(irb, scope, node, err_val_ptr); | 4681 | IrInstruction *err_val = ir_build_load_ptr(irb, scope, node, err_val_ptr); |
| 5656 | IrInstruction *is_err = ir_build_test_err(irb, scope, node, err_val); | 4682 | IrInstruction *is_err = ir_build_test_err(irb, scope, node, err_val); |
| 5657 | | 4683 | |
| 5658 | IrBasicBlock *ok_block = ir_build_basic_block(irb, scope, "TryOk"); | 4684 | IrBasicBlock *ok_block = ir_create_basic_block(irb, scope, "TryOk"); |
| 5659 | IrBasicBlock *else_block = ir_build_basic_block(irb, scope, "TryElse"); | 4685 | IrBasicBlock *else_block = ir_create_basic_block(irb, scope, "TryElse"); |
| 5660 | IrBasicBlock *endif_block = ir_build_basic_block(irb, scope, "TryEnd"); | 4686 | IrBasicBlock *endif_block = ir_create_basic_block(irb, scope, "TryEnd"); |
| 5661 | | 4687 | |
| 5662 | IrInstruction *is_comptime; | 4688 | IrInstruction *is_comptime; |
| 5663 | if (ir_should_inline(irb->exec, scope)) { | 4689 | if (ir_should_inline(irb->exec, scope)) { |
| ... | @@ -5667,7 +4693,7 @@ static IrInstruction *ir_gen_try_expr(IrBuilder *irb, Scope *scope, AstNode *nod | ... | @@ -5667,7 +4693,7 @@ static IrInstruction *ir_gen_try_expr(IrBuilder *irb, Scope *scope, AstNode *nod |
| 5667 | } | 4693 | } |
| 5668 | ir_build_cond_br(irb, scope, node, is_err, else_block, ok_block, is_comptime); | 4694 | ir_build_cond_br(irb, scope, node, is_err, else_block, ok_block, is_comptime); |
| 5669 | | 4695 | |
| 5670 | ir_set_cursor_at_end(irb, ok_block); | 4696 | ir_set_cursor_at_end_and_append_block(irb, ok_block); |
| 5671 | | 4697 | |
| 5672 | Scope *var_scope; | 4698 | Scope *var_scope; |
| 5673 | if (var_symbol) { | 4699 | if (var_symbol) { |
| ... | @@ -5690,7 +4716,7 @@ static IrInstruction *ir_gen_try_expr(IrBuilder *irb, Scope *scope, AstNode *nod | ... | @@ -5690,7 +4716,7 @@ static IrInstruction *ir_gen_try_expr(IrBuilder *irb, Scope *scope, AstNode *nod |
| 5690 | if (!instr_is_unreachable(then_expr_result)) | 4716 | if (!instr_is_unreachable(then_expr_result)) |
| 5691 | ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime)); | 4717 | ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime)); |
| 5692 | | 4718 | |
| 5693 | ir_set_cursor_at_end(irb, else_block); | 4719 | ir_set_cursor_at_end_and_append_block(irb, else_block); |
| 5694 | | 4720 | |
| 5695 | IrInstruction *else_expr_result; | 4721 | IrInstruction *else_expr_result; |
| 5696 | if (else_node) { | 4722 | if (else_node) { |
| ... | @@ -5718,7 +4744,7 @@ static IrInstruction *ir_gen_try_expr(IrBuilder *irb, Scope *scope, AstNode *nod | ... | @@ -5718,7 +4744,7 @@ static IrInstruction *ir_gen_try_expr(IrBuilder *irb, Scope *scope, AstNode *nod |
| 5718 | if (!instr_is_unreachable(else_expr_result)) | 4744 | if (!instr_is_unreachable(else_expr_result)) |
| 5719 | ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime)); | 4745 | ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime)); |
| 5720 | | 4746 | |
| 5721 | ir_set_cursor_at_end(irb, endif_block); | 4747 | ir_set_cursor_at_end_and_append_block(irb, endif_block); |
| 5722 | IrInstruction **incoming_values = allocate<IrInstruction *>(2); | 4748 | IrInstruction **incoming_values = allocate<IrInstruction *>(2); |
| 5723 | incoming_values[0] = then_expr_result; | 4749 | incoming_values[0] = then_expr_result; |
| 5724 | incoming_values[1] = else_expr_result; | 4750 | incoming_values[1] = else_expr_result; |
| ... | @@ -5781,8 +4807,8 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * | ... | @@ -5781,8 +4807,8 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 5781 | return target_value_ptr; | 4807 | return target_value_ptr; |
| 5782 | IrInstruction *target_value = ir_build_switch_target(irb, scope, node, target_value_ptr); | 4808 | IrInstruction *target_value = ir_build_switch_target(irb, scope, node, target_value_ptr); |
| 5783 | | 4809 | |
| 5784 | IrBasicBlock *else_block = ir_build_basic_block(irb, scope, "SwitchElse"); | 4810 | IrBasicBlock *else_block = ir_create_basic_block(irb, scope, "SwitchElse"); |
| 5785 | IrBasicBlock *end_block = ir_build_basic_block(irb, scope, "SwitchEnd"); | 4811 | IrBasicBlock *end_block = ir_create_basic_block(irb, scope, "SwitchEnd"); |
| 5786 | | 4812 | |
| 5787 | size_t prong_count = node->data.switch_expr.prongs.length; | 4813 | size_t prong_count = node->data.switch_expr.prongs.length; |
| 5788 | ZigList<IrInstructionSwitchBrCase> cases = {0}; | 4814 | ZigList<IrInstructionSwitchBrCase> cases = {0}; |
| ... | @@ -5798,6 +4824,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * | ... | @@ -5798,6 +4824,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 5798 | ZigList<IrBasicBlock *> incoming_blocks = {0}; | 4824 | ZigList<IrBasicBlock *> incoming_blocks = {0}; |
| 5799 | ZigList<IrInstructionCheckSwitchProngsRange> check_ranges = {0}; | 4825 | ZigList<IrInstructionCheckSwitchProngsRange> check_ranges = {0}; |
| 5800 | | 4826 | |
| | 4827 | // First do the else and the ranges |
| 5801 | Scope *comptime_scope = create_comptime_scope(node, scope); | 4828 | Scope *comptime_scope = create_comptime_scope(node, scope); |
| 5802 | AstNode *else_prong = nullptr; | 4829 | AstNode *else_prong = nullptr; |
| 5803 | for (size_t prong_i = 0; prong_i < prong_count; prong_i += 1) { | 4830 | for (size_t prong_i = 0; prong_i < prong_count; prong_i += 1) { |
| ... | @@ -5814,90 +4841,47 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * | ... | @@ -5814,90 +4841,47 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 5814 | else_prong = prong_node; | 4841 | else_prong = prong_node; |
| 5815 | | 4842 | |
| 5816 | IrBasicBlock *prev_block = irb->current_basic_block; | 4843 | IrBasicBlock *prev_block = irb->current_basic_block; |
| 5817 | ir_set_cursor_at_end(irb, else_block); | 4844 | ir_set_cursor_at_end_and_append_block(irb, else_block); |
| 5818 | if (!ir_gen_switch_prong_expr(irb, scope, node, prong_node, end_block, | 4845 | if (!ir_gen_switch_prong_expr(irb, scope, node, prong_node, end_block, |
| 5819 | is_comptime, target_value_ptr, nullptr, &incoming_blocks, &incoming_values)) | 4846 | is_comptime, target_value_ptr, nullptr, &incoming_blocks, &incoming_values)) |
| 5820 | { | 4847 | { |
| 5821 | return irb->codegen->invalid_instruction; | 4848 | return irb->codegen->invalid_instruction; |
| 5822 | } | 4849 | } |
| 5823 | ir_set_cursor_at_end(irb, prev_block); | 4850 | ir_set_cursor_at_end(irb, prev_block); |
| 5824 | } else { | 4851 | } else if (prong_node->data.switch_prong.any_items_are_range) { |
| 5825 | if (prong_node->data.switch_prong.any_items_are_range) { | 4852 | IrInstruction *ok_bit = nullptr; |
| 5826 | IrInstruction *ok_bit = nullptr; | 4853 | AstNode *last_item_node = nullptr; |
| 5827 | AstNode *last_item_node = nullptr; | 4854 | for (size_t item_i = 0; item_i < prong_item_count; item_i += 1) { |
| 5828 | for (size_t item_i = 0; item_i < prong_item_count; item_i += 1) { | 4855 | AstNode *item_node = prong_node->data.switch_prong.items.at(item_i); |
| 5829 | AstNode *item_node = prong_node->data.switch_prong.items.at(item_i); | 4856 | last_item_node = item_node; |
| 5830 | last_item_node = item_node; | 4857 | if (item_node->type == NodeTypeSwitchRange) { |
| 5831 | if (item_node->type == NodeTypeSwitchRange) { | 4858 | AstNode *start_node = item_node->data.switch_range.start; |
| 5832 | AstNode *start_node = item_node->data.switch_range.start; | 4859 | AstNode *end_node = item_node->data.switch_range.end; |
| 5833 | AstNode *end_node = item_node->data.switch_range.end; | 4860 | |
| 5834 | | 4861 | IrInstruction *start_value = ir_gen_node(irb, start_node, comptime_scope); |
| 5835 | IrInstruction *start_value = ir_gen_node(irb, start_node, comptime_scope); | 4862 | if (start_value == irb->codegen->invalid_instruction) |
| 5836 | if (start_value == irb->codegen->invalid_instruction) | 4863 | return irb->codegen->invalid_instruction; |
| 5837 | return irb->codegen->invalid_instruction; | | |
| 5838 | | | |
| 5839 | IrInstruction *end_value = ir_gen_node(irb, end_node, comptime_scope); | | |
| 5840 | if (end_value == irb->codegen->invalid_instruction) | | |
| 5841 | return irb->codegen->invalid_instruction; | | |
| 5842 | | | |
| 5843 | IrInstructionCheckSwitchProngsRange *check_range = check_ranges.add_one(); | | |
| 5844 | check_range->start = start_value; | | |
| 5845 | check_range->end = end_value; | | |
| 5846 | | | |
| 5847 | IrInstruction *lower_range_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpGreaterOrEq, | | |
| 5848 | target_value, start_value, false); | | |
| 5849 | IrInstruction *upper_range_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpLessOrEq, | | |
| 5850 | target_value, end_value, false); | | |
| 5851 | IrInstruction *both_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpBoolAnd, | | |
| 5852 | lower_range_ok, upper_range_ok, false); | | |
| 5853 | if (ok_bit) { | | |
| 5854 | ok_bit = ir_build_bin_op(irb, scope, item_node, IrBinOpBoolOr, both_ok, ok_bit, false); | | |
| 5855 | } else { | | |
| 5856 | ok_bit = both_ok; | | |
| 5857 | } | | |
| 5858 | } else { | | |
| 5859 | IrInstruction *item_value = ir_gen_node(irb, item_node, comptime_scope); | | |
| 5860 | if (item_value == irb->codegen->invalid_instruction) | | |
| 5861 | return irb->codegen->invalid_instruction; | | |
| 5862 | | | |
| 5863 | IrInstructionCheckSwitchProngsRange *check_range = check_ranges.add_one(); | | |
| 5864 | check_range->start = item_value; | | |
| 5865 | check_range->end = item_value; | | |
| 5866 | | | |
| 5867 | IrInstruction *cmp_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpEq, | | |
| 5868 | item_value, target_value, false); | | |
| 5869 | if (ok_bit) { | | |
| 5870 | ok_bit = ir_build_bin_op(irb, scope, item_node, IrBinOpBoolOr, cmp_ok, ok_bit, false); | | |
| 5871 | } else { | | |
| 5872 | ok_bit = cmp_ok; | | |
| 5873 | } | | |
| 5874 | } | | |
| 5875 | } | | |
| 5876 | | | |
| 5877 | IrBasicBlock *range_block_yes = ir_build_basic_block(irb, scope, "SwitchRangeYes"); | | |
| 5878 | IrBasicBlock *range_block_no = ir_build_basic_block(irb, scope, "SwitchRangeNo"); | | |
| 5879 | | | |
| 5880 | assert(ok_bit); | | |
| 5881 | assert(last_item_node); | | |
| 5882 | ir_mark_gen(ir_build_cond_br(irb, scope, last_item_node, ok_bit, range_block_yes, | | |
| 5883 | range_block_no, is_comptime)); | | |
| 5884 | | | |
| 5885 | ir_set_cursor_at_end(irb, range_block_yes); | | |
| 5886 | if (!ir_gen_switch_prong_expr(irb, scope, node, prong_node, end_block, | | |
| 5887 | is_comptime, target_value_ptr, nullptr, &incoming_blocks, &incoming_values)) | | |
| 5888 | { | | |
| 5889 | return irb->codegen->invalid_instruction; | | |
| 5890 | } | | |
| 5891 | | | |
| 5892 | ir_set_cursor_at_end(irb, range_block_no); | | |
| 5893 | } else { | | |
| 5894 | IrBasicBlock *prong_block = ir_build_basic_block(irb, scope, "SwitchProng"); | | |
| 5895 | IrInstruction *last_item_value = nullptr; | | |
| 5896 | | 4864 | |
| 5897 | for (size_t item_i = 0; item_i < prong_item_count; item_i += 1) { | 4865 | IrInstruction *end_value = ir_gen_node(irb, end_node, comptime_scope); |
| 5898 | AstNode *item_node = prong_node->data.switch_prong.items.at(item_i); | 4866 | if (end_value == irb->codegen->invalid_instruction) |
| 5899 | assert(item_node->type != NodeTypeSwitchRange); | 4867 | return irb->codegen->invalid_instruction; |
| 5900 | | 4868 | |
| | 4869 | IrInstructionCheckSwitchProngsRange *check_range = check_ranges.add_one(); |
| | 4870 | check_range->start = start_value; |
| | 4871 | check_range->end = end_value; |
| | 4872 | |
| | 4873 | IrInstruction *lower_range_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpGreaterOrEq, |
| | 4874 | target_value, start_value, false); |
| | 4875 | IrInstruction *upper_range_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpLessOrEq, |
| | 4876 | target_value, end_value, false); |
| | 4877 | IrInstruction *both_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpBoolAnd, |
| | 4878 | lower_range_ok, upper_range_ok, false); |
| | 4879 | if (ok_bit) { |
| | 4880 | ok_bit = ir_build_bin_op(irb, scope, item_node, IrBinOpBoolOr, both_ok, ok_bit, false); |
| | 4881 | } else { |
| | 4882 | ok_bit = both_ok; |
| | 4883 | } |
| | 4884 | } else { |
| 5901 | IrInstruction *item_value = ir_gen_node(irb, item_node, comptime_scope); | 4885 | IrInstruction *item_value = ir_gen_node(irb, item_node, comptime_scope); |
| 5902 | if (item_value == irb->codegen->invalid_instruction) | 4886 | if (item_value == irb->codegen->invalid_instruction) |
| 5903 | return irb->codegen->invalid_instruction; | 4887 | return irb->codegen->invalid_instruction; |
| ... | @@ -5906,26 +4890,77 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * | ... | @@ -5906,26 +4890,77 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 5906 | check_range->start = item_value; | 4890 | check_range->start = item_value; |
| 5907 | check_range->end = item_value; | 4891 | check_range->end = item_value; |
| 5908 | | 4892 | |
| 5909 | IrInstructionSwitchBrCase *this_case = cases.add_one(); | 4893 | IrInstruction *cmp_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpEq, |
| 5910 | this_case->value = item_value; | 4894 | item_value, target_value, false); |
| 5911 | this_case->block = prong_block; | 4895 | if (ok_bit) { |
| 5912 | | 4896 | ok_bit = ir_build_bin_op(irb, scope, item_node, IrBinOpBoolOr, cmp_ok, ok_bit, false); |
| 5913 | last_item_value = item_value; | 4897 | } else { |
| | 4898 | ok_bit = cmp_ok; |
| | 4899 | } |
| 5914 | } | 4900 | } |
| 5915 | IrInstruction *only_item_value = (prong_item_count == 1) ? last_item_value : nullptr; | 4901 | } |
| 5916 | | 4902 | |
| 5917 | IrBasicBlock *prev_block = irb->current_basic_block; | 4903 | IrBasicBlock *range_block_yes = ir_create_basic_block(irb, scope, "SwitchRangeYes"); |
| 5918 | ir_set_cursor_at_end(irb, prong_block); | 4904 | IrBasicBlock *range_block_no = ir_create_basic_block(irb, scope, "SwitchRangeNo"); |
| 5919 | if (!ir_gen_switch_prong_expr(irb, scope, node, prong_node, end_block, | | |
| 5920 | is_comptime, target_value_ptr, only_item_value, &incoming_blocks, &incoming_values)) | | |
| 5921 | { | | |
| 5922 | return irb->codegen->invalid_instruction; | | |
| 5923 | } | | |
| 5924 | | 4905 | |
| 5925 | ir_set_cursor_at_end(irb, prev_block); | 4906 | assert(ok_bit); |
| | 4907 | assert(last_item_node); |
| | 4908 | ir_mark_gen(ir_build_cond_br(irb, scope, last_item_node, ok_bit, range_block_yes, |
| | 4909 | range_block_no, is_comptime)); |
| 5926 | | 4910 | |
| | 4911 | ir_set_cursor_at_end_and_append_block(irb, range_block_yes); |
| | 4912 | if (!ir_gen_switch_prong_expr(irb, scope, node, prong_node, end_block, |
| | 4913 | is_comptime, target_value_ptr, nullptr, &incoming_blocks, &incoming_values)) |
| | 4914 | { |
| | 4915 | return irb->codegen->invalid_instruction; |
| 5927 | } | 4916 | } |
| | 4917 | |
| | 4918 | ir_set_cursor_at_end_and_append_block(irb, range_block_no); |
| | 4919 | } |
| | 4920 | } |
| | 4921 | |
| | 4922 | // next do the non-else non-ranges |
| | 4923 | for (size_t prong_i = 0; prong_i < prong_count; prong_i += 1) { |
| | 4924 | AstNode *prong_node = node->data.switch_expr.prongs.at(prong_i); |
| | 4925 | size_t prong_item_count = prong_node->data.switch_prong.items.length; |
| | 4926 | if (prong_item_count == 0) |
| | 4927 | continue; |
| | 4928 | if (prong_node->data.switch_prong.any_items_are_range) |
| | 4929 | continue; |
| | 4930 | |
| | 4931 | IrBasicBlock *prong_block = ir_create_basic_block(irb, scope, "SwitchProng"); |
| | 4932 | IrInstruction *last_item_value = nullptr; |
| | 4933 | |
| | 4934 | for (size_t item_i = 0; item_i < prong_item_count; item_i += 1) { |
| | 4935 | AstNode *item_node = prong_node->data.switch_prong.items.at(item_i); |
| | 4936 | assert(item_node->type != NodeTypeSwitchRange); |
| | 4937 | |
| | 4938 | IrInstruction *item_value = ir_gen_node(irb, item_node, comptime_scope); |
| | 4939 | if (item_value == irb->codegen->invalid_instruction) |
| | 4940 | return irb->codegen->invalid_instruction; |
| | 4941 | |
| | 4942 | IrInstructionCheckSwitchProngsRange *check_range = check_ranges.add_one(); |
| | 4943 | check_range->start = item_value; |
| | 4944 | check_range->end = item_value; |
| | 4945 | |
| | 4946 | IrInstructionSwitchBrCase *this_case = cases.add_one(); |
| | 4947 | this_case->value = item_value; |
| | 4948 | this_case->block = prong_block; |
| | 4949 | |
| | 4950 | last_item_value = item_value; |
| | 4951 | } |
| | 4952 | IrInstruction *only_item_value = (prong_item_count == 1) ? last_item_value : nullptr; |
| | 4953 | |
| | 4954 | IrBasicBlock *prev_block = irb->current_basic_block; |
| | 4955 | ir_set_cursor_at_end_and_append_block(irb, prong_block); |
| | 4956 | if (!ir_gen_switch_prong_expr(irb, scope, node, prong_node, end_block, |
| | 4957 | is_comptime, target_value_ptr, only_item_value, &incoming_blocks, &incoming_values)) |
| | 4958 | { |
| | 4959 | return irb->codegen->invalid_instruction; |
| 5928 | } | 4960 | } |
| | 4961 | |
| | 4962 | ir_set_cursor_at_end(irb, prev_block); |
| | 4963 | |
| 5929 | } | 4964 | } |
| 5930 | | 4965 | |
| 5931 | ir_build_check_switch_prongs(irb, scope, node, target_value, check_ranges.items, check_ranges.length, | 4966 | ir_build_check_switch_prongs(irb, scope, node, target_value, check_ranges.items, check_ranges.length, |
| ... | @@ -5938,11 +4973,11 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * | ... | @@ -5938,11 +4973,11 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 5938 | } | 4973 | } |
| 5939 | | 4974 | |
| 5940 | if (!else_prong) { | 4975 | if (!else_prong) { |
| 5941 | ir_set_cursor_at_end(irb, else_block); | 4976 | ir_set_cursor_at_end_and_append_block(irb, else_block); |
| 5942 | ir_build_unreachable(irb, scope, node); | 4977 | ir_build_unreachable(irb, scope, node); |
| 5943 | } | 4978 | } |
| 5944 | | 4979 | |
| 5945 | ir_set_cursor_at_end(irb, end_block); | 4980 | ir_set_cursor_at_end_and_append_block(irb, end_block); |
| 5946 | assert(incoming_blocks.length == incoming_values.length); | 4981 | assert(incoming_blocks.length == incoming_values.length); |
| 5947 | return ir_build_phi(irb, scope, node, incoming_blocks.length, incoming_blocks.items, incoming_values.items); | 4982 | return ir_build_phi(irb, scope, node, incoming_blocks.length, incoming_blocks.items, incoming_values.items); |
| 5948 | } | 4983 | } |
| ... | @@ -6158,12 +5193,12 @@ static IrInstruction *ir_gen_err_ok_or(IrBuilder *irb, Scope *parent_scope, AstN | ... | @@ -6158,12 +5193,12 @@ static IrInstruction *ir_gen_err_ok_or(IrBuilder *irb, Scope *parent_scope, AstN |
| 6158 | is_comptime = ir_build_test_comptime(irb, parent_scope, node, is_err); | 5193 | is_comptime = ir_build_test_comptime(irb, parent_scope, node, is_err); |
| 6159 | } | 5194 | } |
| 6160 | | 5195 | |
| 6161 | IrBasicBlock *ok_block = ir_build_basic_block(irb, parent_scope, "UnwrapErrOk"); | 5196 | IrBasicBlock *ok_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrOk"); |
| 6162 | IrBasicBlock *err_block = ir_build_basic_block(irb, parent_scope, "UnwrapErrError"); | 5197 | IrBasicBlock *err_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrError"); |
| 6163 | IrBasicBlock *end_block = ir_build_basic_block(irb, parent_scope, "UnwrapErrEnd"); | 5198 | IrBasicBlock *end_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrEnd"); |
| 6164 | ir_build_cond_br(irb, parent_scope, node, is_err, err_block, ok_block, is_comptime); | 5199 | ir_build_cond_br(irb, parent_scope, node, is_err, err_block, ok_block, is_comptime); |
| 6165 | | 5200 | |
| 6166 | ir_set_cursor_at_end(irb, err_block); | 5201 | ir_set_cursor_at_end_and_append_block(irb, err_block); |
| 6167 | Scope *err_scope; | 5202 | Scope *err_scope; |
| 6168 | if (var_node) { | 5203 | if (var_node) { |
| 6169 | assert(var_node->type == NodeTypeSymbol); | 5204 | assert(var_node->type == NodeTypeSymbol); |
| ... | @@ -6187,13 +5222,13 @@ static IrInstruction *ir_gen_err_ok_or(IrBuilder *irb, Scope *parent_scope, AstN | ... | @@ -6187,13 +5222,13 @@ static IrInstruction *ir_gen_err_ok_or(IrBuilder *irb, Scope *parent_scope, AstN |
| 6187 | if (!instr_is_unreachable(err_result)) | 5222 | if (!instr_is_unreachable(err_result)) |
| 6188 | ir_mark_gen(ir_build_br(irb, err_scope, node, end_block, is_comptime)); | 5223 | ir_mark_gen(ir_build_br(irb, err_scope, node, end_block, is_comptime)); |
| 6189 | | 5224 | |
| 6190 | ir_set_cursor_at_end(irb, ok_block); | 5225 | ir_set_cursor_at_end_and_append_block(irb, ok_block); |
| 6191 | IrInstruction *unwrapped_ptr = ir_build_unwrap_err_payload(irb, parent_scope, node, err_union_ptr, false); | 5226 | IrInstruction *unwrapped_ptr = ir_build_unwrap_err_payload(irb, parent_scope, node, err_union_ptr, false); |
| 6192 | IrInstruction *unwrapped_payload = ir_build_load_ptr(irb, parent_scope, node, unwrapped_ptr); | 5227 | IrInstruction *unwrapped_payload = ir_build_load_ptr(irb, parent_scope, node, unwrapped_ptr); |
| 6193 | IrBasicBlock *after_ok_block = irb->current_basic_block; | 5228 | IrBasicBlock *after_ok_block = irb->current_basic_block; |
| 6194 | ir_build_br(irb, parent_scope, node, end_block, is_comptime); | 5229 | ir_build_br(irb, parent_scope, node, end_block, is_comptime); |
| 6195 | | 5230 | |
| 6196 | ir_set_cursor_at_end(irb, end_block); | 5231 | ir_set_cursor_at_end_and_append_block(irb, end_block); |
| 6197 | IrInstruction **incoming_values = allocate<IrInstruction *>(2); | 5232 | IrInstruction **incoming_values = allocate<IrInstruction *>(2); |
| 6198 | incoming_values[0] = err_result; | 5233 | incoming_values[0] = err_result; |
| 6199 | incoming_values[1] = unwrapped_payload; | 5234 | incoming_values[1] = unwrapped_payload; |
| ... | @@ -6437,7 +5472,8 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec | ... | @@ -6437,7 +5472,8 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec |
| 6437 | irb->codegen = codegen; | 5472 | irb->codegen = codegen; |
| 6438 | irb->exec = ir_executable; | 5473 | irb->exec = ir_executable; |
| 6439 | | 5474 | |
| 6440 | irb->current_basic_block = ir_build_basic_block(irb, scope, "Entry"); | 5475 | IrBasicBlock *entry_block = ir_create_basic_block(irb, scope, "Entry"); |
| | 5476 | ir_set_cursor_at_end_and_append_block(irb, entry_block); |
| 6441 | // Entry block gets a reference because we enter it to begin. | 5477 | // Entry block gets a reference because we enter it to begin. |
| 6442 | ir_ref_bb(irb->current_basic_block); | 5478 | ir_ref_bb(irb->current_basic_block); |
| 6443 | | 5479 | |
| ... | @@ -7332,6 +6368,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, | ... | @@ -7332,6 +6368,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, |
| 7332 | } | 6368 | } |
| 7333 | } | 6369 | } |
| 7334 | | 6370 | |
| | 6371 | |
| 7335 | // implicit number literal to typed number | 6372 | // implicit number literal to typed number |
| 7336 | // implicit number literal to &const integer | 6373 | // implicit number literal to &const integer |
| 7337 | if (actual_type->id == TypeTableEntryIdNumLitFloat || | 6374 | if (actual_type->id == TypeTableEntryIdNumLitFloat || |
| ... | @@ -7786,32 +6823,14 @@ static IrBasicBlock *ir_get_new_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrInstr | ... | @@ -7786,32 +6823,14 @@ static IrBasicBlock *ir_get_new_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrInstr |
| 7786 | assert(old_bb); | 6823 | assert(old_bb); |
| 7787 | | 6824 | |
| 7788 | if (old_bb->other) { | 6825 | if (old_bb->other) { |
| 7789 | if (ref_old_instruction == nullptr || old_bb->other->ref_instruction != ref_old_instruction) | 6826 | if (ref_old_instruction == nullptr || old_bb->other->ref_instruction != ref_old_instruction) { |
| 7790 | return old_bb->other; | 6827 | return old_bb->other; |
| | 6828 | } |
| 7791 | } | 6829 | } |
| 7792 | | 6830 | |
| 7793 | IrBasicBlock *new_bb = ir_build_bb_from(&ira->new_irb, old_bb); | 6831 | IrBasicBlock *new_bb = ir_build_bb_from(&ira->new_irb, old_bb); |
| 7794 | new_bb->ref_instruction = ref_old_instruction; | 6832 | new_bb->ref_instruction = ref_old_instruction; |
| 7795 | | 6833 | |
| 7796 | // We are about to enqueue old_bb for analysis. Before we do so, look over old_bb's | | |
| 7797 | // instructions and make sure we have enqueued first the blocks which contain | | |
| 7798 | // instructions old_bb depends on. | | |
| 7799 | for (size_t instr_i = 0; instr_i < old_bb->instruction_list.length; instr_i += 1) { | | |
| 7800 | IrInstruction *instruction = old_bb->instruction_list.at(instr_i); | | |
| 7801 | | | |
| 7802 | for (size_t dep_i = 0; ; dep_i += 1) { | | |
| 7803 | IrInstruction *dep_instruction = ir_instruction_get_dep(instruction, dep_i); | | |
| 7804 | if (dep_instruction == nullptr) | | |
| 7805 | break; | | |
| 7806 | if (dep_instruction->other) | | |
| 7807 | continue; | | |
| 7808 | if (dep_instruction->owner_bb == old_bb) | | |
| 7809 | continue; | | |
| 7810 | ir_get_new_bb(ira, dep_instruction->owner_bb, nullptr); | | |
| 7811 | } | | |
| 7812 | } | | |
| 7813 | ira->old_bb_queue.append(old_bb); | | |
| 7814 | | | |
| 7815 | return new_bb; | 6834 | return new_bb; |
| 7816 | } | 6835 | } |
| 7817 | | 6836 | |
| ... | @@ -7819,12 +6838,10 @@ static void ir_start_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrBasicBlock *cons | ... | @@ -7819,12 +6838,10 @@ static void ir_start_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrBasicBlock *cons |
| 7819 | ira->instruction_index = 0; | 6838 | ira->instruction_index = 0; |
| 7820 | ira->old_irb.current_basic_block = old_bb; | 6839 | ira->old_irb.current_basic_block = old_bb; |
| 7821 | ira->const_predecessor_bb = const_predecessor_bb; | 6840 | ira->const_predecessor_bb = const_predecessor_bb; |
| 7822 | | | |
| 7823 | if (!const_predecessor_bb && old_bb->other) | | |
| 7824 | ira->new_irb.exec->basic_block_list.append(old_bb->other); | | |
| 7825 | } | 6841 | } |
| 7826 | | 6842 | |
| 7827 | static void ir_finish_bb(IrAnalyze *ira) { | 6843 | static void ir_finish_bb(IrAnalyze *ira) { |
| | 6844 | ira->new_irb.exec->basic_block_list.append(ira->new_irb.current_basic_block); |
| 7828 | ira->instruction_index += 1; | 6845 | ira->instruction_index += 1; |
| 7829 | while (ira->instruction_index < ira->old_irb.current_basic_block->instruction_list.length) { | 6846 | while (ira->instruction_index < ira->old_irb.current_basic_block->instruction_list.length) { |
| 7830 | IrInstruction *next_instruction = ira->old_irb.current_basic_block->instruction_list.at(ira->instruction_index); | 6847 | IrInstruction *next_instruction = ira->old_irb.current_basic_block->instruction_list.at(ira->instruction_index); |
| ... | @@ -7835,19 +6852,35 @@ static void ir_finish_bb(IrAnalyze *ira) { | ... | @@ -7835,19 +6852,35 @@ static void ir_finish_bb(IrAnalyze *ira) { |
| 7835 | ira->instruction_index += 1; | 6852 | ira->instruction_index += 1; |
| 7836 | } | 6853 | } |
| 7837 | | 6854 | |
| 7838 | ira->block_queue_index += 1; | 6855 | ira->old_bb_index += 1; |
| 7839 | | 6856 | |
| 7840 | if (ira->block_queue_index < ira->old_bb_queue.length) { | 6857 | bool need_repeat = true; |
| 7841 | IrBasicBlock *old_bb = ira->old_bb_queue.at(ira->block_queue_index); | 6858 | for (;;) { |
| 7842 | assert(old_bb->other); | 6859 | while (ira->old_bb_index < ira->old_irb.exec->basic_block_list.length) { |
| 7843 | ira->new_irb.current_basic_block = old_bb->other; | 6860 | IrBasicBlock *old_bb = ira->old_irb.exec->basic_block_list.at(ira->old_bb_index); |
| | 6861 | if (old_bb->other == nullptr) { |
| | 6862 | ira->old_bb_index += 1; |
| | 6863 | continue; |
| | 6864 | } |
| | 6865 | if (old_bb->other->instruction_list.length != 0) { |
| | 6866 | ira->old_bb_index += 1; |
| | 6867 | continue; |
| | 6868 | } |
| | 6869 | ira->new_irb.current_basic_block = old_bb->other; |
| 7844 | | 6870 | |
| 7845 | ir_start_bb(ira, old_bb, nullptr); | 6871 | ir_start_bb(ira, old_bb, nullptr); |
| | 6872 | return; |
| | 6873 | } |
| | 6874 | if (!need_repeat) |
| | 6875 | return; |
| | 6876 | need_repeat = false; |
| | 6877 | ira->old_bb_index = 0; |
| | 6878 | continue; |
| 7846 | } | 6879 | } |
| 7847 | } | 6880 | } |
| 7848 | | 6881 | |
| 7849 | static TypeTableEntry *ir_unreach_error(IrAnalyze *ira) { | 6882 | static TypeTableEntry *ir_unreach_error(IrAnalyze *ira) { |
| 7850 | ira->block_queue_index = SIZE_MAX; | 6883 | ira->old_bb_index = SIZE_MAX; |
| 7851 | ira->new_irb.exec->invalid = true; | 6884 | ira->new_irb.exec->invalid = true; |
| 7852 | return ira->codegen->builtin_types.entry_unreachable; | 6885 | return ira->codegen->builtin_types.entry_unreachable; |
| 7853 | } | 6886 | } |
| ... | @@ -10639,6 +9672,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod | ... | @@ -10639,6 +9672,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod |
| 10639 | static VariableTableEntry *get_fn_var_by_index(FnTableEntry *fn_entry, size_t index) { | 9672 | static VariableTableEntry *get_fn_var_by_index(FnTableEntry *fn_entry, size_t index) { |
| 10640 | size_t next_var_i = 0; | 9673 | size_t next_var_i = 0; |
| 10641 | FnGenParamInfo *gen_param_info = fn_entry->type_entry->data.fn.gen_param_info; | 9674 | FnGenParamInfo *gen_param_info = fn_entry->type_entry->data.fn.gen_param_info; |
| | 9675 | assert(gen_param_info != nullptr); |
| 10642 | for (size_t param_i = 0; param_i < index; param_i += 1) { | 9676 | for (size_t param_i = 0; param_i < index; param_i += 1) { |
| 10643 | FnGenParamInfo *info = &gen_param_info[param_i]; | 9677 | FnGenParamInfo *info = &gen_param_info[param_i]; |
| 10644 | if (info->gen_index == SIZE_MAX) | 9678 | if (info->gen_index == SIZE_MAX) |
| ... | @@ -11442,7 +10476,7 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP | ... | @@ -11442,7 +10476,7 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP |
| 11442 | IrInstruction *old_value = phi_instruction->incoming_values[i]; | 10476 | IrInstruction *old_value = phi_instruction->incoming_values[i]; |
| 11443 | assert(old_value); | 10477 | assert(old_value); |
| 11444 | IrInstruction *new_value = old_value->other; | 10478 | IrInstruction *new_value = old_value->other; |
| 11445 | if (!new_value || new_value->value.type->id == TypeTableEntryIdUnreachable) | 10479 | if (!new_value || new_value->value.type->id == TypeTableEntryIdUnreachable || predecessor->other == nullptr) |
| 11446 | continue; | 10480 | continue; |
| 11447 | | 10481 | |
| 11448 | if (type_is_invalid(new_value->value.type)) | 10482 | if (type_is_invalid(new_value->value.type)) |
| ... | @@ -16312,11 +15346,11 @@ TypeTableEntry *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutabl | ... | @@ -16312,11 +15346,11 @@ TypeTableEntry *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutabl |
| 16312 | IrBasicBlock *new_entry_bb = ir_get_new_bb(ira, old_entry_bb, nullptr); | 15346 | IrBasicBlock *new_entry_bb = ir_get_new_bb(ira, old_entry_bb, nullptr); |
| 16313 | ir_ref_bb(new_entry_bb); | 15347 | ir_ref_bb(new_entry_bb); |
| 16314 | ira->new_irb.current_basic_block = new_entry_bb; | 15348 | ira->new_irb.current_basic_block = new_entry_bb; |
| 16315 | ira->block_queue_index = 0; | 15349 | ira->old_bb_index = 0; |
| 16316 | | 15350 | |
| 16317 | ir_start_bb(ira, old_entry_bb, nullptr); | 15351 | ir_start_bb(ira, old_entry_bb, nullptr); |
| 16318 | | 15352 | |
| 16319 | while (ira->block_queue_index < ira->old_bb_queue.length) { | 15353 | while (ira->old_bb_index < ira->old_irb.exec->basic_block_list.length) { |
| 16320 | IrInstruction *old_instruction = ira->old_irb.current_basic_block->instruction_list.at(ira->instruction_index); | 15354 | IrInstruction *old_instruction = ira->old_irb.current_basic_block->instruction_list.at(ira->instruction_index); |
| 16321 | | 15355 | |
| 16322 | if (old_instruction->ref_count == 0 && !ir_has_side_effects(old_instruction)) { | 15356 | if (old_instruction->ref_count == 0 && !ir_has_side_effects(old_instruction)) { |
| ... | @@ -16326,7 +15360,7 @@ TypeTableEntry *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutabl | ... | @@ -16326,7 +15360,7 @@ TypeTableEntry *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutabl |
| 16326 | | 15360 | |
| 16327 | TypeTableEntry *return_type = ir_analyze_instruction(ira, old_instruction); | 15361 | TypeTableEntry *return_type = ir_analyze_instruction(ira, old_instruction); |
| 16328 | if (type_is_invalid(return_type) && ir_should_inline(new_exec, old_instruction->scope)) { | 15362 | if (type_is_invalid(return_type) && ir_should_inline(new_exec, old_instruction->scope)) { |
| 16329 | break; | 15363 | return ira->codegen->builtin_types.entry_invalid; |
| 16330 | } | 15364 | } |
| 16331 | | 15365 | |
| 16332 | // unreachable instructions do their own control flow. | 15366 | // unreachable instructions do their own control flow. |