- */
-static void dump_size_type(size_t size) {
- switch (size) {
- case 1:
- be_emit_cstring("\t.byte\t");
- break;
-
- case 2:
- be_emit_cstring("\t.short\t");
- break;
-
- case 4:
- be_emit_cstring("\t.long\t");
- break;
-
- case 8:
- be_emit_cstring("\t.quad\t");
- break;
-
- case 10:
- case 12:
- case 16: /* Note: .octa does not work on mac */
- /* handled in arith */
- break;
-
- default:
- panic("Try to dump a type with %u bytes", (unsigned)size);
- }
-}
-
-/**
- * Emit an atomic value.
- *
- * @param env the gas output environment
- * @param init a node representing the atomic value (on the const code irg)
- */
-static void dump_atomic_init(be_gas_decl_env_t *env, ir_node *init)
-{
- ir_mode *mode = get_irn_mode(init);
- int bytes = get_mode_size_bytes(mode);
-
- dump_size_type(bytes);
- do_dump_atomic_init(env, init);
- be_emit_char('\n');
- be_emit_write_line();
-}
-
-/************************************************************************/
-/* Routines to dump global variables */
-/************************************************************************/
-
-static int initializer_is_string_const(const ir_initializer_t *initializer)
-{
- size_t i, len;
- int found_printable = 0;
-
- if (initializer->kind != IR_INITIALIZER_COMPOUND)
- return 0;
-
- len = initializer->compound.n_initializers;
- if (len < 1)
- return 0;
- for (i = 0; i < len; ++i) {
- int c;
- tarval *tv;
- ir_mode *mode;
- ir_initializer_t *sub_initializer
- = initializer->compound.initializers[i];
-
- if (sub_initializer->kind != IR_INITIALIZER_TARVAL)
- return 0;
-
- tv = sub_initializer->tarval.value;
- mode = get_tarval_mode(tv);
-
- if (!mode_is_int(mode) || get_mode_size_bits(mode) != 8)
- return 0;
-
- c = get_tarval_long(tv);
- if (isgraph(c) || isspace(c))
- found_printable = 1;
- else if (c != 0)
- return 0;
-
- if (i == len - 1 && c != '\0')
- return 0;
- }
-
- return found_printable;
-}
-
-/**
- * Determine if an entity is a string constant
- * @param ent The entity
- * @return 1 if it is a string constant, 0 otherwise
- */
-static int ent_is_string_const(const ir_entity *ent)
-{
- ir_type *type, *element_type;
- ir_mode *mode;
- int i, c, n;
-
- type = get_entity_type(ent);
-
- /* if it's an array */
- if (!is_Array_type(type))
- return 0;
-
- element_type = get_array_element_type(type);
-
- /* and the array's element type is primitive */
- if (!is_Primitive_type(element_type))
- return 0;
-
- /* and the mode of the element type is an int of
- * the same size as the byte mode */
- mode = get_type_mode(element_type);
- if (!mode_is_int(mode) || get_mode_size_bits(mode) != 8)
- return 0;
-
- if (ent->initializer != NULL) {
- return initializer_is_string_const(ent->initializer);
- } else if (entity_has_compound_ent_values(ent)) {
- int found_printable = 0;
- /* if it contains only printable chars and a 0 at the end */
- n = get_compound_ent_n_values(ent);
- for (i = 0; i < n; ++i) {
- ir_node *irn = get_compound_ent_value(ent, i);
- if (! is_Const(irn))
- return 0;
-
- c = (int) get_tarval_long(get_Const_tarval(irn));
-
- if (isgraph(c) || isspace(c))
- found_printable = 1;
- else if (c != 0)
- return 0;
-
- if (i == n - 1 && c != '\0')
- return 0;
- }
- return found_printable;
- }
-
- return 0;
-}
-
-static bool initializer_is_null(const ir_initializer_t *initializer)
-{
- switch (initializer->kind) {
- case IR_INITIALIZER_NULL:
- return true;
- case IR_INITIALIZER_TARVAL: {
- tarval *tv = initializer->tarval.value;
- return tarval_is_null(tv);
- }
- case IR_INITIALIZER_CONST: {
- ir_node *value = initializer->consti.value;
- if (!is_Const(value))
- return false;
- return is_Const_null(value);
- }
- case IR_INITIALIZER_COMPOUND: {
- size_t i;
- for (i = 0; i < initializer->compound.n_initializers; ++i) {
- ir_initializer_t *subinitializer
- = initializer->compound.initializers[i];
- if (!initializer_is_null(subinitializer))
- return false;
- }
- return true;
- }
- }
- panic("invalid initializer in initializer_is_null");
-}
-
-static bool entity_is_null(const ir_entity *entity)
-{
- if (entity->initializer != NULL) {
- return initializer_is_null(entity->initializer);
- } else if (entity_has_compound_ent_values(entity)) {
- /* I'm too lazy to implement this case as compound graph paths will be
- * remove anyway in the future */
- }
- /* uninitialized, NULL is fine */
- return true;
-}
-
-/**
- * Dump a string constant.
- * No checks are made!!
- *
- * @param ent The entity to dump.
- */
-static void dump_string_cst(const ir_entity *ent)
-{
- int i, len;
- int output_len;
- ir_type *type;
- int type_size;
- int remaining_space;
-
- len = get_compound_ent_n_values(ent);
- output_len = len;
- if (be_gas_object_file_format == OBJECT_FILE_FORMAT_MACH_O) {
- be_emit_cstring("\t.ascii \"");
- } else {
- be_emit_cstring("\t.string \"");
- output_len -= 1;
- }
-
- for (i = 0; i < output_len; ++i) {
- ir_node *irn;
- int c;
-
- irn = get_compound_ent_value(ent, i);
- c = (int) get_tarval_long(get_Const_tarval(irn));
-
- switch (c) {
- case '"' : be_emit_cstring("\\\""); break;
- case '\n': be_emit_cstring("\\n"); break;
- case '\r': be_emit_cstring("\\r"); break;
- case '\t': be_emit_cstring("\\t"); break;
- case '\\': be_emit_cstring("\\\\"); break;
- default :
- if (isprint(c))
- be_emit_char(c);
- else
- be_emit_irprintf("\\%o", c);
- break;
- }
- }
- be_emit_cstring("\"\n");
- be_emit_write_line();