- type *ty = get_entity_type(ent);
- const char *ld_name = get_entity_ld_name(ent);
- int align, h;
- struct obstack *obst = data_obstack;
-
- /*
- * FIXME: did NOT work for partly constant values
- */
- if (! is_Method_type(ty)) {
- ent_variability variability = get_entity_variability(ent);
- visibility visibility = get_entity_visibility(ent);
-
- if (variability == variability_constant) {
- /* a constant entity, put it on the rdata */
- obst = rdata_obstack;
- }
-
- /* check, wether it is initialized, if yes create data */
- if (variability != variability_uninitialized) {
- if (visibility == visibility_external_visible) {
- obstack_printf(obst, ".globl\t%s\n", ld_name);
- }
- obstack_printf(obst, "\t.type\t%s,@object\n", ld_name);
- obstack_printf(obst, "\t.size\t%s,%d\n", ld_name, (get_type_size_bits(ty) + 7) >> 3);
-
- align = get_type_alignment_bytes(ty);
- ia32_dump_align(obst, align);
-
- obstack_printf(obst, "%s:\n", ld_name);
-
- if (is_atomic_type(ty)) {
- if (get_entity_visibility(ent) != visibility_external_allocated)
- dump_atomic_init(obst, get_atomic_ent_value(ent));
- }
- else {
- int i, size = 0;
-
- if (ent_is_string_const(ent)) {
- dump_string_cst(obst, ent);
- }
- else if (is_Array_type(ty)) {
- int filler;
-
- /* potential spare values should be already included! */
- for (i = 0; i < get_compound_ent_n_values(ent); ++i) {
- entity *step = get_compound_ent_value_member(ent, i);
- type *stype = get_entity_type(step);
-
- if (get_type_mode(stype)) {
- int align = (get_type_alignment_bits(stype) + 7) >> 3;
- int n = size % align;
-
- if (n > 0) {
- obstack_printf(obst, "\t.zero\t%d\n", align - n);
- size += align - n;
- }
- }
- dump_atomic_init(obst, get_compound_ent_value(ent, i));
- size += get_type_size_bytes(stype);
- }
- filler = get_type_size_bytes(ty) - size;
-
- if (filler > 0)
- obstack_printf(obst, "\t.zero\t%d\n", filler);
- }
- else if (is_compound_type(ty)) {
- ir_node **vals;
- int type_size, j;
-
- /* Compound entities are NOT sorted.
- * The sorting strategy used doesn't work for `value' compound fields nor
- * for partially_constant entities.
- */
-
- /*
- * in the worst case, every entity allocates one byte, so the type
- * size should be equal or bigger the number of fields
- */
- type_size = get_type_size_bytes(ty);
- vals = calloc(type_size, sizeof(*vals));
-
- /* collect the values and store them at the offsets */
- for(i = 0; i < get_compound_ent_n_values(ent); ++i) {
- int graph_length, aipos, offset;
- struct arr_info *ai;
- int all_n = 1;
- compound_graph_path *path = get_compound_ent_value_path(ent, i);
-
- /* get the access path to the costant value */
- graph_length = get_compound_graph_path_length(path);
- ai = calloc(graph_length, sizeof(struct arr_info));
-
- /* We wanna know how many arrays are on the path to the entity. We also have to know how
- * many elements each array holds to calculate the offset for the entity. */
- for (j = 0; j < graph_length; j++) {
- entity *step = get_compound_graph_path_node(path, j);
- type *step_type = get_entity_type(step);
- int ty_size = (get_type_size_bits(step_type) + 7) >> 3;
- int k, n = 0;
-
- if (is_Array_type(step_type))
- for (k = 0; k < get_array_n_dimensions(step_type); k++)
- n += get_tarval_long(get_Const_tarval(get_array_upper_bound(step_type, k)));
- if (n) all_n *= n;
- ai[j].n_elems = n ? all_n + 1 : 0;
- ai[j].visit_cnt = 0;
- ai[j].size = ty_size;
- }
-
- aipos = graph_length - 1;
- if (aipos) aipos--;
-
- for (offset = j = 0; j < graph_length; j++) {
- entity *step = get_compound_graph_path_node(path, j);
- type *step_type = get_entity_type(step);
- int ent_ofs = get_entity_offset_bytes(step);
- int stepsize = 0;
-
- /* add all positive offsets (= offsets in structs) */
- if (ent_ofs >= 0) offset += ent_ofs;
-
- if (j == graph_length - 1) {
- stepsize = (get_type_size_bits(step_type) + 7) >> 3;
-
- /* Search the next free position in vals depending on the information from above (ai). */
- while (vals[offset]) {
- if (ai[aipos].visit_cnt < ai[aipos].n_elems) {
- offset += stepsize;
- ai[aipos].visit_cnt++;
- }
- else
- while (aipos >= 0 && ai[aipos].visit_cnt == ai[aipos].n_elems) {
- stepsize = ai[aipos--].size;
- offset += stepsize;
- }
- }
-
- assert(aipos >= 0 && "couldn't store entity");
- vals[offset] = get_compound_ent_value(ent, i);
- }
- }
-
- free(ai);
- }
-
- /* now write them sorted */
- for(i = 0; i < type_size; ) {
- if (vals[i]) {
- dump_atomic_init(obst, vals[i]);
- i += (get_mode_size_bytes(get_irn_mode(vals[i])));
- }
- else {
- /* a gap */
- obstack_printf(obst, "\t.byte\t0\n");
- ++i;
- }
- }
- free(vals);
- }
- else {
- assert(0 && "unsupported type");
- }
- }
- obstack_printf(obst, "\n");
- }
- else if (visibility != visibility_external_allocated) {
- if (visibility == visibility_local) {
- obstack_printf(comm_obstack, "\t.local\t%s\n", ld_name);
- }
-
- /* calculate the alignment */
- align = get_type_alignment_bytes(ty);
- h = highest_bit(align);
-
- if ((1 << h) < align)
- ++h;
- align = (1 << h);
-
- if (align < 1)
- align = 1;
-
- obstack_printf(comm_obstack, "\t.comm\t%s,%d,%d\n", ld_name, (get_type_size_bits(ty) + 7) >> 3, align);
- }
- }
+ ir_type *ty = get_entity_type(ent);
+ const char *ld_name = get_entity_ld_name(ent);
+ obstack_t *obst = data_obstack;
+ int align, h;
+
+ /*
+ * FIXME: did NOT work for partly constant values
+ */
+ if (! is_Method_type(ty)) {
+ ir_variability variability = get_entity_variability(ent);
+ ir_visibility visibility = get_entity_visibility(ent);
+
+ if (variability == variability_constant) {
+ /* a constant entity, put it on the rdata */
+ obst = rdata_obstack;
+ }
+
+ /* check, whether it is initialized, if yes create data */
+ if (variability != variability_uninitialized) {
+ be_dbg_variable(main_env->db_handle, obst, ent);
+
+ if (visibility == visibility_external_visible) {
+ obstack_printf(obst, ".globl\t%s\n", ld_name);
+ }
+ dump_object_size(obst, ld_name, get_type_size_bytes(ty));
+
+ align = get_type_alignment_bytes(ty);
+ ia32_dump_align(obst, align);
+
+ obstack_printf(obst, "%s:\n", ld_name);
+
+ if (is_atomic_type(ty)) {
+ if (get_entity_visibility(ent) != visibility_external_allocated)
+ dump_atomic_init(obst, get_atomic_ent_value(ent));
+ }
+ else {
+ int i, size = 0;
+
+ if (ent_is_string_const(ent)) {
+ dump_string_cst(obst, ent);
+ }
+ else if (is_Array_type(ty)) {
+ int filler;
+
+ /* potential spare values should be already included! */
+ for (i = 0; i < get_compound_ent_n_values(ent); ++i) {
+ entity *step = get_compound_ent_value_member(ent, i);
+ ir_type *stype = get_entity_type(step);
+
+ if (get_type_mode(stype)) {
+ int align = (get_type_alignment_bits(stype) + 7) >> 3;
+ int n = size % align;
+
+ if (n > 0) {
+ obstack_printf(obst, "\t.zero\t%d\n", align - n);
+ size += align - n;
+ }
+ }
+ dump_atomic_init(obst, get_compound_ent_value(ent, i));
+ size += get_type_size_bytes(stype);
+ }
+ filler = get_type_size_bytes(ty) - size;
+
+ if (filler > 0)
+ obstack_printf(obst, "\t.zero\t%d\n", filler);
+ }
+ else if (is_compound_type(ty)) {
+ ir_node **vals;
+ int type_size, j;
+
+ /* Compound entities are NOT sorted.
+ * The sorting strategy used doesn't work for `value' compound fields nor
+ * for partially_constant entities.
+ */
+
+ /*
+ * in the worst case, every entity allocates one byte, so the type
+ * size should be equal or bigger the number of fields
+ */
+ type_size = get_type_size_bytes(ty);
+ vals = xcalloc(type_size, sizeof(*vals));
+
+ /* collect the values and store them at the offsets */
+ for(i = 0; i < get_compound_ent_n_values(ent); ++i) {
+ int graph_length, aipos, offset;
+ struct arr_info *ai;
+ int all_n = 1;
+ compound_graph_path *path = get_compound_ent_value_path(ent, i);
+
+ /* get the access path to the costant value */
+ graph_length = get_compound_graph_path_length(path);
+ ai = xcalloc(graph_length, sizeof(struct arr_info));
+
+ /* We wanna know how many arrays are on the path to the entity. We also have to know how
+ * many elements each array holds to calculate the offset for the entity. */
+ for (j = 0; j < graph_length; j++) {
+ entity *step = get_compound_graph_path_node(path, j);
+ ir_type *step_type = get_entity_type(step);
+ int ty_size = (get_type_size_bits(step_type) + 7) >> 3;
+ int k, n = 0;
+
+ if (is_Array_type(step_type))
+ for (k = 0; k < get_array_n_dimensions(step_type); k++)
+ n += get_tarval_long(get_Const_tarval(get_array_upper_bound(step_type, k)));
+ if (n) all_n *= n;
+ ai[j].n_elems = n ? all_n + 1 : 0;
+ ai[j].visit_cnt = 0;
+ ai[j].size = ty_size;
+ }
+
+ aipos = graph_length - 1;
+ if (aipos) aipos--;
+
+ for (offset = j = 0; j < graph_length; j++) {
+ entity *step = get_compound_graph_path_node(path, j);
+ ir_type *step_type = get_entity_type(step);
+ int ent_ofs = get_entity_offset_bytes(step);
+ int stepsize = 0;
+
+ /* add all positive offsets (= offsets in structs) */
+ if (ent_ofs >= 0) offset += ent_ofs;
+
+ if (j == graph_length - 1) {
+ stepsize = (get_type_size_bits(step_type) + 7) >> 3;
+
+ /* Search the next free position in vals depending on the information from above (ai). */
+ while (vals[offset] && aipos >= 0) {
+ if (ai[aipos].visit_cnt < ai[aipos].n_elems) {
+ offset += stepsize;
+ ai[aipos].visit_cnt++;
+ }
+ else
+ while (aipos >= 0 && ai[aipos].visit_cnt == ai[aipos].n_elems) {
+ stepsize = ai[aipos--].size;
+ offset += stepsize;
+ }
+ }
+
+ assert(aipos >= 0 && "couldn't store entity");
+ vals[offset] = get_compound_ent_value(ent, i);
+ }
+ }
+
+ free(ai);
+ }
+
+ /* now write them sorted */
+ for(i = 0; i < type_size; ) {
+ if (vals[i]) {
+ dump_atomic_init(obst, vals[i]);
+ i += (get_mode_size_bytes(get_irn_mode(vals[i])));
+ }
+ else {
+ /* a gap */
+ obstack_printf(obst, "\t.byte\t0\n");
+ ++i;
+ }
+ }
+ free(vals);
+ }
+ else {
+ assert(0 && "unsupported type");
+ }
+ }
+ obstack_printf(obst, "\n");
+ }
+ else if (visibility != visibility_external_allocated) {
+ be_dbg_variable(main_env->db_handle, comm_obstack, ent);
+
+ /* uninitialized and NOT external */
+ if (get_entity_owner(ent) != get_tls_type()) {
+ /* calculate the alignment */
+ align = get_type_alignment_bytes(ty);
+ h = highest_bit(align);
+
+ if ((1 << h) < align)
+ ++h;
+ align = (1 << h);
+
+ if (align < 1)
+ align = 1;
+
+ ia32_dump_comm(comm_obstack, ld_name, visibility,
+ get_type_size_bytes(ty), align);
+ } else {
+ /* TLS */
+ if (visibility == visibility_external_visible) {
+ obstack_printf(comm_obstack, ".globl\t%s\n", ld_name);
+ }
+ dump_object_size(comm_obstack, ld_name, get_type_size_bytes(ty));
+ align = get_type_alignment_bytes(ty);
+ ia32_dump_align(comm_obstack, align);
+ obstack_printf(comm_obstack, "%s:\n\t.zero %d\n", ld_name, get_type_size_bytes(ty));
+ }
+ }
+ } /* ! is method type */
+ else if (ctor_obstack && get_method_img_section(ent) == section_constructors) {
+ ia32_dump_align(ctor_obstack, get_type_alignment_bytes(ty));
+ dump_size_type(ctor_obstack, get_type_alignment_bytes(ty));
+ obstack_printf(ctor_obstack, "%s\n", ld_name);
+ }