+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);
+ }
+ }
+
+ return offset;
+} /* get_compound_ent_value_offset_bytes */
+
+/* Return the offset in bits from the last byte address. */
+unsigned get_compound_ent_value_offset_bit_remainder(ir_entity *ent, int pos) {
+ compound_graph_path *path;
+ int path_len;
+ ir_entity *last_node;
+
+ 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);
+ last_node = get_compound_graph_path_node(path, path_len - 1);
+
+ if(last_node == NULL)
+ return 0;
+
+ return get_entity_offset_bits_remainder(last_node);
+} /* get_compound_ent_value_offset_bit_remainder */