// Output label at current location int gsym(int b) { int l; l = glabel(); gsym_at(b, l); return l; }
/** * initialize global objects * @param symbol_name * @param type char or integer or struct * @param identity * @param dim * @return 1 if variable is initialized */ int initials(char *symbol_name, int type, int identity, int dim, int otag) { int dim_unknown = 0; int n; if(dim == 0) { // allow for xx[] = {..}; declaration dim_unknown = 1; } if (!(type & CCHAR) && !(type & CINT) && !(type == STRUCT)) { error("unsupported storage size"); } data_segment_gdata(); glabel(symbol_name); if(match("=")) { // an array or struct if(match("{")) { // aggregate initialiser if ((identity == POINTER || identity == VARIABLE) && type == STRUCT) { // aggregate is structure or pointer to structure dim = 0; struct_init(&tag_table[otag], symbol_name); } else { while((dim > 0) || (dim_unknown)) { if (identity == ARRAY && type == STRUCT) { // array of struct needbrack("{"); struct_init(&tag_table[otag], symbol_name); --dim; needbrack("}"); } else { if (init(symbol_name, type, identity, &dim, 0)) { dim_unknown++; } } if(match(",") == 0) { break; } } if(--dim_unknown == 0) identity = POINTER; else { /* Pad any missing objects */ n = dim; gen_def_storage(); if (identity != ARRAY && type != STRUCT) { if (!(type & CCHAR)) n *= 2; } else n = tag_table[otag].size; output_number(n); newline(); } } needbrack("}"); // single constant } else { init(symbol_name, type, identity, &dim, 0); } } code_segment_gtext(); return identity; }