authorgravatar for alex_naskos@hotmail.comAlexandros Naskos <alex_naskos@hotmail.com> 2018-04-24 16:23:22+03:00
committergravatar for alex_naskos@hotmail.comAlexandros Naskos <alex_naskos@hotmail.com> 2018-04-24 16:23:22+03:00
log0e5fb035e3d12879b4bd7a23578fdb8932deb4d1
tree25200f02e929418bdda907f8d31d4dd3cc6bdab6
parente9309d3b1310863d9571486b071b7a34bea1fb60

Added (broken) pointer info, float info


1 files changed, 125 insertions(+), 30 deletions(-)

src/ir.cpp+125-30
......@@ -15728,27 +15728,13 @@ static TypeTableEntry *ir_analyze_instruction_offset_of(IrAnalyze *ira,
1572815728 return ira->codegen->builtin_types.entry_num_lit_int;
1572915729}
1573015730
15731static TypeTableEntry *ir_analyze_instruction_type_info(IrAnalyze *ira,
15732 IrInstructionTypeInfo *instruction)
15731static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *parent, TypeTableEntry *type_entry)
1573315732{
15734 IrInstruction *type_value = instruction->type_value->other;
15735 TypeTableEntry *type_entry = ir_resolve_type(ira, type_value);
15736 if (type_is_invalid(type_entry))
15737 return ira->codegen->builtin_types.entry_invalid;
15733 assert(type_entry != nullptr);
15734 assert(!type_is_invalid(type_entry));
1573815735
15739 ConstExprValue *var_value = get_builtin_value(ira->codegen, "TypeInfo");
15740 assert(var_value->type->id == TypeTableEntryIdMetaType);
15741 TypeTableEntry *result_type = var_value->data.x_type;
15742
15743 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
15744 // TODO: Do I need those? probably set in ir_build_const_from
15745 //out_val->special = ConstValSpecialStatic;
15746 //out_val->type = result_type;
15747
15748 bigint_init_unsigned(&out_val->data.x_union.tag, type_id_index(type_entry->id));
15749 //out_val->data.x_union.parent.id = ConstParentIdNone;
15750
15751 switch (type_entry->id) {
15736 switch (type_entry->id)
15737 {
1575215738 case TypeTableEntryIdInvalid:
1575315739 zig_unreachable();
1575415740 case TypeTableEntryIdMetaType:
......@@ -15763,14 +15749,11 @@ static TypeTableEntry *ir_analyze_instruction_type_info(IrAnalyze *ira,
1576315749 case TypeTableEntryIdBlock:
1576415750 case TypeTableEntryIdArgTuple:
1576515751 case TypeTableEntryIdOpaque:
15766 out_val->data.x_union.payload = nullptr;
15767 break;
15752 // TODO: Construct a valid void payload.
15753 return nullptr;
1576815754 case TypeTableEntryIdInt:
1576915755 {
15770 // Error from 'ir_resolve_const': "unable to evaluate constant expression"
1577115756 ConstExprValue *payload = create_const_vals(1);
15772 out_val->data.x_union.payload = payload;
15773
1577415757 payload->special = ConstValSpecialStatic;
1577515758
1577615759 ConstExprValue *int_info_type = get_builtin_value(ira->codegen, "IntInfo");
......@@ -15780,23 +15763,135 @@ static TypeTableEntry *ir_analyze_instruction_type_info(IrAnalyze *ira,
1578015763 ConstExprValue *fields = create_const_vals(2);
1578115764 payload->data.x_struct.fields = fields;
1578215765
15783 payload->data.x_struct.parent.id = ConstParentIdUnion;
15784 payload->data.x_struct.parent.data.p_union.union_val = out_val;
15766 if (parent->type->id == TypeTableEntryIdStruct)
15767 {
15768 payload->data.x_struct.parent.id = ConstParentIdStruct;
15769 payload->data.x_struct.parent.data.p_union.union_val = parent;
15770 }
15771 else if (parent->type->id == TypeTableEntryIdUnion)
15772 {
15773 payload->data.x_struct.parent.id = ConstParentIdUnion;
15774 payload->data.x_struct.parent.data.p_union.union_val = parent;
15775 }
15776 else
15777 {
15778 payload->data.x_struct.parent.id = ConstParentIdNone;
15779 }
1578515780
15786 // TODO: See what happens if we don't set the field type (set it to nullptr)
15781 // is_signed: bool
1578715782 fields[0].special = ConstValSpecialStatic;
1578815783 fields[0].type = ira->codegen->builtin_types.entry_bool;
1578915784 fields[0].data.x_bool = type_entry->data.integral.is_signed;
15790
15785 // bits: u8
1579115786 fields[1].special = ConstValSpecialStatic;
1579215787 fields[1].type = ira->codegen->builtin_types.entry_u8;
1579315788 bigint_init_unsigned(&fields[1].data.x_bigint, type_entry->data.integral.bit_count);
1579415789
15795 break;
15790 return payload;
15791 }
15792 case TypeTableEntryIdFloat:
15793 {
15794 ConstExprValue *payload = create_const_vals(1);
15795 payload->special = ConstValSpecialStatic;
15796
15797 ConstExprValue *float_info_type = get_builtin_value(ira->codegen, "FloatInfo");
15798 assert(float_info_type->type->id == TypeTableEntryIdMetaType);
15799 payload->type = float_info_type->data.x_type;
15800
15801 ConstExprValue *fields = create_const_vals(1);
15802 payload->data.x_struct.fields = fields;
15803
15804 if (parent->type->id == TypeTableEntryIdStruct)
15805 {
15806 payload->data.x_struct.parent.id = ConstParentIdStruct;
15807 payload->data.x_struct.parent.data.p_union.union_val = parent;
15808 }
15809 else if (parent->type->id == TypeTableEntryIdUnion)
15810 {
15811 payload->data.x_struct.parent.id = ConstParentIdUnion;
15812 payload->data.x_struct.parent.data.p_union.union_val = parent;
15813 }
15814 else
15815 {
15816 payload->data.x_struct.parent.id = ConstParentIdNone;
15817 }
15818 // bits: u8
15819 fields[0].special = ConstValSpecialStatic;
15820 fields[0].type = ira->codegen->builtin_types.entry_u8;
15821 bigint_init_unsigned(&fields->data.x_bigint, type_entry->data.floating.bit_count);
15822
15823 return payload;
15824 }
15825 case TypeTableEntryIdPointer:
15826 {
15827 ConstExprValue *payload = create_const_vals(1);
15828 payload->special = ConstValSpecialStatic;
15829
15830 ConstExprValue *pointer_info_type = get_builtin_value(ira->codegen, "PointerInfo");
15831 assert(pointer_info_type->type->id == TypeTableEntryIdMetaType);
15832 payload->type = pointer_info_type->data.x_type;
15833
15834 ConstExprValue *fields = create_const_vals(4);
15835 payload->data.x_struct.fields = fields;
15836
15837 if (parent->type->id == TypeTableEntryIdStruct)
15838 {
15839 payload->data.x_struct.parent.id = ConstParentIdStruct;
15840 payload->data.x_struct.parent.data.p_union.union_val = parent;
15841 }
15842 else if (parent->type->id == TypeTableEntryIdUnion)
15843 {
15844 payload->data.x_struct.parent.id = ConstParentIdUnion;
15845 payload->data.x_struct.parent.data.p_union.union_val = parent;
15846 }
15847 else
15848 {
15849 payload->data.x_struct.parent.id = ConstParentIdNone;
15850 }
15851 // is_const: bool
15852 fields[0].special = ConstValSpecialStatic;
15853 fields[0].type = ira->codegen->builtin_types.entry_bool;
15854 fields[0].data.x_bool = type_entry->data.pointer.is_const;
15855 // is_volatile: bool
15856 fields[1].special = ConstValSpecialStatic;
15857 fields[1].type = ira->codegen->builtin_types.entry_bool;
15858 fields[1].data.x_bool = type_entry->data.pointer.is_volatile;
15859 // alignment: u32
15860 fields[2].special = ConstValSpecialStatic;
15861 fields[2].type = ira->codegen->builtin_types.entry_u32;
15862 bigint_init_unsigned(&fields->data.x_bigint, type_entry->data.pointer.alignment);
15863 // child: &TypeInfo
15864 ConstExprValue *type_info_type = get_builtin_value(ira->codegen, "TypeInfo");
15865 assert(type_info_type->type->id == TypeTableEntryIdMetaType);
15866 fields[3].special = ConstValSpecialStatic;
15867 fields[3].type = get_pointer_to_type(ira->codegen, type_info_type->data.x_type, false);
15868 fields[3].data.x_ptr.special = ConstPtrSpecialRef;
15869 fields[3].data.x_ptr.mut = ConstPtrMutComptimeVar;
15870 fields[3].data.x_ptr.data.ref.pointee = ir_make_type_info_value(ira, &fields[3], type_entry->data.pointer.child_type);
15871 return payload;
1579615872 }
1579715873 default:
15798 zig_panic("@typeInfo unsupported for %s", buf_ptr(&type_entry->name));
15874 zig_unreachable();
1579915875 }
15876}
15877
15878static TypeTableEntry *ir_analyze_instruction_type_info(IrAnalyze *ira,
15879 IrInstructionTypeInfo *instruction)
15880{
15881 IrInstruction *type_value = instruction->type_value->other;
15882 TypeTableEntry *type_entry = ir_resolve_type(ira, type_value);
15883 if (type_is_invalid(type_entry))
15884 return ira->codegen->builtin_types.entry_invalid;
15885
15886 ConstExprValue *var_value = get_builtin_value(ira->codegen, "TypeInfo");
15887 assert(var_value->type->id == TypeTableEntryIdMetaType);
15888 TypeTableEntry *result_type = var_value->data.x_type;
15889
15890 // TODO: We need to return a const pointer to the typeinfo, not the typeinfo by value.
15891 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
15892 out_val->type = result_type;
15893 bigint_init_unsigned(&out_val->data.x_union.tag, type_id_index(type_entry->id));
15894 out_val->data.x_union.payload = ir_make_type_info_value(ira, out_val, type_entry);
1580015895
1580115896 return result_type;
1580215897}