+ 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);
+}
+
+void
+set_array_entity_values(entity *ent, tarval **values, int num_vals) {
+ int i;
+ ir_graph *rem = current_ir_graph;
+ type *arrtp = get_entity_type(ent);
+ ir_node *val;
+ 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;
+}
+
+int get_compound_ent_value_offset_bits(entity *ent, int pos) {
+ compound_graph_path *path;
+ int i, path_len;
+ int offset = 0;
+
+ 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);
+
+ for (i = 0; i < path_len; ++i) {
+ entity *node = get_compound_graph_path_node(path, i);
+ type *node_tp = get_entity_type(node);
+ type *owner_tp = get_entity_owner(node);
+ if (is_Array_type(owner_tp)) {
+ int size = get_type_size_bits(node_tp);
+ int align = get_type_alignment_bits(node_tp);
+ if (size < align)
+ size = align;
+ else {
+ assert(size % align == 0);
+ /* ansonsten aufrunden */
+ }
+ offset += size * get_compound_graph_path_array_index(path, i);
+ } else {
+ offset += get_entity_offset_bits(node);
+ }
+ }
+ return offset;
+}
+
+int get_compound_ent_value_offset_bytes(entity *ent, int pos) {
+ int offset = get_compound_ent_value_offset_bits(ent, pos);
+ assert(offset % 8 == 0);
+ return offset >> 3;
+}
+
+
+static void init_index(type *arr) {
+ int init;
+ int dim = 0;
+
+ assert(get_array_n_dimensions(arr) == 1);
+
+ if (has_array_lower_bound(arr, dim))
+ init = get_array_lower_bound_int(arr, 0) -1;
+ else
+ init = get_array_upper_bound_int(arr, 0) +1;
+
+ set_entity_link(get_array_element_entity(arr), (void *)init);
+}
+
+
+static int get_next_index(entity *elem_ent) {
+ type *arr = get_entity_owner(elem_ent);
+ int next;
+ int dim = 0;
+
+ assert(get_array_n_dimensions(arr) == 1);
+
+ if (has_array_lower_bound(arr, dim)) {
+ next = (int)get_entity_link(elem_ent) +1;
+ if (has_array_upper_bound(arr, dim)) {
+ int upper = get_array_upper_bound_int(arr, dim);
+ if (next == upper) next = get_array_lower_bound_int(arr, dim);
+ }
+ } else {
+ next = (int)get_entity_link(elem_ent) -1;
+ if (has_array_lower_bound(arr, dim)) {
+ int upper = get_array_upper_bound_int(arr, dim);
+ if (next == upper) next = get_array_upper_bound_int(arr, dim);
+ }
+ }
+
+ set_entity_link(elem_ent, (void *)next);
+ return next;