| ... | ... | @@ -15785,11 +15785,10 @@ static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_na |
| 15785 | 15785 | |
| 15786 | 15786 | Buf field_name = BUF_INIT; |
| 15787 | 15787 | buf_init_from_str(&field_name, type_name); |
| 15788 | | auto entry = type_info_scope->decl_table.maybe_get(&field_name); |
| 15788 | auto entry = type_info_scope->decl_table.get(&field_name); |
| 15789 | 15789 | buf_deinit(&field_name); |
| 15790 | | assert(entry != nullptr); |
| 15791 | 15790 | |
| 15792 | | TldVar *tld = (TldVar *)entry->value; |
| 15791 | TldVar *tld = (TldVar *)entry; |
| 15793 | 15792 | assert(tld->base.id == TldIdVar); |
| 15794 | 15793 | |
| 15795 | 15794 | VariableTableEntry *var = tld->var; |
| ... | ... | @@ -16071,6 +16070,38 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t |
| 16071 | 16070 | enum_field_val->data.x_struct.fields = inner_fields; |
| 16072 | 16071 | }; |
| 16073 | 16072 | |
| 16073 | const auto create_ptr_like_type_info = [ira](const char *name, TypeTableEntry *ptr_type_entry) { |
| 16074 | ConstExprValue *result = create_const_vals(1); |
| 16075 | result->special = ConstValSpecialStatic; |
| 16076 | result->type = ir_type_info_get_type(ira, name); |
| 16077 | |
| 16078 | ConstExprValue *fields = create_const_vals(4); |
| 16079 | result->data.x_struct.fields = fields; |
| 16080 | |
| 16081 | // is_const: bool |
| 16082 | ensure_field_index(result->type, "is_const", 0); |
| 16083 | fields[0].special = ConstValSpecialStatic; |
| 16084 | fields[0].type = ira->codegen->builtin_types.entry_bool; |
| 16085 | fields[0].data.x_bool = ptr_type_entry->data.pointer.is_const; |
| 16086 | // is_volatile: bool |
| 16087 | ensure_field_index(result->type, "is_volatile", 1); |
| 16088 | fields[1].special = ConstValSpecialStatic; |
| 16089 | fields[1].type = ira->codegen->builtin_types.entry_bool; |
| 16090 | fields[1].data.x_bool = ptr_type_entry->data.pointer.is_volatile; |
| 16091 | // alignment: u32 |
| 16092 | ensure_field_index(result->type, "alignment", 2); |
| 16093 | fields[2].special = ConstValSpecialStatic; |
| 16094 | fields[2].type = ira->codegen->builtin_types.entry_u32; |
| 16095 | bigint_init_unsigned(&fields[2].data.x_bigint, ptr_type_entry->data.pointer.alignment); |
| 16096 | // child: type |
| 16097 | ensure_field_index(result->type, "child", 3); |
| 16098 | fields[3].special = ConstValSpecialStatic; |
| 16099 | fields[3].type = ira->codegen->builtin_types.entry_type; |
| 16100 | fields[3].data.x_type = ptr_type_entry->data.pointer.child_type; |
| 16101 | |
| 16102 | return result; |
| 16103 | }; |
| 16104 | |
| 16074 | 16105 | ConstExprValue *result = nullptr; |
| 16075 | 16106 | switch (type_entry->id) |
| 16076 | 16107 | { |
| ... | ... | @@ -16139,34 +16170,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t |
| 16139 | 16170 | } |
| 16140 | 16171 | case TypeTableEntryIdPointer: |
| 16141 | 16172 | { |
| 16142 | | result = create_const_vals(1); |
| 16143 | | result->special = ConstValSpecialStatic; |
| 16144 | | result->type = ir_type_info_get_type(ira, "Pointer"); |
| 16145 | | |
| 16146 | | ConstExprValue *fields = create_const_vals(4); |
| 16147 | | result->data.x_struct.fields = fields; |
| 16148 | | |
| 16149 | | // is_const: bool |
| 16150 | | ensure_field_index(result->type, "is_const", 0); |
| 16151 | | fields[0].special = ConstValSpecialStatic; |
| 16152 | | fields[0].type = ira->codegen->builtin_types.entry_bool; |
| 16153 | | fields[0].data.x_bool = type_entry->data.pointer.is_const; |
| 16154 | | // is_volatile: bool |
| 16155 | | ensure_field_index(result->type, "is_volatile", 1); |
| 16156 | | fields[1].special = ConstValSpecialStatic; |
| 16157 | | fields[1].type = ira->codegen->builtin_types.entry_bool; |
| 16158 | | fields[1].data.x_bool = type_entry->data.pointer.is_volatile; |
| 16159 | | // alignment: u32 |
| 16160 | | ensure_field_index(result->type, "alignment", 2); |
| 16161 | | fields[2].special = ConstValSpecialStatic; |
| 16162 | | fields[2].type = ira->codegen->builtin_types.entry_u32; |
| 16163 | | bigint_init_unsigned(&fields[2].data.x_bigint, type_entry->data.pointer.alignment); |
| 16164 | | // child: type |
| 16165 | | ensure_field_index(result->type, "child", 3); |
| 16166 | | fields[3].special = ConstValSpecialStatic; |
| 16167 | | fields[3].type = ira->codegen->builtin_types.entry_type; |
| 16168 | | fields[3].data.x_type = type_entry->data.pointer.child_type; |
| 16169 | | |
| 16173 | result = create_ptr_like_type_info("Pointer", type_entry); |
| 16170 | 16174 | break; |
| 16171 | 16175 | } |
| 16172 | 16176 | case TypeTableEntryIdArray: |
| ... | ... | @@ -16436,6 +16440,16 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t |
| 16436 | 16440 | } |
| 16437 | 16441 | case TypeTableEntryIdStruct: |
| 16438 | 16442 | { |
| 16443 | if (type_entry->data.structure.is_slice) { |
| 16444 | Buf ptr_field_name = BUF_INIT; |
| 16445 | buf_init_from_str(&ptr_field_name, "ptr"); |
| 16446 | TypeTableEntry *ptr_type = type_entry->data.structure.fields_by_name.get(&ptr_field_name)->type_entry; |
| 16447 | ensure_complete_type(ira->codegen, ptr_type); |
| 16448 | |
| 16449 | result = create_ptr_like_type_info("Slice", ptr_type); |
| 16450 | break; |
| 16451 | } |
| 16452 | |
| 16439 | 16453 | result = create_const_vals(1); |
| 16440 | 16454 | result->special = ConstValSpecialStatic; |
| 16441 | 16455 | result->type = ir_type_info_get_type(ira, "Struct"); |
| ... | ... | @@ -16622,7 +16636,7 @@ static TypeTableEntry *ir_analyze_instruction_type_info(IrAnalyze *ira, |
| 16622 | 16636 | |
| 16623 | 16637 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 16624 | 16638 | out_val->type = result_type; |
| 16625 | | bigint_init_unsigned(&out_val->data.x_union.tag, type_id_index(type_entry->id)); |
| 16639 | bigint_init_unsigned(&out_val->data.x_union.tag, type_id_index(type_entry)); |
| 16626 | 16640 | |
| 16627 | 16641 | ConstExprValue *payload = ir_make_type_info_value(ira, type_entry); |
| 16628 | 16642 | out_val->data.x_union.payload = payload; |
| ... | ... | @@ -16650,7 +16664,7 @@ static TypeTableEntry *ir_analyze_instruction_type_id(IrAnalyze *ira, |
| 16650 | 16664 | TypeTableEntry *result_type = var_value->data.x_type; |
| 16651 | 16665 | |
| 16652 | 16666 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 16653 | | bigint_init_unsigned(&out_val->data.x_enum_tag, type_id_index(type_entry->id)); |
| 16667 | bigint_init_unsigned(&out_val->data.x_enum_tag, type_id_index(type_entry)); |
| 16654 | 16668 | return result_type; |
| 16655 | 16669 | } |
| 16656 | 16670 | |