diff options
Diffstat (limited to 'src/ir_print.cpp')
| -rw-r--r-- | src/ir_print.cpp | 173 |
1 files changed, 4 insertions, 169 deletions
diff --git a/src/ir_print.cpp b/src/ir_print.cpp index eb95a2681e..c3df0df831 100644 --- a/src/ir_print.cpp +++ b/src/ir_print.cpp @@ -32,175 +32,10 @@ static void ir_print_prefix(IrPrint *irp, IrInstruction *instruction) { } static void ir_print_const_value(IrPrint *irp, ConstExprValue *const_val) { - switch (const_val->special) { - case ConstValSpecialRuntime: - zig_unreachable(); - case ConstValSpecialUndef: - fprintf(irp->f, "undefined"); - return; - case ConstValSpecialZeroes: - fprintf(irp->f, "zeroes"); - return; - case ConstValSpecialStatic: - break; - } - assert(const_val->type); - - TypeTableEntry *canon_type = get_underlying_type(const_val->type); - switch (canon_type->id) { - case TypeTableEntryIdTypeDecl: - zig_unreachable(); - case TypeTableEntryIdInvalid: - fprintf(irp->f, "(invalid)"); - return; - case TypeTableEntryIdVar: - fprintf(irp->f, "(var)"); - return; - case TypeTableEntryIdVoid: - fprintf(irp->f, "{}"); - return; - case TypeTableEntryIdNumLitFloat: - fprintf(irp->f, "%f", const_val->data.x_bignum.data.x_float); - return; - case TypeTableEntryIdNumLitInt: - { - BigNum *bignum = &const_val->data.x_bignum; - const char *negative_str = bignum->is_negative ? "-" : ""; - fprintf(irp->f, "%s%llu", negative_str, bignum->data.x_uint); - return; - } - case TypeTableEntryIdMetaType: - fprintf(irp->f, "%s", buf_ptr(&const_val->data.x_type->name)); - return; - case TypeTableEntryIdInt: - { - BigNum *bignum = &const_val->data.x_bignum; - assert(bignum->kind == BigNumKindInt); - const char *negative_str = bignum->is_negative ? "-" : ""; - fprintf(irp->f, "%s%llu", negative_str, bignum->data.x_uint); - } - return; - case TypeTableEntryIdFloat: - { - BigNum *bignum = &const_val->data.x_bignum; - assert(bignum->kind == BigNumKindFloat); - fprintf(irp->f, "%f", bignum->data.x_float); - } - return; - case TypeTableEntryIdUnreachable: - fprintf(irp->f, "@unreachable()"); - return; - case TypeTableEntryIdBool: - { - const char *value = const_val->data.x_bool ? "true" : "false"; - fprintf(irp->f, "%s", value); - return; - } - case TypeTableEntryIdPointer: - fprintf(irp->f, "&"); - if (const_val->data.x_ptr.special == ConstPtrSpecialRuntime) { - fprintf(irp->f, "(runtime pointer value)"); - } else if (const_val->data.x_ptr.special == ConstPtrSpecialCStr) { - fprintf(irp->f, "(c str lit)"); - } else { - ir_print_const_value(irp, const_ptr_pointee(const_val)); - } - return; - case TypeTableEntryIdFn: - { - FnTableEntry *fn_entry = const_val->data.x_fn; - fprintf(irp->f, "%s", buf_ptr(&fn_entry->symbol_name)); - return; - } - case TypeTableEntryIdBlock: - { - AstNode *node = const_val->data.x_block->source_node; - fprintf(irp->f, "(scope:%zu:%zu)", node->line + 1, node->column + 1); - return; - } - case TypeTableEntryIdArray: - { - uint64_t len = canon_type->data.array.len; - fprintf(irp->f, "%s{", buf_ptr(&canon_type->name)); - for (uint64_t i = 0; i < len; i += 1) { - if (i != 0) - fprintf(irp->f, ","); - ConstExprValue *child_value = &const_val->data.x_array.elements[i]; - ir_print_const_value(irp, child_value); - } - fprintf(irp->f, "}"); - return; - } - case TypeTableEntryIdNullLit: - { - fprintf(irp->f, "null"); - return; - } - case TypeTableEntryIdUndefLit: - { - fprintf(irp->f, "undefined"); - return; - } - case TypeTableEntryIdMaybe: - { - if (const_val->data.x_maybe) { - ir_print_const_value(irp, const_val->data.x_maybe); - } else { - fprintf(irp->f, "null"); - } - return; - } - case TypeTableEntryIdNamespace: - { - ImportTableEntry *import = const_val->data.x_import; - if (import->c_import_node) { - fprintf(irp->f, "(namespace from C import)"); - } else { - fprintf(irp->f, "(namespace: %s)", buf_ptr(import->path)); - } - return; - } - case TypeTableEntryIdBoundFn: - { - FnTableEntry *fn_entry = const_val->data.x_bound_fn.fn; - fprintf(irp->f, "bound %s to ", buf_ptr(&fn_entry->symbol_name)); - ir_print_other_instruction(irp, const_val->data.x_bound_fn.first_arg); - return; - } - case TypeTableEntryIdStruct: - { - fprintf(irp->f, "(struct %s constant)", buf_ptr(&canon_type->name)); - return; - } - case TypeTableEntryIdEnum: - { - fprintf(irp->f, "(enum %s constant)", buf_ptr(&canon_type->name)); - return; - } - case TypeTableEntryIdErrorUnion: - { - fprintf(irp->f, "(error union %s constant)", buf_ptr(&canon_type->name)); - return; - } - case TypeTableEntryIdUnion: - { - fprintf(irp->f, "(union %s constant)", buf_ptr(&canon_type->name)); - return; - } - case TypeTableEntryIdPureError: - { - fprintf(irp->f, "(pure error constant)"); - return; - } - case TypeTableEntryIdEnumTag: - { - TypeTableEntry *enum_type = canon_type->data.enum_tag.enum_type; - TypeEnumField *field = &enum_type->data.enumeration.fields[const_val->data.x_bignum.data.x_uint]; - fprintf(irp->f, "%s.%s", buf_ptr(&enum_type->name), buf_ptr(field->name)); - return; - } - } - zig_unreachable(); + Buf buf = BUF_INIT; + buf_resize(&buf, 0); + render_const_value(&buf, const_val); + fprintf(irp->f, "%s", buf_ptr(&buf)); } static void ir_print_var_instruction(IrPrint *irp, IrInstruction *instruction) { |
