void asm_declare_decl_init(decl *d) { enum section_type sec; if((d->store & STORE_MASK_STORE) == store_extern){ asm_predeclare_extern(d); return; } sec = type_is_const(d->ref) ? SECTION_RODATA : SECTION_DATA; if(d->bits.var.init.dinit && !decl_init_is_zero(d->bits.var.init.dinit)){ asm_nam_begin(sec, d); asm_declare_init(sec, d->bits.var.init.dinit, d->ref); asm_out_section(sec, "\n"); }else if(d->bits.var.init.compiler_generated && fopt_mode & FOPT_COMMON){ const char *common_prefix = "comm "; /* section doesn't matter */ sec = SECTION_BSS; if(decl_linkage(d) == linkage_internal){ if(AS_SUPPORTS_LOCAL_COMMON){ asm_out_section(sec, ".local %s\n", decl_asm_spel(d)); }else{ common_prefix = "zerofill __DATA,__bss,"; } } asm_out_section(sec, ".%s%s,%u,%u\n", common_prefix, decl_asm_spel(d), decl_size(d), decl_align(d)); }else{ /* always resB, since we use decl_size() */ asm_nam_begin(SECTION_BSS, d); asm_reserve_bytes(SECTION_BSS, decl_size(d)); } }
void print_decl(decl *d, enum pdeclargs mode) { if(mode & PDECL_INDENT) idt_print(); if(d->store) fprintf(cc1_out, "%s ", decl_store_to_str(d->store)); if(fopt_mode & FOPT_ENGLISH){ print_decl_eng(d); }else{ print_type(d->ref, d); } if(mode & PDECL_SYM_OFFSET){ if(d->sym){ const int off = d->sym->type == sym_arg ? d->sym->loc.arg_offset : (int)d->sym->loc.stack_pos; fprintf(cc1_out, " (sym %s, pos = %d)", sym_to_str(d->sym->type), off); }else{ fprintf(cc1_out, " (no sym)"); } } if(mode & PDECL_SIZE && !type_is(d->ref, type_func)){ if(type_is_complete(d->ref)){ const unsigned sz = decl_size(d); const unsigned align = decl_align(d); fprintf(cc1_out, " size %u, align %u", sz, align); }else{ fprintf(cc1_out, " incomplete decl"); } } if(mode & PDECL_NEWLINE) fputc('\n', cc1_out); if(!type_is(d->ref, type_func) && d->bits.var.init.dinit && mode & PDECL_PINIT) { gen_str_indent++; print_decl_init(d->bits.var.init.dinit); gen_str_indent--; } if(mode & PDECL_ATTR){ gen_str_indent++; if(!type_is(d->ref, type_func) && d->bits.var.align) idt_printf("[align={as_int=%d, resolved=%d}]\n", d->bits.var.align->as_int, d->bits.var.align->resolved); print_attribute(d->attr); print_type_attr(d->ref); gen_str_indent--; } if((mode & PDECL_FUNC_DESCEND) && DECL_HAS_FUNC_CODE(d)){ decl **iter; gen_str_indent++; for(iter = d->bits.func.code->symtab->decls; iter && *iter; iter++){ sym *s = (*iter)->sym; if(s) idt_printf("offset of %s = %d\n", (*iter)->spel, s->loc.stack_pos); } idt_printf("function stack space %d\n", d->bits.func.code->symtab->auto_total_size); print_stmt(d->bits.func.code); gen_str_indent--; } }
static void asm_nam_begin(enum section_type sec, decl *d) { asm_nam_begin3(sec, decl_asm_spel(d), decl_align(d)); }