2 * Copyright (C) 1995-2011 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * @brief Dumps global variables and constants as gas assembler.
23 * @author Christian Wuerdig, Matthias Braun
45 #include "beemitter.h"
48 /** by default, we generate assembler code for the Linux gas */
49 object_file_format_t be_gas_object_file_format = OBJECT_FILE_FORMAT_ELF;
50 elf_variant_t be_gas_elf_variant = ELF_VARIANT_NORMAL;
51 bool be_gas_emit_types = true;
52 char be_gas_elf_type_char = '@';
54 static be_gas_section_t current_section = (be_gas_section_t) -1;
55 static pmap *block_numbers;
56 static unsigned next_block_nr;
59 * An environment containing all needed dumper data.
60 * Currently we create the file completely in memory first, then
61 * write it to the disk. This is an artifact from the old C-generating backend
62 * and even there NOT needed. So we might change it in the future.
64 typedef struct be_gas_decl_env {
65 be_gas_section_t section;
66 const be_main_env_t *main_env;
69 static void emit_section_macho(be_gas_section_t section)
71 be_gas_section_t base = section & GAS_SECTION_TYPE_MASK;
72 be_gas_section_t flags = section & ~GAS_SECTION_TYPE_MASK;
75 if (current_section == section)
77 current_section = section;
82 case GAS_SECTION_TEXT: name = "text"; break;
83 case GAS_SECTION_DATA: name = "data"; break;
84 case GAS_SECTION_RODATA: name = "const"; break;
85 case GAS_SECTION_BSS: name = "data"; break;
86 case GAS_SECTION_CONSTRUCTORS: name = "mod_init_func"; break;
87 case GAS_SECTION_DESTRUCTORS: name = "mod_term_func"; break;
88 case GAS_SECTION_PIC_TRAMPOLINES: name = "section\t__IMPORT,__jump_table,symbol_stubs,self_modifying_code+pure_instructions,5"; break;
89 case GAS_SECTION_PIC_SYMBOLS: name = "section\t__IMPORT,__pointers,non_lazy_symbol_pointers"; break;
90 case GAS_SECTION_CSTRING: name = "cstring"; break;
91 case GAS_SECTION_DEBUG_INFO: name = "section __DWARF,__debug_info,regular,debug"; break;
92 case GAS_SECTION_DEBUG_ABBREV: name = "section __DWARF,__debug_abbrev,regular,debug"; break;
93 case GAS_SECTION_DEBUG_LINE: name = "section __DWARF,__debug_line,regular,debug"; break;
94 case GAS_SECTION_DEBUG_PUBNAMES: name = "section __DWARF,__debug_pubnames,regular,debug"; break;
95 case GAS_SECTION_DEBUG_FRAME: name = "section __DWARF,__debug_frame,regular,debug"; break;
96 default: panic("unsupported scetion type 0x%X", section);
98 be_emit_irprintf("\t.%s\n", name);
100 } else if (flags & GAS_SECTION_FLAG_COMDAT) {
102 case GAS_SECTION_TEXT: name = "section __TEXT,__textcoal_nt,coalesced,pure_instructions"; break;
103 case GAS_SECTION_BSS:
104 case GAS_SECTION_DATA: name = "section __DATA,__datacoal_nt,coalesced"; break;
105 case GAS_SECTION_RODATA: name = "section __TEXT,__const_coal,coalesced"; break;
106 case GAS_SECTION_CSTRING: name = "section __TEXT,__const_coal,coalesced"; break;
107 default: panic("unsupported scetion type 0x%X", section);
109 } else if (flags & GAS_SECTION_FLAG_TLS) {
110 panic("thread local storage not supported on macho (section 0x%X)", section);
112 panic("unsupported section type 0x%X", section);
116 static void emit_section_sparc(be_gas_section_t section, const ir_entity *entity)
118 be_gas_section_t base = section & GAS_SECTION_TYPE_MASK;
119 be_gas_section_t flags = section & ~GAS_SECTION_TYPE_MASK;
120 static const char *const basename[GAS_SECTION_LAST+1] = {
128 NULL, /* pic trampolines */
129 NULL, /* pic symbols */
137 if (current_section == section && !(section & GAS_SECTION_FLAG_COMDAT))
139 current_section = section;
141 be_emit_cstring("\t.section\t\".");
143 /* Part1: section-name */
144 if (flags & GAS_SECTION_FLAG_TLS)
146 assert(base < (be_gas_section_t)ARRAY_SIZE(basename));
147 be_emit_string(basename[base]);
149 if (flags & GAS_SECTION_FLAG_COMDAT) {
151 be_gas_emit_entity(entity);
155 /* for the simple sections we're done here */
159 be_emit_cstring(",#alloc");
162 case GAS_SECTION_TEXT: be_emit_cstring(",#execinstr"); break;
163 case GAS_SECTION_DATA:
164 case GAS_SECTION_BSS: be_emit_cstring(",#write"); break;
169 if (flags & GAS_SECTION_FLAG_TLS) {
170 be_emit_cstring(",#tls");
175 be_emit_write_line();
178 static void emit_section(be_gas_section_t section, const ir_entity *entity)
180 be_gas_section_t base = section & GAS_SECTION_TYPE_MASK;
181 be_gas_section_t flags = section & ~GAS_SECTION_TYPE_MASK;
183 static const struct {
187 } sectioninfos[GAS_SECTION_LAST+1] = {
188 { "text", "progbits", "ax" },
189 { "data", "progbits", "aw" },
190 { "rodata", "progbits", "a" },
191 { "bss", "nobits", "aw" },
192 { "ctors", "progbits", "aw" },
193 { "dtors", "progbits", "aw" },
194 { NULL, NULL, NULL }, /* cstring */
195 { NULL, NULL, NULL }, /* pic trampolines */
196 { NULL, NULL, NULL }, /* pic symbols */
197 { "debug_info", "progbits", "" },
198 { "debug_abbrev", "progbits", "" },
199 { "debug_line", "progbits", "" },
200 { "debug_pubnames", "progbits", "" },
201 { "debug_frame", "progbits", "" },
204 if (be_gas_object_file_format == OBJECT_FILE_FORMAT_MACH_O) {
205 emit_section_macho(section);
207 } else if(be_gas_elf_variant == ELF_VARIANT_SPARC) {
208 emit_section_sparc(section, entity);
212 if (current_section == section && !(section & GAS_SECTION_FLAG_COMDAT))
214 current_section = section;
219 case GAS_SECTION_TEXT:
220 be_emit_cstring("\t.text\n");
221 be_emit_write_line();
223 case GAS_SECTION_DATA:
224 be_emit_cstring("\t.data\n");
225 be_emit_write_line();
227 case GAS_SECTION_RODATA:
228 be_emit_cstring("\t.section\t.rodata\n");
229 be_emit_write_line();
231 case GAS_SECTION_BSS:
232 be_emit_cstring("\t.bss\n");
233 be_emit_write_line();
240 assert(base < (be_gas_section_t) ARRAY_SIZE(sectioninfos));
241 be_emit_cstring("\t.section\t.");
243 if (flags & GAS_SECTION_FLAG_TLS)
245 be_emit_string(sectioninfos[base].name);
246 if (flags & GAS_SECTION_FLAG_COMDAT) {
248 be_gas_emit_entity(entity);
252 be_emit_cstring(",\"");
253 for (f = sectioninfos[base].flags; *f != '\0'; ++f) {
256 if (flags & GAS_SECTION_FLAG_TLS)
258 if (flags & GAS_SECTION_FLAG_COMDAT)
262 if (be_gas_object_file_format != OBJECT_FILE_FORMAT_COFF) {
263 be_emit_cstring("\",");
264 be_emit_char(be_gas_elf_type_char);
265 be_emit_string(sectioninfos[base].type);
268 if (flags & GAS_SECTION_FLAG_COMDAT) {
270 be_gas_emit_entity(entity);
271 be_emit_cstring(",comdat");
274 be_emit_write_line();
279 void be_gas_emit_switch_section(be_gas_section_t section)
281 /* you have to produce a switch_section call with entity manually
282 * for comdat sections */
283 assert( !(section & GAS_SECTION_FLAG_COMDAT));
285 emit_section(section, NULL);
288 static ir_tarval *get_initializer_tarval(const ir_initializer_t *initializer)
290 if (initializer->kind == IR_INITIALIZER_TARVAL)
291 return initializer->tarval.value;
292 if (initializer->kind == IR_INITIALIZER_CONST) {
293 ir_node *node = initializer->consti.value;
294 if (is_Const(node)) {
295 return get_Const_tarval(node);
298 return get_tarval_undefined();
301 static bool initializer_is_string_const(const ir_initializer_t *initializer)
304 bool found_printable = false;
306 if (initializer->kind != IR_INITIALIZER_COMPOUND)
309 len = initializer->compound.n_initializers;
312 for (i = 0; i < len; ++i) {
316 ir_initializer_t *sub_initializer
317 = initializer->compound.initializers[i];
319 tv = get_initializer_tarval(sub_initializer);
320 if (!tarval_is_constant(tv))
323 mode = get_tarval_mode(tv);
324 if (!mode_is_int(mode) || get_mode_size_bits(mode) != 8)
327 c = get_tarval_long(tv);
328 if (isgraph(c) || isspace(c))
329 found_printable = true;
333 if (i == len - 1 && c != '\0')
337 return found_printable;
340 static bool initializer_is_null(const ir_initializer_t *initializer)
342 switch (initializer->kind) {
343 case IR_INITIALIZER_NULL:
345 case IR_INITIALIZER_TARVAL: {
346 ir_tarval *tv = initializer->tarval.value;
347 return tarval_is_null(tv);
349 case IR_INITIALIZER_CONST: {
350 ir_node *value = initializer->consti.value;
351 if (!is_Const(value))
353 return is_Const_null(value);
355 case IR_INITIALIZER_COMPOUND: {
357 for (i = 0; i < initializer->compound.n_initializers; ++i) {
358 ir_initializer_t *subinitializer
359 = initializer->compound.initializers[i];
360 if (!initializer_is_null(subinitializer))
366 panic("invalid initializer in initializer_is_null");
370 * Determine if an entity is a string constant
371 * @param ent The entity
372 * @return 1 if it is a string constant, 0 otherwise
374 static int entity_is_string_const(const ir_entity *ent)
376 ir_type *type, *element_type;
379 type = get_entity_type(ent);
381 /* if it's an array */
382 if (!is_Array_type(type))
385 element_type = get_array_element_type(type);
387 /* and the array's element type is primitive */
388 if (!is_Primitive_type(element_type))
391 /* and the mode of the element type is an int of
392 * the same size as the byte mode */
393 mode = get_type_mode(element_type);
394 if (!mode_is_int(mode) || get_mode_size_bits(mode) != 8)
397 if (ent->initializer != NULL) {
398 return initializer_is_string_const(ent->initializer);
404 static bool entity_is_null(const ir_entity *entity)
406 ir_initializer_t *initializer = get_entity_initializer(entity);
407 return initializer == NULL || initializer_is_null(initializer);
410 static bool is_comdat(const ir_entity *entity)
412 ir_linkage linkage = get_entity_linkage(entity);
413 return (linkage & IR_LINKAGE_MERGE)
414 && (linkage & IR_LINKAGE_GARBAGE_COLLECT);
417 static be_gas_section_t determine_basic_section(const ir_entity *entity)
421 if (is_method_entity(entity))
422 return GAS_SECTION_TEXT;
424 linkage = get_entity_linkage(entity);
425 if (linkage & IR_LINKAGE_CONSTANT) {
426 /* mach-o is the only one with a cstring section */
427 if (be_gas_object_file_format == OBJECT_FILE_FORMAT_MACH_O
428 && entity_is_string_const(entity))
429 return GAS_SECTION_CSTRING;
431 return GAS_SECTION_RODATA;
433 if (entity_is_null(entity))
434 return GAS_SECTION_BSS;
436 return GAS_SECTION_DATA;
439 static be_gas_section_t determine_section(be_gas_decl_env_t *env,
440 const ir_entity *entity)
442 ir_type *owner = get_entity_owner(entity);
444 if (owner == get_segment_type(IR_SEGMENT_GLOBAL)) {
445 be_gas_section_t section = determine_basic_section(entity);
446 if (is_comdat(entity))
447 section |= GAS_SECTION_FLAG_COMDAT;
449 } else if (env != NULL && owner == env->main_env->pic_symbols_type) {
450 return GAS_SECTION_PIC_SYMBOLS;
451 } else if (env != NULL && owner == env->main_env->pic_trampolines_type) {
452 return GAS_SECTION_PIC_TRAMPOLINES;
453 } else if (owner == get_segment_type(IR_SEGMENT_CONSTRUCTORS)) {
454 return GAS_SECTION_CONSTRUCTORS;
455 } else if (owner == get_segment_type(IR_SEGMENT_DESTRUCTORS)) {
456 return GAS_SECTION_DESTRUCTORS;
457 } else if (owner == get_segment_type(IR_SEGMENT_THREAD_LOCAL)) {
458 be_gas_section_t section = determine_basic_section(entity);
459 if (is_comdat(entity))
460 section |= GAS_SECTION_FLAG_COMDAT;
462 return section | GAS_SECTION_FLAG_TLS;
465 /* the java frontend keeps some functions inside classes */
466 if (is_Class_type(owner)) {
467 return determine_basic_section(entity);
470 panic("Couldn't determine section for %+F?!?", entity);
473 static void emit_weak(const ir_entity *entity)
475 if (be_gas_object_file_format == OBJECT_FILE_FORMAT_MACH_O) {
476 be_emit_cstring("\t.weak_reference ");
478 be_emit_cstring("\t.weak ");
480 be_gas_emit_entity(entity);
482 be_emit_write_line();
485 static void emit_visibility(const ir_entity *entity)
487 ir_linkage const linkage = get_entity_linkage(entity);
489 if (linkage & IR_LINKAGE_WEAK) {
491 /* Note: .weak seems to imply .globl so no need to output .globl */
492 } else if (get_entity_visibility(entity) == ir_visibility_external
493 && entity_has_definition(entity)) {
494 be_emit_cstring("\t.globl ");
495 be_gas_emit_entity(entity);
497 be_emit_write_line();
500 if (be_gas_object_file_format == OBJECT_FILE_FORMAT_MACH_O
501 && (linkage & IR_LINKAGE_HIDDEN_USER)
502 && get_entity_ld_name(entity)[0] != '\0') {
503 be_emit_cstring("\t.no_dead_strip ");
504 be_gas_emit_entity(entity);
506 be_emit_write_line();
510 void be_gas_emit_function_prolog(const ir_entity *entity, unsigned po2alignment, const parameter_dbg_info_t *parameter_infos)
512 be_gas_section_t section;
514 be_dwarf_method_before(entity, parameter_infos);
516 section = determine_section(NULL, entity);
517 emit_section(section, entity);
519 /* write the begin line (makes the life easier for scripts parsing the
521 if (be_options.verbose_asm) {
522 be_emit_cstring("# -- Begin ");
523 be_gas_emit_entity(entity);
525 be_emit_write_line();
528 if (po2alignment > 0) {
529 const char *fill_byte = "";
530 unsigned maximum_skip = (1 << po2alignment) - 1;
531 /* gcc fills space between function with 0x90... */
532 if (be_gas_object_file_format == OBJECT_FILE_FORMAT_MACH_O) {
535 be_emit_cstring("\t.p2align ");
536 be_emit_irprintf("%u,%s,%u\n", po2alignment, fill_byte, maximum_skip);
537 be_emit_write_line();
539 emit_visibility(entity);
541 switch (be_gas_object_file_format) {
542 case OBJECT_FILE_FORMAT_ELF:
543 be_emit_cstring("\t.type\t");
544 be_gas_emit_entity(entity);
545 be_emit_cstring(", ");
546 be_emit_char(be_gas_elf_type_char);
547 be_emit_cstring("function\n");
548 be_emit_write_line();
550 case OBJECT_FILE_FORMAT_COFF:
551 be_emit_cstring("\t.def\t");
552 be_gas_emit_entity(entity);
553 be_emit_cstring(";");
554 if (get_entity_visibility(entity) == ir_visibility_local) {
555 be_emit_cstring("\t.scl\t3;");
557 be_emit_cstring("\t.scl\t2;");
559 be_emit_cstring("\t.type\t32;\t.endef\n");
560 be_emit_write_line();
562 case OBJECT_FILE_FORMAT_MACH_O:
565 be_gas_emit_entity(entity);
566 be_emit_cstring(":\n");
567 be_emit_write_line();
569 be_dwarf_method_begin();
572 void be_gas_emit_function_epilog(const ir_entity *entity)
574 be_dwarf_method_end();
576 if (be_gas_object_file_format == OBJECT_FILE_FORMAT_ELF) {
577 be_emit_cstring("\t.size\t");
578 be_gas_emit_entity(entity);
579 be_emit_cstring(", .-");
580 be_gas_emit_entity(entity);
582 be_emit_write_line();
585 if (be_options.verbose_asm) {
586 be_emit_cstring("# -- End ");
587 be_gas_emit_entity(entity);
589 be_emit_write_line();
593 be_emit_write_line();
599 * @param tv the tarval
600 * @param bytes the width of the tarvals value in bytes
602 static void emit_arith_tarval(ir_tarval *tv, unsigned bytes)
606 be_emit_irprintf("0x%02x", get_tarval_sub_bits(tv, 0));
610 be_emit_irprintf("0x%02x%02x",
611 get_tarval_sub_bits(tv, 1), get_tarval_sub_bits(tv, 0));
615 be_emit_irprintf("0x%02x%02x%02x%02x",
616 get_tarval_sub_bits(tv, 3), get_tarval_sub_bits(tv, 2),
617 get_tarval_sub_bits(tv, 1), get_tarval_sub_bits(tv, 0));
621 be_emit_irprintf("0x%02x%02x%02x%02x%02x%02x%02x%02x",
622 get_tarval_sub_bits(tv, 7), get_tarval_sub_bits(tv, 6),
623 get_tarval_sub_bits(tv, 5), get_tarval_sub_bits(tv, 4),
624 get_tarval_sub_bits(tv, 3), get_tarval_sub_bits(tv, 2),
625 get_tarval_sub_bits(tv, 1), get_tarval_sub_bits(tv, 0));
629 panic("Can't dump a tarval with %d bytes", bytes);
633 * Return the label prefix for labeled instructions.
635 const char *be_gas_insn_label_prefix(void)
641 * Dump an atomic value.
643 * @param env the gas output environment
644 * @param init a node representing the atomic value (on the const code irg)
646 static void emit_init_expression(be_gas_decl_env_t *env, ir_node *init)
648 ir_mode *mode = get_irn_mode(init);
649 int bytes = get_mode_size_bytes(mode);
653 init = skip_Id(init);
655 switch (get_irn_opcode(init)) {
657 emit_init_expression(env, get_Cast_op(init));
661 emit_init_expression(env, get_Conv_op(init));
665 tv = get_Const_tarval(init);
667 /* it's an arithmetic value */
668 emit_arith_tarval(tv, bytes);
672 switch (get_SymConst_kind(init)) {
673 case symconst_addr_ent:
674 ent = get_SymConst_entity(init);
675 be_gas_emit_entity(ent);
678 case symconst_ofs_ent:
679 ent = get_SymConst_entity(init);
680 be_emit_irprintf("%d", get_entity_offset(ent));
683 case symconst_type_size:
684 be_emit_irprintf("%u", get_type_size_bytes(get_SymConst_type(init)));
687 case symconst_type_align:
688 be_emit_irprintf("%u", get_type_alignment_bytes(get_SymConst_type(init)));
691 case symconst_enum_const:
692 tv = get_enumeration_value(get_SymConst_enum(init));
693 emit_arith_tarval(tv, bytes);
697 assert(!"emit_atomic_init(): don't know how to init from this SymConst");
702 if (!mode_is_int(mode) && !mode_is_reference(mode)) {
703 panic("Constant must be int or pointer for '+' to work");
705 emit_init_expression(env, get_Add_left(init));
706 be_emit_cstring(" + ");
707 emit_init_expression(env, get_Add_right(init));
711 if (!mode_is_int(mode) && !mode_is_reference(mode)) {
712 panic("Constant must be int or pointer for '-' to work");
714 emit_init_expression(env, get_Sub_left(init));
715 be_emit_cstring(" - ");
716 emit_init_expression(env, get_Sub_right(init));
720 if (!mode_is_int(mode) && !mode_is_reference(mode)) {
721 panic("Constant must be int or pointer for '*' to work");
723 emit_init_expression(env, get_Mul_left(init));
724 be_emit_cstring(" * ");
725 emit_init_expression(env, get_Mul_right(init));
729 be_emit_cstring("0");
733 panic("emit_atomic_init(): unsupported IR-node %+F", init);
738 * Dumps the type for given size (.byte, .long, ...)
740 * @param size the size in bytes
742 static void emit_size_type(size_t size)
745 case 1: be_emit_cstring("\t.byte\t"); break;
746 case 2: be_emit_cstring("\t.short\t"); break;
747 case 4: be_emit_cstring("\t.long\t"); break;
748 case 8: be_emit_cstring("\t.quad\t"); break;
751 panic("Try to dump a type with %u bytes", (unsigned)size);
755 static size_t emit_string_initializer(const ir_initializer_t *initializer)
759 len = initializer->compound.n_initializers;
760 if (be_gas_object_file_format == OBJECT_FILE_FORMAT_MACH_O) {
761 be_emit_cstring("\t.ascii \"");
763 be_emit_cstring("\t.string \"");
767 for (i = 0; i < len; ++i) {
768 const ir_initializer_t *sub_initializer
769 = get_initializer_compound_value(initializer, i);
771 ir_tarval *tv = get_initializer_tarval(sub_initializer);
772 int c = get_tarval_long(tv);
775 case '"' : be_emit_cstring("\\\""); break;
776 case '\n': be_emit_cstring("\\n"); break;
777 case '\r': be_emit_cstring("\\r"); break;
778 case '\t': be_emit_cstring("\\t"); break;
779 case '\\': be_emit_cstring("\\\\"); break;
784 be_emit_irprintf("\\%03o", c);
788 be_emit_cstring("\"\n");
789 be_emit_write_line();
791 return initializer->compound.n_initializers;
794 typedef enum normal_or_bitfield_kind {
799 } normal_or_bitfield_kind;
802 normal_or_bitfield_kind kind;
807 unsigned char bf_val;
808 const ir_initializer_t *string;
810 } normal_or_bitfield;
812 static size_t get_initializer_size(const ir_initializer_t *initializer,
815 switch (get_initializer_kind(initializer)) {
816 case IR_INITIALIZER_TARVAL:
817 assert(get_tarval_mode(get_initializer_tarval_value(initializer)) == get_type_mode(type));
818 return get_type_size_bytes(type);
819 case IR_INITIALIZER_CONST:
820 case IR_INITIALIZER_NULL:
821 return get_type_size_bytes(type);
822 case IR_INITIALIZER_COMPOUND:
823 if (is_Array_type(type)) {
824 if (is_array_variable_size(type)) {
825 ir_type *element_type = get_array_element_type(type);
826 unsigned element_size = get_type_size_bytes(element_type);
827 unsigned element_align
828 = get_type_alignment_bytes(element_type);
829 unsigned misalign = element_size % element_align;
831 = get_initializer_compound_n_entries(initializer);
832 element_size += element_align - misalign;
833 return n_inits * element_size;
835 return get_type_size_bytes(type);
838 assert(is_compound_type(type));
839 size_t size = get_type_size_bytes(type);
840 if (is_compound_variable_size(type)) {
841 /* last initializer has to be an array of variable size */
842 size_t l = get_initializer_compound_n_entries(initializer)-1;
843 const ir_initializer_t *last
844 = get_initializer_compound_value(initializer, l);
845 const ir_entity *last_ent = get_compound_member(type, l);
846 ir_type *last_type = get_entity_type(last_ent);
847 assert(is_array_variable_size(last_type));
848 size += get_initializer_size(last, last_type);
854 panic("found invalid initializer");
858 static normal_or_bitfield *glob_vals;
859 static size_t max_vals;
862 static void emit_bitfield(normal_or_bitfield *vals, size_t offset_bits,
863 const ir_initializer_t *initializer, ir_type *type)
865 static const size_t BITS_PER_BYTE = 8;
866 ir_mode *mode = get_type_mode(type);
867 ir_tarval *tv = NULL;
871 bool big_endian = be_get_backend_param()->byte_order_big_endian;
873 switch (get_initializer_kind(initializer)) {
874 case IR_INITIALIZER_NULL:
876 case IR_INITIALIZER_TARVAL:
877 tv = get_initializer_tarval_value(initializer);
879 case IR_INITIALIZER_CONST: {
880 ir_node *node = get_initializer_const_value(initializer);
881 if (!is_Const(node)) {
882 panic("bitfield initializer not a Const node");
884 tv = get_Const_tarval(node);
887 case IR_INITIALIZER_COMPOUND:
888 panic("bitfield initializer is compound");
891 panic("Couldn't get numeric value for bitfield initializer");
893 tv = tarval_convert_to(tv, get_type_mode(type));
895 value_len = get_type_size_bytes(get_primitive_base_type(type));
897 end = get_mode_size_bits(mode);
898 while (bit_offset < end) {
899 size_t src_offset = bit_offset / BITS_PER_BYTE;
900 size_t src_offset_bits = bit_offset % BITS_PER_BYTE;
901 size_t dst_offset = (bit_offset+offset_bits) / BITS_PER_BYTE;
902 size_t dst_offset_bits = (bit_offset+offset_bits) % BITS_PER_BYTE;
903 size_t src_bits_len = end-bit_offset;
904 size_t dst_bits_len = BITS_PER_BYTE-dst_offset_bits;
905 unsigned char curr_bits;
906 normal_or_bitfield *val;
907 if (src_bits_len > dst_bits_len)
908 src_bits_len = dst_bits_len;
911 val = &vals[value_len - dst_offset - 1];
913 val = &vals[dst_offset];
916 assert((val-glob_vals) < (ptrdiff_t) max_vals);
917 assert(val->kind == BITFIELD ||
918 (val->kind == NORMAL && val->v.value == NULL));
919 val->kind = BITFIELD;
920 curr_bits = get_tarval_sub_bits(tv, src_offset);
921 curr_bits = curr_bits >> src_offset_bits;
922 if (src_offset_bits + src_bits_len > 8) {
923 unsigned next_bits = get_tarval_sub_bits(tv, src_offset+1);
924 curr_bits |= next_bits << (8 - src_offset_bits);
926 curr_bits &= (1 << src_bits_len) - 1;
927 val->v.bf_val |= curr_bits << dst_offset_bits;
929 bit_offset += dst_bits_len;
933 static void emit_ir_initializer(normal_or_bitfield *vals,
934 const ir_initializer_t *initializer,
937 assert((size_t) (vals - glob_vals) < max_vals);
939 if (initializer_is_string_const(initializer)) {
940 assert(vals->kind != BITFIELD);
942 vals->v.string = initializer;
946 switch (get_initializer_kind(initializer)) {
947 case IR_INITIALIZER_NULL:
949 case IR_INITIALIZER_TARVAL: {
952 assert(vals->kind != BITFIELD);
955 vals->v.tarval = get_initializer_tarval_value(initializer);
956 assert(get_type_mode(type) == get_tarval_mode(vals->v.tarval));
957 for (i = 1; i < get_type_size_bytes(type); ++i) {
958 vals[i].kind = NORMAL;
960 vals[i].v.value = NULL;
964 case IR_INITIALIZER_CONST: {
967 assert(vals->kind != BITFIELD);
970 vals->v.value = get_initializer_const_value(initializer);
971 for (i = 1; i < get_type_size_bytes(type); ++i) {
972 vals[i].kind = NORMAL;
974 vals[i].v.value = NULL;
978 case IR_INITIALIZER_COMPOUND: {
980 size_t n = get_initializer_compound_n_entries(initializer);
982 if (is_Array_type(type)) {
983 ir_type *element_type = get_array_element_type(type);
984 size_t skip = get_type_size_bytes(element_type);
985 size_t alignment = get_type_alignment_bytes(element_type);
986 size_t misalign = skip % alignment;
988 skip += alignment - misalign;
991 for (i = 0; i < n; ++i) {
992 ir_initializer_t *sub_initializer
993 = get_initializer_compound_value(initializer, i);
995 emit_ir_initializer(vals, sub_initializer, element_type);
1000 size_t n_members, i;
1001 assert(is_compound_type(type));
1002 n_members = get_compound_n_members(type);
1003 for (i = 0; i < n_members; ++i) {
1004 ir_entity *member = get_compound_member(type, i);
1005 size_t offset = get_entity_offset(member);
1006 ir_type *subtype = get_entity_type(member);
1007 ir_mode *mode = get_type_mode(subtype);
1008 ir_initializer_t *sub_initializer;
1010 assert(i < get_initializer_compound_n_entries(initializer));
1012 = get_initializer_compound_value(initializer, i);
1016 = get_entity_offset_bits_remainder(member);
1018 if (is_Primitive_type(subtype)
1019 && get_primitive_base_type(subtype) != NULL) {
1020 emit_bitfield(&vals[offset], offset_bits,
1021 sub_initializer, subtype);
1024 assert(offset_bits == 0);
1028 emit_ir_initializer(&vals[offset], sub_initializer, subtype);
1035 panic("invalid ir_initializer kind found");
1038 static void emit_tarval_data(ir_type *type, ir_tarval *tv)
1040 size_t size = get_type_size_bytes(type);
1042 /* this should be an x86 extended float */
1043 assert(be_get_backend_param()->byte_order_big_endian == 0);
1045 /* Beware: Mixed endian output! One little endian number emitted as
1046 * three longs. Each long initializer is written in big endian. */
1048 "\t.long\t0x%02x%02x%02x%02x\n"
1049 "\t.long\t0x%02x%02x%02x%02x\n"
1050 "\t.long\t0x%02x%02x%02x%02x\n",
1051 get_tarval_sub_bits(tv, 3), get_tarval_sub_bits(tv, 2),
1052 get_tarval_sub_bits(tv, 1), get_tarval_sub_bits(tv, 0),
1053 get_tarval_sub_bits(tv, 7), get_tarval_sub_bits(tv, 6),
1054 get_tarval_sub_bits(tv, 5), get_tarval_sub_bits(tv, 4),
1055 get_tarval_sub_bits(tv, 11), get_tarval_sub_bits(tv, 10),
1056 get_tarval_sub_bits(tv, 9), get_tarval_sub_bits(tv, 8)
1058 be_emit_write_line();
1059 } else if (size == 16) {
1060 if (be_get_backend_param()->byte_order_big_endian) {
1062 "\t.long\t0x%02x%02x%02x%02x\n"
1063 "\t.long\t0x%02x%02x%02x%02x\n"
1064 "\t.long\t0x%02x%02x%02x%02x\n"
1065 "\t.long\t0x%02x%02x%02x%02x\n",
1066 get_tarval_sub_bits(tv, 15), get_tarval_sub_bits(tv, 14),
1067 get_tarval_sub_bits(tv, 13), get_tarval_sub_bits(tv, 12),
1068 get_tarval_sub_bits(tv, 11), get_tarval_sub_bits(tv, 10),
1069 get_tarval_sub_bits(tv, 9), get_tarval_sub_bits(tv, 8),
1070 get_tarval_sub_bits(tv, 7), get_tarval_sub_bits(tv, 6),
1071 get_tarval_sub_bits(tv, 5), get_tarval_sub_bits(tv, 4),
1072 get_tarval_sub_bits(tv, 3), get_tarval_sub_bits(tv, 2),
1073 get_tarval_sub_bits(tv, 1), get_tarval_sub_bits(tv, 0)
1076 /* Beware: Mixed endian output! One little endian number emitted as
1077 * three longs. Each long initializer is written in big endian. */
1079 "\t.long\t0x%02x%02x%02x%02x\n"
1080 "\t.long\t0x%02x%02x%02x%02x\n"
1081 "\t.long\t0x%02x%02x%02x%02x\n"
1082 "\t.long\t0x%02x%02x%02x%02x\n",
1083 get_tarval_sub_bits(tv, 3), get_tarval_sub_bits(tv, 2),
1084 get_tarval_sub_bits(tv, 1), get_tarval_sub_bits(tv, 0),
1085 get_tarval_sub_bits(tv, 7), get_tarval_sub_bits(tv, 6),
1086 get_tarval_sub_bits(tv, 5), get_tarval_sub_bits(tv, 4),
1087 get_tarval_sub_bits(tv, 11), get_tarval_sub_bits(tv, 10),
1088 get_tarval_sub_bits(tv, 9), get_tarval_sub_bits(tv, 8),
1089 get_tarval_sub_bits(tv, 15), get_tarval_sub_bits(tv, 14),
1090 get_tarval_sub_bits(tv, 13), get_tarval_sub_bits(tv, 12)
1093 be_emit_write_line();
1097 emit_size_type(size);
1098 emit_arith_tarval(tv, size);
1100 be_emit_write_line();
1105 * Emit an atomic value.
1107 * @param env the gas output environment
1108 * @param init a node representing the atomic value (on the const code irg)
1110 static void emit_node_data(be_gas_decl_env_t *env, ir_node *init, ir_type *type)
1112 size_t size = get_type_size_bytes(type);
1113 if (size == 12 || size == 16) {
1115 if (!is_Const(init)) {
1116 panic("12/16byte initializers only support Const nodes yet");
1118 tv = get_Const_tarval(init);
1119 emit_tarval_data(type, tv);
1123 emit_size_type(size);
1124 emit_init_expression(env, init);
1126 be_emit_write_line();
1129 static void emit_initializer(be_gas_decl_env_t *env, const ir_entity *entity)
1131 const ir_initializer_t *initializer = entity->initializer;
1133 normal_or_bitfield *vals;
1137 if (initializer_is_string_const(initializer)) {
1138 emit_string_initializer(initializer);
1142 type = get_entity_type(entity);
1143 size = get_initializer_size(initializer, type);
1149 * In the worst case, every initializer allocates one byte.
1150 * Moreover, initializer might be big, do not allocate on stack.
1152 vals = XMALLOCNZ(normal_or_bitfield, size);
1159 emit_ir_initializer(vals, initializer, type);
1161 /* now write values sorted */
1162 for (k = 0; k < size; ) {
1164 normal_or_bitfield_kind kind = vals[k].kind;
1168 if (vals[k].v.value != NULL) {
1169 emit_node_data(env, vals[k].v.value, vals[k].type);
1170 elem_size = get_type_size_bytes(vals[k].type);
1176 emit_tarval_data(vals[k].type, vals[k].v.tarval);
1177 elem_size = get_type_size_bytes(vals[k].type);
1180 elem_size = emit_string_initializer(vals[k].v.string);
1183 be_emit_irprintf("\t.byte\t%d\n", vals[k].v.bf_val);
1184 be_emit_write_line();
1188 panic("internal compiler error (invalid normal_or_bitfield_kind");
1192 while (k < size && vals[k].kind == NORMAL && vals[k].v.value == NULL) {
1199 be_emit_irprintf("\t.space\t%d, 0\n", space);
1200 be_emit_write_line();
1206 static void emit_align(unsigned p2alignment)
1208 be_emit_irprintf("\t.p2align\t%u\n", log2_floor(p2alignment));
1209 be_emit_write_line();
1212 static unsigned get_effective_entity_alignment(const ir_entity *entity)
1214 unsigned alignment = get_entity_alignment(entity);
1215 if (alignment == 0) {
1216 ir_type *type = get_entity_type(entity);
1217 alignment = get_type_alignment_bytes(type);
1222 static void emit_common(const ir_entity *entity)
1224 unsigned size = get_type_size_bytes(get_entity_type(entity));
1225 unsigned alignment = get_effective_entity_alignment(entity);
1227 if (get_entity_linkage(entity) & IR_LINKAGE_WEAK) {
1231 switch (be_gas_object_file_format) {
1232 case OBJECT_FILE_FORMAT_MACH_O:
1233 be_emit_cstring("\t.comm ");
1234 be_gas_emit_entity(entity);
1235 be_emit_irprintf(",%u,%u\n", size, log2_floor(alignment));
1236 be_emit_write_line();
1238 case OBJECT_FILE_FORMAT_ELF:
1239 be_emit_cstring("\t.comm ");
1240 be_gas_emit_entity(entity);
1241 be_emit_irprintf(",%u,%u\n", size, alignment);
1242 be_emit_write_line();
1244 case OBJECT_FILE_FORMAT_COFF:
1245 be_emit_cstring("\t.comm ");
1246 be_gas_emit_entity(entity);
1247 be_emit_irprintf(",%u # %u\n", size, alignment);
1248 be_emit_write_line();
1251 panic("invalid object file format");
1254 static void emit_local_common(const ir_entity *entity)
1256 unsigned size = get_type_size_bytes(get_entity_type(entity));
1257 unsigned alignment = get_effective_entity_alignment(entity);
1259 if (get_entity_linkage(entity) & IR_LINKAGE_WEAK) {
1263 switch (be_gas_object_file_format) {
1264 case OBJECT_FILE_FORMAT_MACH_O:
1265 be_emit_cstring("\t.lcomm ");
1266 be_gas_emit_entity(entity);
1267 be_emit_irprintf(",%u,%u\n", size, log2_floor(alignment));
1268 be_emit_write_line();
1270 case OBJECT_FILE_FORMAT_ELF:
1271 be_emit_cstring("\t.local ");
1272 be_gas_emit_entity(entity);
1273 be_emit_cstring("\n");
1274 be_emit_write_line();
1275 be_emit_cstring("\t.comm ");
1276 be_gas_emit_entity(entity);
1277 be_emit_irprintf(",%u,%u\n", size, alignment);
1278 be_emit_write_line();
1280 case OBJECT_FILE_FORMAT_COFF:
1281 be_emit_cstring("\t.lcomm ");
1282 be_gas_emit_entity(entity);
1283 be_emit_irprintf(",%u # %u\n", size, alignment);
1284 be_emit_write_line();
1287 panic("invalid object file format");
1290 static void emit_indirect_symbol(const ir_entity *entity, be_gas_section_t section)
1292 /* we can only do PIC code on macho so far */
1293 assert(be_gas_object_file_format == OBJECT_FILE_FORMAT_MACH_O);
1295 be_gas_emit_entity(entity);
1296 be_emit_cstring(":\n");
1297 be_emit_write_line();
1298 be_emit_irprintf("\t.indirect_symbol %I\n", get_entity_ident(entity));
1299 be_emit_write_line();
1300 if (section == GAS_SECTION_PIC_TRAMPOLINES) {
1301 be_emit_cstring("\thlt ; hlt ; hlt ; hlt ; hlt\n");
1302 be_emit_write_line();
1304 assert(section == GAS_SECTION_PIC_SYMBOLS);
1305 be_emit_cstring("\t.long 0\n");
1306 be_emit_write_line();
1310 char const *be_gas_get_private_prefix(void)
1312 return be_gas_object_file_format == OBJECT_FILE_FORMAT_MACH_O ? "L" : ".L";
1315 void be_gas_emit_entity(const ir_entity *entity)
1317 if (entity->type == get_code_type()) {
1318 ir_label_t label = get_entity_label(entity);
1319 be_emit_irprintf("%s_%lu", be_gas_get_private_prefix(), label);
1323 if (get_entity_visibility(entity) == ir_visibility_private) {
1324 be_emit_string(be_gas_get_private_prefix());
1326 be_emit_irprintf("%I", get_entity_ld_ident(entity));
1329 void be_gas_emit_block_name(const ir_node *block)
1331 ir_entity *entity = get_Block_entity(block);
1332 if (entity != NULL) {
1333 be_gas_emit_entity(entity);
1335 void *nr_val = pmap_get(block_numbers, block);
1337 if (nr_val == NULL) {
1338 nr = next_block_nr++;
1339 pmap_insert(block_numbers, block, INT_TO_PTR(nr+1));
1341 nr = PTR_TO_INT(nr_val)-1;
1343 be_emit_irprintf("%s%d", be_gas_get_private_prefix(), nr);
1347 void be_gas_begin_block(const ir_node *block, bool needs_label)
1350 be_gas_emit_block_name(block);
1353 if (!be_options.verbose_asm)
1355 be_emit_cstring("/*");
1356 be_gas_emit_block_name(block);
1357 be_emit_cstring(":*/");
1360 if (be_options.verbose_asm) {
1362 ir_graph *irg = get_irn_irg(block);
1363 ir_exec_freq *exec_freq = be_get_irg_exec_freq(irg);
1365 be_emit_pad_comment();
1366 be_emit_cstring("/* preds:");
1368 arity = get_irn_arity(block);
1370 be_emit_cstring(" none");
1373 for (i = 0; i < arity; ++i) {
1374 ir_node *predblock = get_Block_cfgpred_block(block, i);
1376 be_gas_emit_block_name(predblock);
1379 if (exec_freq != NULL) {
1380 be_emit_irprintf(", freq: %.3f",
1381 get_block_execfreq(exec_freq, block));
1383 be_emit_cstring(" */");
1386 be_emit_write_line();
1390 * Dump a global entity.
1392 * @param env the gas output environment
1393 * @param ent the entity to be dumped
1395 static void emit_global(be_gas_decl_env_t *env, const ir_entity *entity)
1397 ir_type *type = get_entity_type(entity);
1398 ident *ld_ident = get_entity_ld_ident(entity);
1399 unsigned alignment = get_effective_entity_alignment(entity);
1400 be_gas_section_t section = determine_section(env, entity);
1401 ir_visibility visibility = get_entity_visibility(entity);
1402 ir_linkage linkage = get_entity_linkage(entity);
1404 /* Block labels are already emitted in the code. */
1405 if (type == get_code_type())
1408 /* we already emitted all methods with graphs in other functions like
1409 * be_gas_emit_function_prolog(). All others don't need to be emitted.
1411 if (is_Method_type(type) && section != GAS_SECTION_PIC_TRAMPOLINES) {
1415 be_dwarf_variable(entity);
1417 if (section == GAS_SECTION_BSS) {
1418 switch (visibility) {
1419 case ir_visibility_local:
1420 case ir_visibility_private:
1421 emit_local_common(entity);
1423 case ir_visibility_external:
1424 if (linkage & IR_LINKAGE_MERGE) {
1425 emit_common(entity);
1432 emit_visibility(entity);
1434 if (!is_po2(alignment))
1435 panic("alignment not a power of 2");
1437 emit_section(section, entity);
1439 if (section == GAS_SECTION_PIC_TRAMPOLINES
1440 || section == GAS_SECTION_PIC_SYMBOLS) {
1441 emit_indirect_symbol(entity, section);
1445 /* nothing left to do without an initializer */
1446 if (!entity_has_definition(entity))
1450 if (alignment > 1) {
1451 emit_align(alignment);
1453 if (be_gas_object_file_format == OBJECT_FILE_FORMAT_ELF
1454 && be_gas_emit_types
1455 && visibility != ir_visibility_private) {
1456 be_emit_cstring("\t.type\t");
1457 be_gas_emit_entity(entity);
1458 be_emit_cstring(", ");
1459 be_emit_char(be_gas_elf_type_char);
1460 be_emit_cstring("object\n\t.size\t");\
1461 be_gas_emit_entity(entity);
1462 be_emit_irprintf(", %u\n", get_type_size_bytes(type));
1465 if (get_id_str(ld_ident)[0] != '\0') {
1466 be_gas_emit_entity(entity);
1467 be_emit_cstring(":\n");
1468 be_emit_write_line();
1471 if (entity_is_null(entity)) {
1472 /* we should use .space for stuff in the bss segment */
1473 unsigned size = get_type_size_bytes(type);
1475 be_emit_irprintf("\t.space %u, 0\n", get_type_size_bytes(type));
1476 be_emit_write_line();
1479 assert(entity->initializer != NULL);
1480 emit_initializer(env, entity);
1485 * Dumps declarations of global variables and the initialization code.
1487 * @param gt a global like type, either the global or the TLS one
1488 * @param env an environment
1490 static void be_gas_emit_globals(ir_type *gt, be_gas_decl_env_t *env)
1492 size_t i, n = get_compound_n_members(gt);
1494 for (i = 0; i < n; i++) {
1495 ir_entity *ent = get_compound_member(gt, i);
1496 emit_global(env, ent);
1500 /* Generate all entities. */
1501 static void emit_global_decls(const be_main_env_t *main_env)
1503 be_gas_decl_env_t env;
1504 memset(&env, 0, sizeof(env));
1506 /* dump global type */
1507 env.main_env = main_env;
1508 env.section = (be_gas_section_t) -1;
1510 be_gas_emit_globals(get_glob_type(), &env);
1511 be_gas_emit_globals(get_tls_type(), &env);
1512 be_gas_emit_globals(get_segment_type(IR_SEGMENT_CONSTRUCTORS), &env);
1513 be_gas_emit_globals(get_segment_type(IR_SEGMENT_DESTRUCTORS), &env);
1514 be_gas_emit_globals(main_env->pic_symbols_type, &env);
1515 be_gas_emit_globals(main_env->pic_trampolines_type, &env);
1518 * ".subsections_via_symbols marks object files which are OK to divide
1519 * their section contents into individual blocks".
1520 * From my understanding this means no label points in the middle of an
1521 * object which we want to address as a whole. Firm code should be fine
1524 if (be_gas_object_file_format == OBJECT_FILE_FORMAT_MACH_O) {
1525 be_emit_cstring("\t.subsections_via_symbols\n");
1526 be_emit_write_line();
1530 void be_emit_jump_table(const ir_node *node, const ir_switch_table *table,
1531 ir_entity *entity, get_cfop_target_func get_cfop_target)
1533 unsigned n_outs = arch_get_irn_n_outs(node);
1534 const ir_node **targets = XMALLOCNZ(const ir_node*, n_outs);
1535 size_t n_entries = ir_switch_table_get_n_entries(table);
1536 unsigned long length = 0;
1538 const ir_edge_t *edge;
1540 const ir_node **labels;
1542 /* go over all proj's and collect their jump targets */
1543 foreach_out_edge(node, edge) {
1544 ir_node *proj = get_edge_src_irn(edge);
1545 long pn = get_Proj_proj(proj);
1546 ir_node *target = get_cfop_target(proj);
1547 assert(targets[pn] == NULL);
1548 targets[pn] = target;
1551 /* go over table to determine max value (note that we normalized the
1552 * ranges so that the minimum is 0) */
1553 for (e = 0; e < n_entries; ++e) {
1554 const ir_switch_table_entry *entry
1555 = ir_switch_table_get_entry_const(table, e);
1556 ir_tarval *max = entry->max;
1560 if (!tarval_is_long(max))
1561 panic("switch case overflow (%+F)", node);
1562 val = (unsigned long) get_tarval_long(max);
1568 /* the 16000 isn't a real limit of the architecture. But should protect us
1569 * from seamingly endless compiler runs */
1570 if (length > 16000) {
1571 /* switch lowerer should have broken this monster to pieces... */
1572 panic("too large switch encountered (%+F)", node);
1576 labels = XMALLOCNZ(const ir_node*, length);
1577 for (e = 0; e < n_entries; ++e) {
1578 const ir_switch_table_entry *entry
1579 = ir_switch_table_get_entry_const(table, e);
1580 ir_tarval *min = entry->min;
1581 ir_tarval *max = entry->max;
1582 const ir_node *target = targets[entry->pn];
1583 assert(entry->pn < (long)n_outs);
1585 unsigned long val = (unsigned long)get_tarval_long(max);
1586 labels[val] = target;
1588 unsigned long min_val;
1589 unsigned long max_val;
1591 if (!tarval_is_long(min))
1592 panic("switch case overflow (%+F)", node);
1593 min_val = (unsigned long)get_tarval_long(min);
1594 max_val = (unsigned long)get_tarval_long(max);
1595 assert(min_val <= max_val);
1596 for (i = min_val; i <= max_val; ++i) {
1603 if (entity != NULL) {
1604 be_gas_emit_switch_section(GAS_SECTION_RODATA);
1605 be_emit_cstring("\t.align 4\n");
1606 be_gas_emit_entity(entity);
1607 be_emit_cstring(":\n");
1610 for (i = 0; i < length; ++i) {
1611 const ir_node *block = labels[i];
1614 be_emit_cstring("\t.long ");
1615 be_gas_emit_block_name(block);
1617 be_emit_write_line();
1621 be_gas_emit_switch_section(GAS_SECTION_TEXT);
1627 static void emit_global_asms(void)
1629 size_t n = get_irp_n_asms();
1632 be_gas_emit_switch_section(GAS_SECTION_TEXT);
1633 for (i = 0; i < n; ++i) {
1634 ident *asmtext = get_irp_asm(i);
1636 be_emit_cstring("#APP\n");
1637 be_emit_write_line();
1638 be_emit_irprintf("%I\n", asmtext);
1639 be_emit_write_line();
1640 be_emit_cstring("#NO_APP\n");
1641 be_emit_write_line();
1645 void be_gas_begin_compilation_unit(const be_main_env_t *env)
1648 be_dwarf_unit_begin(env->cup_name);
1650 block_numbers = pmap_create();
1656 void be_gas_end_compilation_unit(const be_main_env_t *env)
1658 emit_global_decls(env);
1660 pmap_destroy(block_numbers);
1662 be_dwarf_unit_end();