mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 15:18:49 +00:00
Only store field_index remove field_src_index (for the time being)
This commit is contained in:
@@ -1989,7 +1989,7 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32
|
|||||||
Entity *old_field = old_struct->Struct.fields[i];
|
Entity *old_field = old_struct->Struct.fields[i];
|
||||||
if (old_field->kind == Entity_Variable) {
|
if (old_field->kind == Entity_Variable) {
|
||||||
Type *array_type = alloc_type_array(old_field->type, count);
|
Type *array_type = alloc_type_array(old_field->type, count);
|
||||||
Entity *new_field = alloc_entity_field(scope, old_field->token, array_type, false, old_field->Variable.field_src_index);
|
Entity *new_field = alloc_entity_field(scope, old_field->token, array_type, false, old_field->Variable.field_index);
|
||||||
soa_struct->Struct.fields[i] = new_field;
|
soa_struct->Struct.fields[i] = new_field;
|
||||||
add_entity(c, scope, nullptr, new_field);
|
add_entity(c, scope, nullptr, new_field);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+1
-1
@@ -2317,7 +2317,7 @@ Type *make_soa_struct_internal(CheckerContext *ctx, Ast *array_typ_expr, Ast *el
|
|||||||
} else {
|
} else {
|
||||||
field_type = alloc_type_pointer(old_field->type);
|
field_type = alloc_type_pointer(old_field->type);
|
||||||
}
|
}
|
||||||
Entity *new_field = alloc_entity_field(scope, old_field->token, field_type, false, old_field->Variable.field_src_index);
|
Entity *new_field = alloc_entity_field(scope, old_field->token, field_type, false, old_field->Variable.field_index);
|
||||||
soa_struct->Struct.fields[i] = new_field;
|
soa_struct->Struct.fields[i] = new_field;
|
||||||
add_entity(ctx, scope, nullptr, new_field);
|
add_entity(ctx, scope, nullptr, new_field);
|
||||||
add_entity_use(ctx, nullptr, new_field);
|
add_entity_use(ctx, nullptr, new_field);
|
||||||
|
|||||||
+5
-8
@@ -155,8 +155,7 @@ struct Entity {
|
|||||||
} Constant;
|
} Constant;
|
||||||
struct {
|
struct {
|
||||||
Ast *init_expr; // only used for some variables within procedure bodies
|
Ast *init_expr; // only used for some variables within procedure bodies
|
||||||
i32 field_index;
|
i32 field_index;
|
||||||
i32 field_src_index;
|
|
||||||
|
|
||||||
ParameterValue param_value;
|
ParameterValue param_value;
|
||||||
Ast * param_expr;
|
Ast * param_expr;
|
||||||
@@ -319,20 +318,18 @@ Entity *alloc_entity_const_param(Scope *scope, Token token, Type *type, ExactVal
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Entity *alloc_entity_field(Scope *scope, Token token, Type *type, bool is_using, i32 field_src_index, EntityState state = EntityState_Unresolved) {
|
Entity *alloc_entity_field(Scope *scope, Token token, Type *type, bool is_using, i32 field_index, EntityState state = EntityState_Unresolved) {
|
||||||
Entity *entity = alloc_entity_variable(scope, token, type);
|
Entity *entity = alloc_entity_variable(scope, token, type);
|
||||||
entity->Variable.field_src_index = field_src_index;
|
entity->Variable.field_index = field_index;
|
||||||
entity->Variable.field_index = field_src_index;
|
|
||||||
if (is_using) entity->flags |= EntityFlag_Using;
|
if (is_using) entity->flags |= EntityFlag_Using;
|
||||||
entity->flags |= EntityFlag_Field;
|
entity->flags |= EntityFlag_Field;
|
||||||
entity->state = state;
|
entity->state = state;
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
Entity *alloc_entity_array_elem(Scope *scope, Token token, Type *type, i32 field_src_index) {
|
Entity *alloc_entity_array_elem(Scope *scope, Token token, Type *type, i32 field_index) {
|
||||||
Entity *entity = alloc_entity_variable(scope, token, type);
|
Entity *entity = alloc_entity_variable(scope, token, type);
|
||||||
entity->Variable.field_src_index = field_src_index;
|
entity->Variable.field_index = field_index;
|
||||||
entity->Variable.field_index = field_src_index;
|
|
||||||
entity->flags |= EntityFlag_Field;
|
entity->flags |= EntityFlag_Field;
|
||||||
entity->flags |= EntityFlag_ArrayElem;
|
entity->flags |= EntityFlag_ArrayElem;
|
||||||
entity->state = EntityState_Resolved;
|
entity->state = EntityState_Resolved;
|
||||||
|
|||||||
@@ -3259,7 +3259,7 @@ lbAddr lb_build_addr(lbProcedure *p, Ast *expr) {
|
|||||||
TypeAndValue tav = type_and_value_of_expr(elem);
|
TypeAndValue tav = type_and_value_of_expr(elem);
|
||||||
} else {
|
} else {
|
||||||
TypeAndValue tav = type_and_value_of_expr(elem);
|
TypeAndValue tav = type_and_value_of_expr(elem);
|
||||||
Selection sel = lookup_field_from_index(bt, st->fields[field_index]->Variable.field_src_index);
|
Selection sel = lookup_field_from_index(bt, st->fields[field_index]->Variable.field_index);
|
||||||
index = sel.index[0];
|
index = sel.index[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -807,6 +807,13 @@ lbValue lb_address_from_load(lbProcedure *p, lbValue value) {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
i32 lb_convert_struct_index(Type *t, i32 index) {
|
||||||
|
if (t->kind == Type_Struct && t->Struct.custom_align != 0) {
|
||||||
|
index += 1;
|
||||||
|
}
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
lbValue lb_emit_struct_ep(lbProcedure *p, lbValue s, i32 index) {
|
lbValue lb_emit_struct_ep(lbProcedure *p, lbValue s, i32 index) {
|
||||||
GB_ASSERT(is_type_pointer(s.type));
|
GB_ASSERT(is_type_pointer(s.type));
|
||||||
Type *t = base_type(type_deref(s.type));
|
Type *t = base_type(type_deref(s.type));
|
||||||
@@ -884,9 +891,8 @@ lbValue lb_emit_struct_ep(lbProcedure *p, lbValue s, i32 index) {
|
|||||||
|
|
||||||
GB_ASSERT_MSG(result_type != nullptr, "%s %d", type_to_string(t), index);
|
GB_ASSERT_MSG(result_type != nullptr, "%s %d", type_to_string(t), index);
|
||||||
|
|
||||||
if (t->kind == Type_Struct && t->Struct.custom_align != 0) {
|
index = lb_convert_struct_index(t, index);
|
||||||
index += 1;
|
|
||||||
}
|
|
||||||
if (lb_is_const(s)) {
|
if (lb_is_const(s)) {
|
||||||
lbModule *m = p->module;
|
lbModule *m = p->module;
|
||||||
lbValue res = {};
|
lbValue res = {};
|
||||||
@@ -1007,9 +1013,7 @@ lbValue lb_emit_struct_ev(lbProcedure *p, lbValue s, i32 index) {
|
|||||||
|
|
||||||
GB_ASSERT_MSG(result_type != nullptr, "%s, %d", type_to_string(s.type), index);
|
GB_ASSERT_MSG(result_type != nullptr, "%s, %d", type_to_string(s.type), index);
|
||||||
|
|
||||||
if (t->kind == Type_Struct && t->Struct.custom_align != 0) {
|
index = lb_convert_struct_index(t, index);
|
||||||
index += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
lbValue res = {};
|
lbValue res = {};
|
||||||
res.value = LLVMBuildExtractValue(p->builder, s.value, cast(unsigned)index, "");
|
res.value = LLVMBuildExtractValue(p->builder, s.value, cast(unsigned)index, "");
|
||||||
|
|||||||
+1
-1
@@ -2432,7 +2432,7 @@ Selection lookup_field_from_index(Type *type, i64 index) {
|
|||||||
for (isize i = 0; i < max_count; i++) {
|
for (isize i = 0; i < max_count; i++) {
|
||||||
Entity *f = type->Struct.fields[i];
|
Entity *f = type->Struct.fields[i];
|
||||||
if (f->kind == Entity_Variable) {
|
if (f->kind == Entity_Variable) {
|
||||||
if (f->Variable.field_src_index == index) {
|
if (f->Variable.field_index == index) {
|
||||||
auto sel_array = array_make<i32>(a, 1);
|
auto sel_array = array_make<i32>(a, 1);
|
||||||
sel_array[0] = cast(i32)i;
|
sel_array[0] = cast(i32)i;
|
||||||
return make_selection(f, sel_array, false);
|
return make_selection(f, sel_array, false);
|
||||||
|
|||||||
Reference in New Issue
Block a user