zig

fork of https://codeberg.org/ziglang/zig
Log | Tree | Refs | README | LICENSE

blob fa7ff97d (43523B) - Raw


      1 /*
      2  * Copyright (c) 2016 Andrew Kelley
      3  *
      4  * This file is part of zig, which is MIT licensed.
      5  * See http://opensource.org/licenses/MIT
      6  */
      7 
      8 #include "analyze.hpp"
      9 #include "ir.hpp"
     10 #include "ir_print.hpp"
     11 
     12 struct IrPrint {
     13     FILE *f;
     14     int indent;
     15     int indent_size;
     16 };
     17 
     18 static void ir_print_other_instruction(IrPrint *irp, IrInstruction *instruction);
     19 
     20 static void ir_print_indent(IrPrint *irp) {
     21     for (int i = 0; i < irp->indent; i += 1) {
     22         fprintf(irp->f, " ");
     23     }
     24 }
     25 
     26 static void ir_print_prefix(IrPrint *irp, IrInstruction *instruction) {
     27     ir_print_indent(irp);
     28     const char *type_name = instruction->value.type ? buf_ptr(&instruction->value.type->name) : "(unknown)";
     29     const char *ref_count = ir_has_side_effects(instruction) ?
     30         "-" : buf_ptr(buf_sprintf("%zu", instruction->ref_count));
     31     fprintf(irp->f, "#%-3zu| %-12s| %-2s| ", instruction->debug_id, type_name, ref_count);
     32 }
     33 
     34 static void ir_print_const_value(IrPrint *irp, ConstExprValue *const_val) {
     35     Buf buf = BUF_INIT;
     36     buf_resize(&buf, 0);
     37     render_const_value(&buf, const_val);
     38     fprintf(irp->f, "%s", buf_ptr(&buf));
     39 }
     40 
     41 static void ir_print_var_instruction(IrPrint *irp, IrInstruction *instruction) {
     42     fprintf(irp->f, "#%zu", instruction->debug_id);
     43 }
     44 
     45 static void ir_print_other_instruction(IrPrint *irp, IrInstruction *instruction) {
     46     if (instruction->value.special != ConstValSpecialRuntime) {
     47         ir_print_const_value(irp, &instruction->value);
     48     } else {
     49         ir_print_var_instruction(irp, instruction);
     50     }
     51 }
     52 
     53 static void ir_print_other_block(IrPrint *irp, IrBasicBlock *bb) {
     54     fprintf(irp->f, "$%s_%zu", bb->name_hint, bb->debug_id);
     55 }
     56 
     57 static void ir_print_return(IrPrint *irp, IrInstructionReturn *return_instruction) {
     58     assert(return_instruction->value);
     59     fprintf(irp->f, "return ");
     60     ir_print_other_instruction(irp, return_instruction->value);
     61 }
     62 
     63 static void ir_print_const(IrPrint *irp, IrInstructionConst *const_instruction) {
     64     ir_print_const_value(irp, &const_instruction->base.value);
     65 }
     66 
     67 static const char *ir_bin_op_id_str(IrBinOp op_id) {
     68     switch (op_id) {
     69         case IrBinOpInvalid:
     70             zig_unreachable();
     71         case IrBinOpBoolOr:
     72             return "BoolOr";
     73         case IrBinOpBoolAnd:
     74             return "BoolAnd";
     75         case IrBinOpCmpEq:
     76             return "==";
     77         case IrBinOpCmpNotEq:
     78             return "!=";
     79         case IrBinOpCmpLessThan:
     80             return "<";
     81         case IrBinOpCmpGreaterThan:
     82             return ">";
     83         case IrBinOpCmpLessOrEq:
     84             return "<=";
     85         case IrBinOpCmpGreaterOrEq:
     86             return ">=";
     87         case IrBinOpBinOr:
     88             return "|";
     89         case IrBinOpBinXor:
     90             return "^";
     91         case IrBinOpBinAnd:
     92             return "&";
     93         case IrBinOpBitShiftLeft:
     94             return "<<";
     95         case IrBinOpBitShiftLeftWrap:
     96             return "<<%";
     97         case IrBinOpBitShiftRight:
     98             return ">>";
     99         case IrBinOpAdd:
    100             return "+";
    101         case IrBinOpAddWrap:
    102             return "+%";
    103         case IrBinOpSub:
    104             return "-";
    105         case IrBinOpSubWrap:
    106             return "-%";
    107         case IrBinOpMult:
    108             return "*";
    109         case IrBinOpMultWrap:
    110             return "*%";
    111         case IrBinOpDiv:
    112             return "/";
    113         case IrBinOpMod:
    114             return "%";
    115         case IrBinOpArrayCat:
    116             return "++";
    117         case IrBinOpArrayMult:
    118             return "**";
    119     }
    120     zig_unreachable();
    121 }
    122 
    123 static const char *ir_un_op_id_str(IrUnOp op_id) {
    124     switch (op_id) {
    125         case IrUnOpInvalid:
    126             zig_unreachable();
    127         case IrUnOpBinNot:
    128             return "~";
    129         case IrUnOpNegation:
    130             return "-";
    131         case IrUnOpNegationWrap:
    132             return "-%";
    133         case IrUnOpDereference:
    134             return "*";
    135         case IrUnOpMaybe:
    136             return "?";
    137         case IrUnOpError:
    138             return "%";
    139     }
    140     zig_unreachable();
    141 }
    142 
    143 static void ir_print_un_op(IrPrint *irp, IrInstructionUnOp *un_op_instruction) {
    144     fprintf(irp->f, "%s ", ir_un_op_id_str(un_op_instruction->op_id));
    145     ir_print_other_instruction(irp, un_op_instruction->value);
    146 }
    147 
    148 static void ir_print_bin_op(IrPrint *irp, IrInstructionBinOp *bin_op_instruction) {
    149     ir_print_other_instruction(irp, bin_op_instruction->op1);
    150     fprintf(irp->f, " %s ", ir_bin_op_id_str(bin_op_instruction->op_id));
    151     ir_print_other_instruction(irp, bin_op_instruction->op2);
    152     if (!bin_op_instruction->safety_check_on) {
    153         fprintf(irp->f, " // no safety");
    154     }
    155 }
    156 
    157 static void ir_print_decl_var(IrPrint *irp, IrInstructionDeclVar *decl_var_instruction) {
    158     const char *var_or_const = decl_var_instruction->var->gen_is_const ? "const" : "var";
    159     const char *name = buf_ptr(&decl_var_instruction->var->name);
    160     if (decl_var_instruction->var_type) {
    161         fprintf(irp->f, "%s %s: ", var_or_const, name);
    162         ir_print_other_instruction(irp, decl_var_instruction->var_type);
    163         fprintf(irp->f, " = ");
    164     } else {
    165         fprintf(irp->f, "%s %s = ", var_or_const, name);
    166     }
    167     ir_print_other_instruction(irp, decl_var_instruction->init_value);
    168     if (decl_var_instruction->var->is_comptime != nullptr) {
    169         fprintf(irp->f, " // comptime = ");
    170         ir_print_other_instruction(irp, decl_var_instruction->var->is_comptime);
    171     }
    172 }
    173 
    174 static void ir_print_cast(IrPrint *irp, IrInstructionCast *cast_instruction) {
    175     fprintf(irp->f, "cast ");
    176     ir_print_other_instruction(irp, cast_instruction->value);
    177     fprintf(irp->f, " to %s", buf_ptr(&cast_instruction->dest_type->name));
    178 }
    179 
    180 static void ir_print_call(IrPrint *irp, IrInstructionCall *call_instruction) {
    181     if (call_instruction->fn_entry) {
    182         fprintf(irp->f, "%s", buf_ptr(&call_instruction->fn_entry->symbol_name));
    183     } else {
    184         assert(call_instruction->fn_ref);
    185         ir_print_other_instruction(irp, call_instruction->fn_ref);
    186     }
    187     fprintf(irp->f, "(");
    188     for (size_t i = 0; i < call_instruction->arg_count; i += 1) {
    189         IrInstruction *arg = call_instruction->args[i];
    190         if (i != 0)
    191             fprintf(irp->f, ", ");
    192         ir_print_other_instruction(irp, arg);
    193     }
    194     fprintf(irp->f, ")");
    195 }
    196 
    197 static void ir_print_cond_br(IrPrint *irp, IrInstructionCondBr *cond_br_instruction) {
    198     fprintf(irp->f, "if (");
    199     ir_print_other_instruction(irp, cond_br_instruction->condition);
    200     fprintf(irp->f, ") ");
    201     ir_print_other_block(irp, cond_br_instruction->then_block);
    202     fprintf(irp->f, " else ");
    203     ir_print_other_block(irp, cond_br_instruction->else_block);
    204     if (cond_br_instruction->is_comptime != nullptr) {
    205         fprintf(irp->f, " // comptime = ");
    206         ir_print_other_instruction(irp, cond_br_instruction->is_comptime);
    207     }
    208 }
    209 
    210 static void ir_print_br(IrPrint *irp, IrInstructionBr *br_instruction) {
    211     fprintf(irp->f, "goto ");
    212     ir_print_other_block(irp, br_instruction->dest_block);
    213     if (br_instruction->is_comptime != nullptr) {
    214         fprintf(irp->f, " // comptime = ");
    215         ir_print_other_instruction(irp, br_instruction->is_comptime);
    216     }
    217 }
    218 
    219 static void ir_print_phi(IrPrint *irp, IrInstructionPhi *phi_instruction) {
    220     assert(phi_instruction->incoming_count != 0);
    221     assert(phi_instruction->incoming_count != SIZE_MAX);
    222     for (size_t i = 0; i < phi_instruction->incoming_count; i += 1) {
    223         IrBasicBlock *incoming_block = phi_instruction->incoming_blocks[i];
    224         IrInstruction *incoming_value = phi_instruction->incoming_values[i];
    225         if (i != 0)
    226             fprintf(irp->f, " ");
    227         ir_print_other_block(irp, incoming_block);
    228         fprintf(irp->f, ":");
    229         ir_print_other_instruction(irp, incoming_value);
    230     }
    231 }
    232 
    233 static void ir_print_container_init_list(IrPrint *irp, IrInstructionContainerInitList *instruction) {
    234     ir_print_other_instruction(irp, instruction->container_type);
    235     fprintf(irp->f, "{");
    236     if (instruction->item_count > 50) {
    237         fprintf(irp->f, "...(%zu items)...", instruction->item_count);
    238     } else {
    239         for (size_t i = 0; i < instruction->item_count; i += 1) {
    240             IrInstruction *item = instruction->items[i];
    241             if (i != 0)
    242                 fprintf(irp->f, ", ");
    243             ir_print_other_instruction(irp, item);
    244         }
    245     }
    246     fprintf(irp->f, "}");
    247 }
    248 
    249 static void ir_print_container_init_fields(IrPrint *irp, IrInstructionContainerInitFields *instruction) {
    250     ir_print_other_instruction(irp, instruction->container_type);
    251     fprintf(irp->f, "{");
    252     for (size_t i = 0; i < instruction->field_count; i += 1) {
    253         IrInstructionContainerInitFieldsField *field = &instruction->fields[i];
    254         const char *comma = (i == 0) ? "" : ", ";
    255         fprintf(irp->f, "%s.%s = ", comma, buf_ptr(field->name));
    256         ir_print_other_instruction(irp, field->value);
    257     }
    258     fprintf(irp->f, "} // container init");
    259 }
    260 
    261 static void ir_print_struct_init(IrPrint *irp, IrInstructionStructInit *instruction) {
    262     fprintf(irp->f, "%s {", buf_ptr(&instruction->struct_type->name));
    263     for (size_t i = 0; i < instruction->field_count; i += 1) {
    264         IrInstructionStructInitField *field = &instruction->fields[i];
    265         Buf *field_name = field->type_struct_field->name;
    266         const char *comma = (i == 0) ? "" : ", ";
    267         fprintf(irp->f, "%s.%s = ", comma, buf_ptr(field_name));
    268         ir_print_other_instruction(irp, field->value);
    269     }
    270     fprintf(irp->f, "} // struct init");
    271 }
    272 
    273 static void ir_print_unreachable(IrPrint *irp, IrInstructionUnreachable *instruction) {
    274     fprintf(irp->f, "unreachable");
    275 }
    276 
    277 static void ir_print_elem_ptr(IrPrint *irp, IrInstructionElemPtr *instruction) {
    278     fprintf(irp->f, "&");
    279     ir_print_other_instruction(irp, instruction->array_ptr);
    280     fprintf(irp->f, "[");
    281     ir_print_other_instruction(irp, instruction->elem_index);
    282     fprintf(irp->f, "]");
    283     if (!instruction->safety_check_on) {
    284         fprintf(irp->f, " // no safety");
    285     }
    286 }
    287 
    288 static void ir_print_var_ptr(IrPrint *irp, IrInstructionVarPtr *instruction) {
    289     fprintf(irp->f, "&%s", buf_ptr(&instruction->var->name));
    290 }
    291 
    292 static void ir_print_load_ptr(IrPrint *irp, IrInstructionLoadPtr *instruction) {
    293     fprintf(irp->f, "*");
    294     ir_print_other_instruction(irp, instruction->ptr);
    295 }
    296 
    297 static void ir_print_store_ptr(IrPrint *irp, IrInstructionStorePtr *instruction) {
    298     fprintf(irp->f, "*");
    299     ir_print_var_instruction(irp, instruction->ptr);
    300     fprintf(irp->f, " = ");
    301     ir_print_other_instruction(irp, instruction->value);
    302 }
    303 
    304 static void ir_print_typeof(IrPrint *irp, IrInstructionTypeOf *instruction) {
    305     fprintf(irp->f, "@typeOf(");
    306     ir_print_other_instruction(irp, instruction->value);
    307     fprintf(irp->f, ")");
    308 }
    309 
    310 static void ir_print_to_ptr_type(IrPrint *irp, IrInstructionToPtrType *instruction) {
    311     fprintf(irp->f, "@toPtrType(");
    312     ir_print_other_instruction(irp, instruction->value);
    313     fprintf(irp->f, ")");
    314 }
    315 
    316 static void ir_print_ptr_type_child(IrPrint *irp, IrInstructionPtrTypeChild *instruction) {
    317     fprintf(irp->f, "@ptrTypeChild(");
    318     ir_print_other_instruction(irp, instruction->value);
    319     fprintf(irp->f, ")");
    320 }
    321 
    322 static void ir_print_field_ptr(IrPrint *irp, IrInstructionFieldPtr *instruction) {
    323     fprintf(irp->f, "fieldptr ");
    324     ir_print_other_instruction(irp, instruction->container_ptr);
    325     fprintf(irp->f, ".%s", buf_ptr(instruction->field_name));
    326 }
    327 
    328 static void ir_print_struct_field_ptr(IrPrint *irp, IrInstructionStructFieldPtr *instruction) {
    329     fprintf(irp->f, "@StructFieldPtr(&");
    330     ir_print_other_instruction(irp, instruction->struct_ptr);
    331     fprintf(irp->f, ".%s", buf_ptr(instruction->field->name));
    332     fprintf(irp->f, ")");
    333 }
    334 
    335 static void ir_print_enum_field_ptr(IrPrint *irp, IrInstructionEnumFieldPtr *instruction) {
    336     fprintf(irp->f, "@EnumFieldPtr(&");
    337     ir_print_other_instruction(irp, instruction->enum_ptr);
    338     fprintf(irp->f, ".%s", buf_ptr(instruction->field->name));
    339     fprintf(irp->f, ")");
    340 }
    341 
    342 static void ir_print_set_fn_test(IrPrint *irp, IrInstructionSetFnTest *instruction) {
    343     fprintf(irp->f, "@setFnTest(");
    344     ir_print_other_instruction(irp, instruction->fn_value);
    345     fprintf(irp->f, ")");
    346 }
    347 
    348 static void ir_print_set_fn_visible(IrPrint *irp, IrInstructionSetFnVisible *instruction) {
    349     fprintf(irp->f, "@setFnVisible(");
    350     ir_print_other_instruction(irp, instruction->fn_value);
    351     fprintf(irp->f, ", ");
    352     ir_print_other_instruction(irp, instruction->is_visible);
    353     fprintf(irp->f, ")");
    354 }
    355 
    356 static void ir_print_set_debug_safety(IrPrint *irp, IrInstructionSetDebugSafety *instruction) {
    357     fprintf(irp->f, "@setDebugSafety(");
    358     ir_print_other_instruction(irp, instruction->scope_value);
    359     fprintf(irp->f, ", ");
    360     ir_print_other_instruction(irp, instruction->debug_safety_on);
    361     fprintf(irp->f, ")");
    362 }
    363 
    364 static void ir_print_array_type(IrPrint *irp, IrInstructionArrayType *instruction) {
    365     fprintf(irp->f, "[");
    366     ir_print_other_instruction(irp, instruction->size);
    367     fprintf(irp->f, "]");
    368     ir_print_other_instruction(irp, instruction->child_type);
    369 }
    370 
    371 static void ir_print_slice_type(IrPrint *irp, IrInstructionSliceType *instruction) {
    372     const char *const_kw = instruction->is_const ? "const " : "";
    373     fprintf(irp->f, "[]%s", const_kw);
    374     ir_print_other_instruction(irp, instruction->child_type);
    375 }
    376 
    377 static void ir_print_asm(IrPrint *irp, IrInstructionAsm *instruction) {
    378     assert(instruction->base.source_node->type == NodeTypeAsmExpr);
    379     AstNodeAsmExpr *asm_expr = &instruction->base.source_node->data.asm_expr;
    380     const char *volatile_kw = instruction->has_side_effects ? " volatile" : "";
    381     fprintf(irp->f, "asm%s (\"%s\") : ", volatile_kw, buf_ptr(asm_expr->asm_template));
    382 
    383     for (size_t i = 0; i < asm_expr->output_list.length; i += 1) {
    384         AsmOutput *asm_output = asm_expr->output_list.at(i);
    385         if (i != 0) fprintf(irp->f, ", ");
    386 
    387         fprintf(irp->f, "[%s] \"%s\" (",
    388                 buf_ptr(asm_output->asm_symbolic_name),
    389                 buf_ptr(asm_output->constraint));
    390         if (asm_output->return_type) {
    391             fprintf(irp->f, "-> ");
    392             ir_print_other_instruction(irp, instruction->output_types[i]);
    393         } else {
    394             fprintf(irp->f, "%s", buf_ptr(asm_output->variable_name));
    395         }
    396         fprintf(irp->f, ")");
    397     }
    398 
    399     fprintf(irp->f, " : ");
    400     for (size_t i = 0; i < asm_expr->input_list.length; i += 1) {
    401         AsmInput *asm_input = asm_expr->input_list.at(i);
    402 
    403         if (i != 0) fprintf(irp->f, ", ");
    404         fprintf(irp->f, "[%s] \"%s\" (",
    405                 buf_ptr(asm_input->asm_symbolic_name),
    406                 buf_ptr(asm_input->constraint));
    407         ir_print_other_instruction(irp, instruction->input_list[i]);
    408         fprintf(irp->f, ")");
    409     }
    410     fprintf(irp->f, " : ");
    411     for (size_t i = 0; i < asm_expr->clobber_list.length; i += 1) {
    412         Buf *reg_name = asm_expr->clobber_list.at(i);
    413         if (i != 0) fprintf(irp->f, ", ");
    414         fprintf(irp->f, "\"%s\"", buf_ptr(reg_name));
    415     }
    416     fprintf(irp->f, ")");
    417 }
    418 
    419 static void ir_print_compile_var(IrPrint *irp, IrInstructionCompileVar *instruction) {
    420     fprintf(irp->f, "@compileVar(");
    421     ir_print_other_instruction(irp, instruction->name);
    422     fprintf(irp->f, ")");
    423 }
    424 
    425 static void ir_print_size_of(IrPrint *irp, IrInstructionSizeOf *instruction) {
    426     fprintf(irp->f, "@sizeOf(");
    427     ir_print_other_instruction(irp, instruction->type_value);
    428     fprintf(irp->f, ")");
    429 }
    430 
    431 static void ir_print_test_null(IrPrint *irp, IrInstructionTestNonNull *instruction) {
    432     fprintf(irp->f, "*");
    433     ir_print_other_instruction(irp, instruction->value);
    434     fprintf(irp->f, " != null");
    435 }
    436 
    437 static void ir_print_unwrap_maybe(IrPrint *irp, IrInstructionUnwrapMaybe *instruction) {
    438     fprintf(irp->f, "&??*");
    439     ir_print_other_instruction(irp, instruction->value);
    440     if (!instruction->safety_check_on) {
    441         fprintf(irp->f, " // no safety");
    442     }
    443 }
    444 
    445 static void ir_print_clz(IrPrint *irp, IrInstructionClz *instruction) {
    446     fprintf(irp->f, "@clz(");
    447     ir_print_other_instruction(irp, instruction->value);
    448     fprintf(irp->f, ")");
    449 }
    450 
    451 static void ir_print_ctz(IrPrint *irp, IrInstructionCtz *instruction) {
    452     fprintf(irp->f, "@ctz(");
    453     ir_print_other_instruction(irp, instruction->value);
    454     fprintf(irp->f, ")");
    455 }
    456 
    457 static void ir_print_switch_br(IrPrint *irp, IrInstructionSwitchBr *instruction) {
    458     fprintf(irp->f, "switch (");
    459     ir_print_other_instruction(irp, instruction->target_value);
    460     fprintf(irp->f, ") ");
    461     for (size_t i = 0; i < instruction->case_count; i += 1) {
    462         IrInstructionSwitchBrCase *this_case = &instruction->cases[i];
    463         ir_print_other_instruction(irp, this_case->value);
    464         fprintf(irp->f, " => ");
    465         ir_print_other_block(irp, this_case->block);
    466         fprintf(irp->f, ", ");
    467     }
    468     fprintf(irp->f, "else => ");
    469     ir_print_other_block(irp, instruction->else_block);
    470     if (instruction->is_comptime != nullptr) {
    471         fprintf(irp->f, " // comptime = ");
    472         ir_print_other_instruction(irp, instruction->is_comptime);
    473     }
    474 }
    475 
    476 static void ir_print_switch_var(IrPrint *irp, IrInstructionSwitchVar *instruction) {
    477     fprintf(irp->f, "switchvar ");
    478     ir_print_other_instruction(irp, instruction->target_value_ptr);
    479     fprintf(irp->f, ", ");
    480     ir_print_other_instruction(irp, instruction->prong_value);
    481 }
    482 
    483 static void ir_print_switch_target(IrPrint *irp, IrInstructionSwitchTarget *instruction) {
    484     fprintf(irp->f, "switchtarget ");
    485     ir_print_other_instruction(irp, instruction->target_value_ptr);
    486 }
    487 
    488 static void ir_print_enum_tag(IrPrint *irp, IrInstructionEnumTag *instruction) {
    489     fprintf(irp->f, "enumtag ");
    490     ir_print_other_instruction(irp, instruction->value);
    491 }
    492 
    493 static void ir_print_generated_code(IrPrint *irp, IrInstructionGeneratedCode *instruction) {
    494     fprintf(irp->f, "@generatedCode(");
    495     ir_print_other_instruction(irp, instruction->value);
    496     fprintf(irp->f, ")");
    497 }
    498 
    499 static void ir_print_import(IrPrint *irp, IrInstructionImport *instruction) {
    500     fprintf(irp->f, "@import(");
    501     ir_print_other_instruction(irp, instruction->name);
    502     fprintf(irp->f, ")");
    503 }
    504 
    505 static void ir_print_array_len(IrPrint *irp, IrInstructionArrayLen *instruction) {
    506     ir_print_other_instruction(irp, instruction->array_value);
    507     fprintf(irp->f, ".len");
    508 }
    509 
    510 static void ir_print_ref(IrPrint *irp, IrInstructionRef *instruction) {
    511     const char *const_str = instruction->is_const ? "const " : "";
    512     fprintf(irp->f, "%sref ", const_str);
    513     ir_print_other_instruction(irp, instruction->value);
    514 }
    515 
    516 static void ir_print_min_value(IrPrint *irp, IrInstructionMinValue *instruction) {
    517     fprintf(irp->f, "@minValue(");
    518     ir_print_other_instruction(irp, instruction->value);
    519     fprintf(irp->f, ")");
    520 }
    521 
    522 static void ir_print_max_value(IrPrint *irp, IrInstructionMaxValue *instruction) {
    523     fprintf(irp->f, "@maxValue(");
    524     ir_print_other_instruction(irp, instruction->value);
    525     fprintf(irp->f, ")");
    526 }
    527 
    528 static void ir_print_compile_err(IrPrint *irp, IrInstructionCompileErr *instruction) {
    529     fprintf(irp->f, "@compileError(");
    530     ir_print_other_instruction(irp, instruction->msg);
    531     fprintf(irp->f, ")");
    532 }
    533 
    534 static void ir_print_err_name(IrPrint *irp, IrInstructionErrName *instruction) {
    535     fprintf(irp->f, "@errorName(");
    536     ir_print_other_instruction(irp, instruction->value);
    537     fprintf(irp->f, ")");
    538 }
    539 
    540 static void ir_print_c_import(IrPrint *irp, IrInstructionCImport *instruction) {
    541     fprintf(irp->f, "@cImport(...)");
    542 }
    543 
    544 static void ir_print_c_include(IrPrint *irp, IrInstructionCInclude *instruction) {
    545     fprintf(irp->f, "@cInclude(");
    546     ir_print_other_instruction(irp, instruction->name);
    547     fprintf(irp->f, ")");
    548 }
    549 
    550 static void ir_print_c_define(IrPrint *irp, IrInstructionCDefine *instruction) {
    551     fprintf(irp->f, "@cDefine(");
    552     ir_print_other_instruction(irp, instruction->name);
    553     fprintf(irp->f, ", ");
    554     ir_print_other_instruction(irp, instruction->value);
    555     fprintf(irp->f, ")");
    556 }
    557 
    558 static void ir_print_c_undef(IrPrint *irp, IrInstructionCUndef *instruction) {
    559     fprintf(irp->f, "@cUndef(");
    560     ir_print_other_instruction(irp, instruction->name);
    561     fprintf(irp->f, ")");
    562 }
    563 
    564 static void ir_print_embed_file(IrPrint *irp, IrInstructionEmbedFile *instruction) {
    565     fprintf(irp->f, "@embedFile(");
    566     ir_print_other_instruction(irp, instruction->name);
    567     fprintf(irp->f, ")");
    568 }
    569 
    570 static void ir_print_cmpxchg(IrPrint *irp, IrInstructionCmpxchg *instruction) {
    571     fprintf(irp->f, "@cmpxchg(");
    572     ir_print_other_instruction(irp, instruction->ptr);
    573     fprintf(irp->f, ", ");
    574     ir_print_other_instruction(irp, instruction->cmp_value);
    575     fprintf(irp->f, ", ");
    576     ir_print_other_instruction(irp, instruction->new_value);
    577     fprintf(irp->f, ", ");
    578     ir_print_other_instruction(irp, instruction->success_order_value);
    579     fprintf(irp->f, ", ");
    580     ir_print_other_instruction(irp, instruction->failure_order_value);
    581     fprintf(irp->f, ")");
    582 }
    583 
    584 static void ir_print_fence(IrPrint *irp, IrInstructionFence *instruction) {
    585     fprintf(irp->f, "@fence(");
    586     ir_print_other_instruction(irp, instruction->order_value);
    587     fprintf(irp->f, ")");
    588 }
    589 
    590 static void ir_print_div_exact(IrPrint *irp, IrInstructionDivExact *instruction) {
    591     fprintf(irp->f, "@divExact(");
    592     ir_print_other_instruction(irp, instruction->op1);
    593     fprintf(irp->f, ", ");
    594     ir_print_other_instruction(irp, instruction->op2);
    595     fprintf(irp->f, ")");
    596 }
    597 
    598 static void ir_print_truncate(IrPrint *irp, IrInstructionTruncate *instruction) {
    599     fprintf(irp->f, "@truncate(");
    600     ir_print_other_instruction(irp, instruction->dest_type);
    601     fprintf(irp->f, ", ");
    602     ir_print_other_instruction(irp, instruction->target);
    603     fprintf(irp->f, ")");
    604 }
    605 
    606 static void ir_print_alloca(IrPrint *irp, IrInstructionAlloca *instruction) {
    607     fprintf(irp->f, "@alloca(");
    608     ir_print_other_instruction(irp, instruction->type_value);
    609     fprintf(irp->f, ", ");
    610     ir_print_other_instruction(irp, instruction->count);
    611     fprintf(irp->f, ")");
    612 }
    613 
    614 static void ir_print_int_type(IrPrint *irp, IrInstructionIntType *instruction) {
    615     fprintf(irp->f, "@intType(");
    616     ir_print_other_instruction(irp, instruction->is_signed);
    617     fprintf(irp->f, ", ");
    618     ir_print_other_instruction(irp, instruction->bit_count);
    619     fprintf(irp->f, ")");
    620 }
    621 
    622 static void ir_print_bool_not(IrPrint *irp, IrInstructionBoolNot *instruction) {
    623     fprintf(irp->f, "! ");
    624     ir_print_other_instruction(irp, instruction->value);
    625 }
    626 
    627 static void ir_print_memset(IrPrint *irp, IrInstructionMemset *instruction) {
    628     fprintf(irp->f, "@memset(");
    629     ir_print_other_instruction(irp, instruction->dest_ptr);
    630     fprintf(irp->f, ", ");
    631     ir_print_other_instruction(irp, instruction->byte);
    632     fprintf(irp->f, ", ");
    633     ir_print_other_instruction(irp, instruction->count);
    634     fprintf(irp->f, ")");
    635 }
    636 
    637 static void ir_print_memcpy(IrPrint *irp, IrInstructionMemcpy *instruction) {
    638     fprintf(irp->f, "@memcpy(");
    639     ir_print_other_instruction(irp, instruction->dest_ptr);
    640     fprintf(irp->f, ", ");
    641     ir_print_other_instruction(irp, instruction->src_ptr);
    642     fprintf(irp->f, ", ");
    643     ir_print_other_instruction(irp, instruction->count);
    644     fprintf(irp->f, ")");
    645 }
    646 
    647 static void ir_print_slice(IrPrint *irp, IrInstructionSlice *instruction) {
    648     ir_print_other_instruction(irp, instruction->ptr);
    649     fprintf(irp->f, "[");
    650     ir_print_other_instruction(irp, instruction->start);
    651     fprintf(irp->f, "...");
    652     if (instruction->end)
    653         ir_print_other_instruction(irp, instruction->end);
    654     fprintf(irp->f, "]");
    655     if (instruction->is_const)
    656         fprintf(irp->f, "const");
    657 }
    658 
    659 static void ir_print_member_count(IrPrint *irp, IrInstructionMemberCount *instruction) {
    660     fprintf(irp->f, "@memberCount(");
    661     ir_print_other_instruction(irp, instruction->container);
    662     fprintf(irp->f, ")");
    663 }
    664 
    665 static void ir_print_breakpoint(IrPrint *irp, IrInstructionBreakpoint *instruction) {
    666     fprintf(irp->f, "@breakpoint()");
    667 }
    668 
    669 static void ir_print_frame_address(IrPrint *irp, IrInstructionFrameAddress *instruction) {
    670     fprintf(irp->f, "@frameAddress()");
    671 }
    672 
    673 static void ir_print_return_address(IrPrint *irp, IrInstructionReturnAddress *instruction) {
    674     fprintf(irp->f, "@returnAddress()");
    675 }
    676 
    677 static void ir_print_alignof(IrPrint *irp, IrInstructionAlignOf *instruction) {
    678     fprintf(irp->f, "@alignOf(");
    679     ir_print_other_instruction(irp, instruction->type_value);
    680     fprintf(irp->f, ")");
    681 }
    682 
    683 static void ir_print_overflow_op(IrPrint *irp, IrInstructionOverflowOp *instruction) {
    684     switch (instruction->op) {
    685         case IrOverflowOpAdd:
    686             fprintf(irp->f, "@addWithOverflow(");
    687             break;
    688         case IrOverflowOpSub:
    689             fprintf(irp->f, "@subWithOverflow(");
    690             break;
    691         case IrOverflowOpMul:
    692             fprintf(irp->f, "@mulWithOverflow(");
    693             break;
    694         case IrOverflowOpShl:
    695             fprintf(irp->f, "@shlWithOverflow(");
    696             break;
    697     }
    698     ir_print_other_instruction(irp, instruction->type_value);
    699     fprintf(irp->f, ", ");
    700     ir_print_other_instruction(irp, instruction->op1);
    701     fprintf(irp->f, ", ");
    702     ir_print_other_instruction(irp, instruction->op2);
    703     fprintf(irp->f, ", ");
    704     ir_print_other_instruction(irp, instruction->result_ptr);
    705     fprintf(irp->f, ")");
    706 }
    707 
    708 static void ir_print_test_err(IrPrint *irp, IrInstructionTestErr *instruction) {
    709     fprintf(irp->f, "@testError(");
    710     ir_print_other_instruction(irp, instruction->value);
    711     fprintf(irp->f, ")");
    712 }
    713 
    714 static void ir_print_unwrap_err_code(IrPrint *irp, IrInstructionUnwrapErrCode *instruction) {
    715     fprintf(irp->f, "@unwrapErrorCode(");
    716     ir_print_other_instruction(irp, instruction->value);
    717     fprintf(irp->f, ")");
    718 }
    719 
    720 static void ir_print_unwrap_err_payload(IrPrint *irp, IrInstructionUnwrapErrPayload *instruction) {
    721     fprintf(irp->f, "@unwrapErrorPayload(");
    722     ir_print_other_instruction(irp, instruction->value);
    723     fprintf(irp->f, ")");
    724     if (!instruction->safety_check_on) {
    725         fprintf(irp->f, " // no safety");
    726     }
    727 }
    728 
    729 static void ir_print_maybe_wrap(IrPrint *irp, IrInstructionMaybeWrap *instruction) {
    730     fprintf(irp->f, "@maybeWrap(");
    731     ir_print_other_instruction(irp, instruction->value);
    732     fprintf(irp->f, ")");
    733 }
    734 
    735 static void ir_print_err_wrap_code(IrPrint *irp, IrInstructionErrWrapCode *instruction) {
    736     fprintf(irp->f, "@errWrapCode(");
    737     ir_print_other_instruction(irp, instruction->value);
    738     fprintf(irp->f, ")");
    739 }
    740 
    741 static void ir_print_err_wrap_payload(IrPrint *irp, IrInstructionErrWrapPayload *instruction) {
    742     fprintf(irp->f, "@errWrapPayload(");
    743     ir_print_other_instruction(irp, instruction->value);
    744     fprintf(irp->f, ")");
    745 }
    746 
    747 static void ir_print_fn_proto(IrPrint *irp, IrInstructionFnProto *instruction) {
    748     fprintf(irp->f, "fn(");
    749     for (size_t i = 0; i < instruction->base.source_node->data.fn_proto.params.length; i += 1) {
    750         if (i != 0)
    751             fprintf(irp->f, ",");
    752         ir_print_other_instruction(irp, instruction->param_types[i]);
    753     }
    754     fprintf(irp->f, ")->");
    755     ir_print_other_instruction(irp, instruction->return_type);
    756 }
    757 
    758 static void ir_print_test_comptime(IrPrint *irp, IrInstructionTestComptime *instruction) {
    759     fprintf(irp->f, "@testComptime(");
    760     ir_print_other_instruction(irp, instruction->value);
    761     fprintf(irp->f, ")");
    762 }
    763 
    764 static void ir_print_init_enum(IrPrint *irp, IrInstructionInitEnum *instruction) {
    765     fprintf(irp->f, "%s.%s {", buf_ptr(&instruction->enum_type->name), buf_ptr(instruction->field->name));
    766     ir_print_other_instruction(irp, instruction->init_value);
    767     fprintf(irp->f, "}");
    768 }
    769 
    770 static void ir_print_pointer_reinterpret(IrPrint *irp, IrInstructionPointerReinterpret *instruction) {
    771     fprintf(irp->f, "@pointerReinterpret(");
    772     ir_print_other_instruction(irp, instruction->ptr);
    773     fprintf(irp->f, ")");
    774 }
    775 
    776 static void ir_print_widen_or_shorten(IrPrint *irp, IrInstructionWidenOrShorten *instruction) {
    777     fprintf(irp->f, "@widenOrShorten(");
    778     ir_print_other_instruction(irp, instruction->target);
    779     fprintf(irp->f, ")");
    780 }
    781 
    782 static void ir_print_ptr_to_int(IrPrint *irp, IrInstructionPtrToInt *instruction) {
    783     fprintf(irp->f, "@ptrToInt(");
    784     ir_print_other_instruction(irp, instruction->target);
    785     fprintf(irp->f, ")");
    786 }
    787 
    788 static void ir_print_int_to_ptr(IrPrint *irp, IrInstructionIntToPtr *instruction) {
    789     fprintf(irp->f, "@intToPtr(");
    790     ir_print_other_instruction(irp, instruction->target);
    791     fprintf(irp->f, ")");
    792 }
    793 
    794 static void ir_print_int_to_enum(IrPrint *irp, IrInstructionIntToEnum *instruction) {
    795     fprintf(irp->f, "@intToEnum(");
    796     ir_print_other_instruction(irp, instruction->target);
    797     fprintf(irp->f, ")");
    798 }
    799 
    800 static void ir_print_check_switch_prongs(IrPrint *irp, IrInstructionCheckSwitchProngs *instruction) {
    801     fprintf(irp->f, "@checkSwitchProngs(");
    802     ir_print_other_instruction(irp, instruction->target_value);
    803     fprintf(irp->f, ",");
    804     for (size_t i = 0; i < instruction->range_count; i += 1) {
    805         if (i != 0)
    806             fprintf(irp->f, ",");
    807         ir_print_other_instruction(irp, instruction->ranges[i].start);
    808         fprintf(irp->f, "...");
    809         ir_print_other_instruction(irp, instruction->ranges[i].end);
    810     }
    811     fprintf(irp->f, ")");
    812 }
    813 
    814 static void ir_print_test_type(IrPrint *irp, IrInstructionTestType *instruction) {
    815     fprintf(irp->f, "@testType(");
    816     ir_print_other_instruction(irp, instruction->type_value);
    817     fprintf(irp->f, ")");
    818 }
    819 
    820 static void ir_print_type_name(IrPrint *irp, IrInstructionTypeName *instruction) {
    821     fprintf(irp->f, "@typeName(");
    822     ir_print_other_instruction(irp, instruction->type_value);
    823     fprintf(irp->f, ")");
    824 }
    825 
    826 static void ir_print_can_implicit_cast(IrPrint *irp, IrInstructionCanImplicitCast *instruction) {
    827     fprintf(irp->f, "@canImplicitCast(");
    828     ir_print_other_instruction(irp, instruction->type_value);
    829     fprintf(irp->f, ",");
    830     ir_print_other_instruction(irp, instruction->target_value);
    831     fprintf(irp->f, ")");
    832 }
    833 
    834 static void ir_print_set_global_align(IrPrint *irp, IrInstructionSetGlobalAlign *instruction) {
    835     fprintf(irp->f, "@setGlobalAlign(%s,", buf_ptr(&instruction->var->name));
    836     ir_print_other_instruction(irp, instruction->value);
    837     fprintf(irp->f, ")");
    838 }
    839 
    840 static void ir_print_set_global_section(IrPrint *irp, IrInstructionSetGlobalSection *instruction) {
    841     fprintf(irp->f, "@setGlobalSection(%s,", buf_ptr(&instruction->var->name));
    842     ir_print_other_instruction(irp, instruction->value);
    843     fprintf(irp->f, ")");
    844 }
    845 
    846 static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
    847     ir_print_prefix(irp, instruction);
    848     switch (instruction->id) {
    849         case IrInstructionIdInvalid:
    850             zig_unreachable();
    851         case IrInstructionIdReturn:
    852             ir_print_return(irp, (IrInstructionReturn *)instruction);
    853             break;
    854         case IrInstructionIdConst:
    855             ir_print_const(irp, (IrInstructionConst *)instruction);
    856             break;
    857         case IrInstructionIdBinOp:
    858             ir_print_bin_op(irp, (IrInstructionBinOp *)instruction);
    859             break;
    860         case IrInstructionIdDeclVar:
    861             ir_print_decl_var(irp, (IrInstructionDeclVar *)instruction);
    862             break;
    863         case IrInstructionIdCast:
    864             ir_print_cast(irp, (IrInstructionCast *)instruction);
    865             break;
    866         case IrInstructionIdCall:
    867             ir_print_call(irp, (IrInstructionCall *)instruction);
    868             break;
    869         case IrInstructionIdUnOp:
    870             ir_print_un_op(irp, (IrInstructionUnOp *)instruction);
    871             break;
    872         case IrInstructionIdCondBr:
    873             ir_print_cond_br(irp, (IrInstructionCondBr *)instruction);
    874             break;
    875         case IrInstructionIdBr:
    876             ir_print_br(irp, (IrInstructionBr *)instruction);
    877             break;
    878         case IrInstructionIdPhi:
    879             ir_print_phi(irp, (IrInstructionPhi *)instruction);
    880             break;
    881         case IrInstructionIdContainerInitList:
    882             ir_print_container_init_list(irp, (IrInstructionContainerInitList *)instruction);
    883             break;
    884         case IrInstructionIdContainerInitFields:
    885             ir_print_container_init_fields(irp, (IrInstructionContainerInitFields *)instruction);
    886             break;
    887         case IrInstructionIdStructInit:
    888             ir_print_struct_init(irp, (IrInstructionStructInit *)instruction);
    889             break;
    890         case IrInstructionIdUnreachable:
    891             ir_print_unreachable(irp, (IrInstructionUnreachable *)instruction);
    892             break;
    893         case IrInstructionIdElemPtr:
    894             ir_print_elem_ptr(irp, (IrInstructionElemPtr *)instruction);
    895             break;
    896         case IrInstructionIdVarPtr:
    897             ir_print_var_ptr(irp, (IrInstructionVarPtr *)instruction);
    898             break;
    899         case IrInstructionIdLoadPtr:
    900             ir_print_load_ptr(irp, (IrInstructionLoadPtr *)instruction);
    901             break;
    902         case IrInstructionIdStorePtr:
    903             ir_print_store_ptr(irp, (IrInstructionStorePtr *)instruction);
    904             break;
    905         case IrInstructionIdTypeOf:
    906             ir_print_typeof(irp, (IrInstructionTypeOf *)instruction);
    907             break;
    908         case IrInstructionIdToPtrType:
    909             ir_print_to_ptr_type(irp, (IrInstructionToPtrType *)instruction);
    910             break;
    911         case IrInstructionIdPtrTypeChild:
    912             ir_print_ptr_type_child(irp, (IrInstructionPtrTypeChild *)instruction);
    913             break;
    914         case IrInstructionIdFieldPtr:
    915             ir_print_field_ptr(irp, (IrInstructionFieldPtr *)instruction);
    916             break;
    917         case IrInstructionIdStructFieldPtr:
    918             ir_print_struct_field_ptr(irp, (IrInstructionStructFieldPtr *)instruction);
    919             break;
    920         case IrInstructionIdEnumFieldPtr:
    921             ir_print_enum_field_ptr(irp, (IrInstructionEnumFieldPtr *)instruction);
    922             break;
    923         case IrInstructionIdSetFnTest:
    924             ir_print_set_fn_test(irp, (IrInstructionSetFnTest *)instruction);
    925             break;
    926         case IrInstructionIdSetFnVisible:
    927             ir_print_set_fn_visible(irp, (IrInstructionSetFnVisible *)instruction);
    928             break;
    929         case IrInstructionIdSetDebugSafety:
    930             ir_print_set_debug_safety(irp, (IrInstructionSetDebugSafety *)instruction);
    931             break;
    932         case IrInstructionIdArrayType:
    933             ir_print_array_type(irp, (IrInstructionArrayType *)instruction);
    934             break;
    935         case IrInstructionIdSliceType:
    936             ir_print_slice_type(irp, (IrInstructionSliceType *)instruction);
    937             break;
    938         case IrInstructionIdAsm:
    939             ir_print_asm(irp, (IrInstructionAsm *)instruction);
    940             break;
    941         case IrInstructionIdCompileVar:
    942             ir_print_compile_var(irp, (IrInstructionCompileVar *)instruction);
    943             break;
    944         case IrInstructionIdSizeOf:
    945             ir_print_size_of(irp, (IrInstructionSizeOf *)instruction);
    946             break;
    947         case IrInstructionIdTestNonNull:
    948             ir_print_test_null(irp, (IrInstructionTestNonNull *)instruction);
    949             break;
    950         case IrInstructionIdUnwrapMaybe:
    951             ir_print_unwrap_maybe(irp, (IrInstructionUnwrapMaybe *)instruction);
    952             break;
    953         case IrInstructionIdCtz:
    954             ir_print_ctz(irp, (IrInstructionCtz *)instruction);
    955             break;
    956         case IrInstructionIdClz:
    957             ir_print_clz(irp, (IrInstructionClz *)instruction);
    958             break;
    959         case IrInstructionIdSwitchBr:
    960             ir_print_switch_br(irp, (IrInstructionSwitchBr *)instruction);
    961             break;
    962         case IrInstructionIdSwitchVar:
    963             ir_print_switch_var(irp, (IrInstructionSwitchVar *)instruction);
    964             break;
    965         case IrInstructionIdSwitchTarget:
    966             ir_print_switch_target(irp, (IrInstructionSwitchTarget *)instruction);
    967             break;
    968         case IrInstructionIdEnumTag:
    969             ir_print_enum_tag(irp, (IrInstructionEnumTag *)instruction);
    970             break;
    971         case IrInstructionIdGeneratedCode:
    972             ir_print_generated_code(irp, (IrInstructionGeneratedCode *)instruction);
    973             break;
    974         case IrInstructionIdImport:
    975             ir_print_import(irp, (IrInstructionImport *)instruction);
    976             break;
    977         case IrInstructionIdArrayLen:
    978             ir_print_array_len(irp, (IrInstructionArrayLen *)instruction);
    979             break;
    980         case IrInstructionIdRef:
    981             ir_print_ref(irp, (IrInstructionRef *)instruction);
    982             break;
    983         case IrInstructionIdMinValue:
    984             ir_print_min_value(irp, (IrInstructionMinValue *)instruction);
    985             break;
    986         case IrInstructionIdMaxValue:
    987             ir_print_max_value(irp, (IrInstructionMaxValue *)instruction);
    988             break;
    989         case IrInstructionIdCompileErr:
    990             ir_print_compile_err(irp, (IrInstructionCompileErr *)instruction);
    991             break;
    992         case IrInstructionIdErrName:
    993             ir_print_err_name(irp, (IrInstructionErrName *)instruction);
    994             break;
    995         case IrInstructionIdCImport:
    996             ir_print_c_import(irp, (IrInstructionCImport *)instruction);
    997             break;
    998         case IrInstructionIdCInclude:
    999             ir_print_c_include(irp, (IrInstructionCInclude *)instruction);
   1000             break;
   1001         case IrInstructionIdCDefine:
   1002             ir_print_c_define(irp, (IrInstructionCDefine *)instruction);
   1003             break;
   1004         case IrInstructionIdCUndef:
   1005             ir_print_c_undef(irp, (IrInstructionCUndef *)instruction);
   1006             break;
   1007         case IrInstructionIdEmbedFile:
   1008             ir_print_embed_file(irp, (IrInstructionEmbedFile *)instruction);
   1009             break;
   1010         case IrInstructionIdCmpxchg:
   1011             ir_print_cmpxchg(irp, (IrInstructionCmpxchg *)instruction);
   1012             break;
   1013         case IrInstructionIdFence:
   1014             ir_print_fence(irp, (IrInstructionFence *)instruction);
   1015             break;
   1016         case IrInstructionIdDivExact:
   1017             ir_print_div_exact(irp, (IrInstructionDivExact *)instruction);
   1018             break;
   1019         case IrInstructionIdTruncate:
   1020             ir_print_truncate(irp, (IrInstructionTruncate *)instruction);
   1021             break;
   1022         case IrInstructionIdAlloca:
   1023             ir_print_alloca(irp, (IrInstructionAlloca *)instruction);
   1024             break;
   1025         case IrInstructionIdIntType:
   1026             ir_print_int_type(irp, (IrInstructionIntType *)instruction);
   1027             break;
   1028         case IrInstructionIdBoolNot:
   1029             ir_print_bool_not(irp, (IrInstructionBoolNot *)instruction);
   1030             break;
   1031         case IrInstructionIdMemset:
   1032             ir_print_memset(irp, (IrInstructionMemset *)instruction);
   1033             break;
   1034         case IrInstructionIdMemcpy:
   1035             ir_print_memcpy(irp, (IrInstructionMemcpy *)instruction);
   1036             break;
   1037         case IrInstructionIdSlice:
   1038             ir_print_slice(irp, (IrInstructionSlice *)instruction);
   1039             break;
   1040         case IrInstructionIdMemberCount:
   1041             ir_print_member_count(irp, (IrInstructionMemberCount *)instruction);
   1042             break;
   1043         case IrInstructionIdBreakpoint:
   1044             ir_print_breakpoint(irp, (IrInstructionBreakpoint *)instruction);
   1045             break;
   1046         case IrInstructionIdReturnAddress:
   1047             ir_print_return_address(irp, (IrInstructionReturnAddress *)instruction);
   1048             break;
   1049         case IrInstructionIdFrameAddress:
   1050             ir_print_frame_address(irp, (IrInstructionFrameAddress *)instruction);
   1051             break;
   1052         case IrInstructionIdAlignOf:
   1053             ir_print_alignof(irp, (IrInstructionAlignOf *)instruction);
   1054             break;
   1055         case IrInstructionIdOverflowOp:
   1056             ir_print_overflow_op(irp, (IrInstructionOverflowOp *)instruction);
   1057             break;
   1058         case IrInstructionIdTestErr:
   1059             ir_print_test_err(irp, (IrInstructionTestErr *)instruction);
   1060             break;
   1061         case IrInstructionIdUnwrapErrCode:
   1062             ir_print_unwrap_err_code(irp, (IrInstructionUnwrapErrCode *)instruction);
   1063             break;
   1064         case IrInstructionIdUnwrapErrPayload:
   1065             ir_print_unwrap_err_payload(irp, (IrInstructionUnwrapErrPayload *)instruction);
   1066             break;
   1067         case IrInstructionIdMaybeWrap:
   1068             ir_print_maybe_wrap(irp, (IrInstructionMaybeWrap *)instruction);
   1069             break;
   1070         case IrInstructionIdErrWrapCode:
   1071             ir_print_err_wrap_code(irp, (IrInstructionErrWrapCode *)instruction);
   1072             break;
   1073         case IrInstructionIdErrWrapPayload:
   1074             ir_print_err_wrap_payload(irp, (IrInstructionErrWrapPayload *)instruction);
   1075             break;
   1076         case IrInstructionIdFnProto:
   1077             ir_print_fn_proto(irp, (IrInstructionFnProto *)instruction);
   1078             break;
   1079         case IrInstructionIdTestComptime:
   1080             ir_print_test_comptime(irp, (IrInstructionTestComptime *)instruction);
   1081             break;
   1082         case IrInstructionIdInitEnum:
   1083             ir_print_init_enum(irp, (IrInstructionInitEnum *)instruction);
   1084             break;
   1085         case IrInstructionIdPointerReinterpret:
   1086             ir_print_pointer_reinterpret(irp, (IrInstructionPointerReinterpret *)instruction);
   1087             break;
   1088         case IrInstructionIdWidenOrShorten:
   1089             ir_print_widen_or_shorten(irp, (IrInstructionWidenOrShorten *)instruction);
   1090             break;
   1091         case IrInstructionIdPtrToInt:
   1092             ir_print_ptr_to_int(irp, (IrInstructionPtrToInt *)instruction);
   1093             break;
   1094         case IrInstructionIdIntToPtr:
   1095             ir_print_int_to_ptr(irp, (IrInstructionIntToPtr *)instruction);
   1096             break;
   1097         case IrInstructionIdIntToEnum:
   1098             ir_print_int_to_enum(irp, (IrInstructionIntToEnum *)instruction);
   1099             break;
   1100         case IrInstructionIdCheckSwitchProngs:
   1101             ir_print_check_switch_prongs(irp, (IrInstructionCheckSwitchProngs *)instruction);
   1102             break;
   1103         case IrInstructionIdTestType:
   1104             ir_print_test_type(irp, (IrInstructionTestType *)instruction);
   1105             break;
   1106         case IrInstructionIdTypeName:
   1107             ir_print_type_name(irp, (IrInstructionTypeName *)instruction);
   1108             break;
   1109         case IrInstructionIdCanImplicitCast:
   1110             ir_print_can_implicit_cast(irp, (IrInstructionCanImplicitCast *)instruction);
   1111             break;
   1112         case IrInstructionIdSetGlobalAlign:
   1113             ir_print_set_global_align(irp, (IrInstructionSetGlobalAlign *)instruction);
   1114             break;
   1115         case IrInstructionIdSetGlobalSection:
   1116             ir_print_set_global_section(irp, (IrInstructionSetGlobalSection *)instruction);
   1117             break;
   1118     }
   1119     fprintf(irp->f, "\n");
   1120 }
   1121 
   1122 void ir_print(FILE *f, IrExecutable *executable, int indent_size) {
   1123     IrPrint ir_print = {};
   1124     IrPrint *irp = &ir_print;
   1125     irp->f = f;
   1126     irp->indent = indent_size;
   1127     irp->indent_size = indent_size;
   1128 
   1129     for (size_t bb_i = 0; bb_i < executable->basic_block_list.length; bb_i += 1) {
   1130         IrBasicBlock *current_block = executable->basic_block_list.at(bb_i);
   1131         fprintf(irp->f, "%s_%zu:\n", current_block->name_hint, current_block->debug_id);
   1132         for (size_t instr_i = 0; instr_i < current_block->instruction_list.length; instr_i += 1) {
   1133             IrInstruction *instruction = current_block->instruction_list.at(instr_i);
   1134             ir_print_instruction(irp, instruction);
   1135         }
   1136     }
   1137 }