- n = ARR_LEN(ent->attr.cmpd_attr.val_paths);
- for (i = 0; i < n; ++i) {
- compound_graph_path *path = ent->attr.cmpd_attr.val_paths[i];
- if (path->list[path->len-1].node == value_ent) {
- for (; i < n - 1; ++i) {
- ent->attr.cmpd_attr.val_paths[i] = ent->attr.cmpd_attr.val_paths[i+1];
- ent->attr.cmpd_attr.values[i] = ent->attr.cmpd_attr.values[i+1];
- }
- ARR_SETLEN(ir_entity*, ent->attr.cmpd_attr.val_paths, n - 1);
- ARR_SETLEN(ir_node*, ent->attr.cmpd_attr.values, n - 1);
- break;
- }
- }
-} /* remove_compound_ent_value */
-
-void
-add_compound_ent_value(ir_entity *ent, ir_node *val, ir_entity *member) {
- compound_graph_path *path;
- ir_type *owner_tp = get_entity_owner(member);
- assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
- path = new_compound_graph_path(get_entity_type(ent), 1);
- path->list[0].node = member;
- if (is_Array_type(owner_tp)) {
- int max;
- int i, n;
-
- assert(get_array_n_dimensions(owner_tp) == 1 && has_array_lower_bound(owner_tp, 0));
- max = get_array_lower_bound_int(owner_tp, 0) -1;
- for (i = 0, n = get_compound_ent_n_values(ent); i < n; ++i) {
- int index = get_compound_graph_path_array_index(get_compound_ent_value_path(ent, i), 0);
- if (index > max) {
- max = index;
- }
- }
- path->list[0].index = max + 1;
- }
- add_compound_ent_value_w_path(ent, val, path);
-} /* add_compound_ent_value */
-
-
-ir_entity *
-get_compound_ent_value_member(ir_entity *ent, int pos) {
- compound_graph_path *path;
- assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
- path = get_compound_ent_value_path(ent, pos);
-
- return get_compound_graph_path_node(path, get_compound_graph_path_length(path)-1);
-} /* get_compound_ent_value_member */
-
-void
-set_compound_ent_value(ir_entity *ent, ir_node *val, ir_entity *member, int pos) {
- compound_graph_path *path;
- assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
- path = get_compound_ent_value_path(ent, pos);
- set_compound_graph_path_node(path, 0, member);
- set_compound_ent_value_w_path(ent, val, path, pos);
-} /* set_compound_ent_value */
-
-void
-set_array_entity_values(ir_entity *ent, tarval **values, int num_vals) {
- int i;
- ir_graph *rem = current_ir_graph;
- ir_type *arrtp = get_entity_type(ent);
- ir_node *val;
- ir_type *elttp = get_array_element_type(arrtp);
-
- assert(is_Array_type(arrtp));
- assert(get_array_n_dimensions(arrtp) == 1);
- /* One bound is sufficient, the number of constant fields makes the
- size. */
- assert(get_array_lower_bound (arrtp, 0) || get_array_upper_bound (arrtp, 0));
- assert(get_entity_variability(ent) != variability_uninitialized);
- current_ir_graph = get_const_code_irg();
-
- for (i = 0; i < num_vals; i++) {
- val = new_Const_type(values[i], elttp);
- add_compound_ent_value(ent, val, get_array_element_entity(arrtp));
- set_compound_graph_path_array_index(get_compound_ent_value_path(ent, i), 0, i);
- }
- current_ir_graph = rem;
-} /* set_array_entity_values */
-
-/* Return the overall offset of value at position pos in bytes. */
-unsigned get_compound_ent_value_offset_bytes(ir_entity *ent, int pos) {
- compound_graph_path *path;
- int path_len, i;
- unsigned offset = 0;
- ir_type *curr_tp;
-
- assert(get_type_state(get_entity_type(ent)) == layout_fixed);
-
- path = get_compound_ent_value_path(ent, pos);
- path_len = get_compound_graph_path_length(path);
- curr_tp = path->tp;
-
- for (i = 0; i < path_len; ++i) {
- if (is_Array_type(curr_tp)) {
- ir_type *elem_type = get_array_element_type(curr_tp);
- unsigned size = get_type_size_bytes(elem_type);
- unsigned align = get_type_alignment_bytes(elem_type);
- int idx;
-
- assert(size > 0);
- if(size % align > 0) {
- size += align - (size % align);
- }
- idx = get_compound_graph_path_array_index(path, i);
- assert(idx >= 0);
- offset += size * idx;
- curr_tp = elem_type;
- } else {
- ir_entity *node = get_compound_graph_path_node(path, i);
- offset += get_entity_offset(node);
- curr_tp = get_entity_type(node);
- }