/* * dump switch table */ void dumpsw (INTPTR_T *ws) /*int ws[];*/ { INTPTR_T i,j; // gdata (); gnlabel (ws[WSTAB]); if (ws[WSCASEP] != swstp) { j = ws[WSCASEP]; while (j < swstp) { defword (); i = 4; while (i--) { outdec (swstcase[j]); outbyte (','); outlabel (swstlab[j++]); if ((i == 0) | (j >= swstp)) { newl (); break; } outbyte (','); } } } defword (); outlabel (ws[WSDEF]); outstr (",0"); newl(); // gtext (); }
/** * dump struct data * @param symbol struct variable * @param position position of the struct in the array, or zero */ int dump_struct (SYMBOL *symbol, int position) { int dumped_bytes = 0; int i, number_of_members, value; number_of_members = tag_table[symbol->tagidx].number_of_members; for (i = 0; i < number_of_members; i++) { // i is the index of current member, get type int member_type = member_table[tag_table[symbol->tagidx].member_idx + i].type; if (member_type == CCHAR || member_type == CUCHAR) { defbyte(); dumped_bytes += 1; } else { /* XXX: compound types? */ defword(); dumped_bytes += 2; } if (position < get_size(symbol->name)) { // dump data value = get_item_at(symbol->name, position * number_of_members + i, &tag_table[symbol->tagidx]); outdec(value); } else { // dump zero, no more data available outdec(0); } nl(); } return (dumped_bytes); }
void dumplits( int size, int pr_label , int queueptr,int queuelab, unsigned char *queue) { int j, k,lit ; if ( queueptr ) { if ( pr_label ) { output_section("rodata_compiler"); // output_section("text"); prefix(); queuelabel(queuelab) ; col() ; nl(); } k = 0 ; while ( k < queueptr ) { /* pseudo-op to define byte */ if (infunc) j=1; else j=10; if (size == 1) defbyte(); else if (size == 4) deflong(); else if (size == 0 ) { defmesg(); j=30; } else defword(); while ( j-- ) { if (size==0) { lit=getint(queue+k,1); if (lit >= 32 && lit <= 126 && lit != '"' && lit != '\\' ) outbyte(lit); else { outstr("\"\n"); defbyte(); outdec(lit); nl(); lit=0; } k++; if ( j == 0 || k >=queueptr || lit == 0 ) { if (lit) outbyte('"'); nl(); break; } } else { outdec(getint(queue+k, size)); k += size ; if ( j == 0 || k >= queueptr ) { nl(); /* need <cr> */ break; } outbyte(','); /* separate bytes */ } } } output_section("code_compiler"); // output_section("code"); } nl(); }
/* * dump the constant pool * */ void dump_const (void) { long i, j, k; long size; /* long c; */ if (const_nb) { const_ptr = const_var; for (i = 0; i < const_nb; i++) { size = const_ptr->size; cptr = const_ptr->sym; cptr->storage = EXTERN; prefix(); outstr(cptr->name); outstr(":"); nl(); j = const_ptr->data; while (size) { k = const_val[j++]; if ((cptr->type == CCHAR || cptr->type == CUCHAR) && cptr->ident != POINTER && !(cptr->ident == ARRAY && cptr->ptr_order > 0)) { defbyte(); const_size += 1; } else { defword(); const_size += 2; } if ((k == -1) || (k >= MAX_CONST_DATA)) outstr("0"); else if (k <= -1024) { k = (-k) - 1024; outlabel(litlab); outbyte('+'); outdec(k); } else outstr(&const_data[k]); nl(); size--; } const_ptr++; } } }
/* * dump all static variables */ void dumpglbs (void) { long i = 1; int dim, list_size, line_count; int j; FILE *save = output; if (!data) data = fmemopen(data_buf, DATABUFSIZE, "w"); if (!rodata) rodata = fmemopen(rodata_buf, DATABUFSIZE, "w"); /* This is done in several passes: Pass 0: Dump initialization data into const bank. Pass 1: Define space for uninitialized data. Pass 2: Define space for initialized data. */ if (glbflag) { int pass = 0; next: i = 1; for (cptr = rglbptr; cptr < glbptr; cptr++) { if (cptr->ident != FUNCTION) { // ppubext(cptr); if ((cptr->storage & WRITTEN) == 0 && /* Not yet written to file */ cptr->storage != EXTERN) { dim = cptr->offset; if (find_symbol_initials(cptr->name)) { // has initials /* dump initialization data */ if (pass == 1) /* initialized data not handled in pass 1 */ continue; else if (pass == 2) { /* define space for initialized data */ output = data; if (cptr->storage != LSTATIC) prefix(); outstr(cptr->name); outstr(":\t"); defstorage(); outdec(cptr->size); nl(); cptr->storage |= WRITTEN; output = save; continue; } /* output initialization data into const bank */ output = rodata; have_init_data = 1; list_size = 0; line_count = 0; list_size = get_size(cptr->name); if (cptr->type == CSTRUCT) list_size /= tag_table[cptr->tagidx].number_of_members; if (dim == -1) dim = list_size; int item; /* dim is an item count for non-compound types and a byte size for compound types; dump_struct() wants an item number, so we have to count both to get the right members out. */ for (j = item = 0; j < dim; j++, item++) { if (cptr->type == CSTRUCT) j += dump_struct(cptr, item) - 1; else { if (line_count % 10 == 0) { nl(); if (cptr->type == CCHAR || cptr->type == CUCHAR) defbyte(); else defword(); } if (j < list_size) { // dump data int value = get_item_at(cptr->name, j, &tag_table[cptr->tagidx]); outdec(value); } else { // dump zero, no more data available outdec(0); } line_count++; if (line_count % 10 == 0) line_count = 0; else { if (j < dim - 1) outbyte(','); } } } nl(); output = save; } else { if (pass == 0) continue; /* define space in bss */ if (i) { i = 0; nl(); gdata(); } if (cptr->storage != LSTATIC) prefix(); outstr(cptr->name); outstr(":\t"); defstorage(); outdec(cptr->size); nl(); cptr->storage |= WRITTEN; } } } else { // fpubext(cptr); } } if (++pass < 3) goto next; } if (i) { nl(); gdata(); } output = save; }
/* * evaluate one initialiser * * if dump is TRUE, dump literal immediately * save character string in litq to dump later * this is used for structures and arrays of pointers to char, so that the * struct or array is built immediately and the char strings are dumped later */ void init(int size, int ident, int *dim, int more, int dump, int is_struct) { int32_t value; int sz; /* number of chars in queue */ /* * djm 14/3/99 We have to rewrite this bit (ugh!) so that we store * our literal in a temporary queue, then if needed, we then dump * it out.. */ if ((sz = qstr(&value)) != -1 ) { sz++; #if 0 if (ident == VARIABLE || (size != 1 && more != CCHAR)) error(E_ASSIGN); #endif #ifdef INIT_TEST outstr("ident="); outdec(ident); outstr("size="); outdec(size); outstr("more="); outdec(more); outstr("dim="); outdec(*dim); outstr("sz="); outdec(sz); nl(); #endif if (ident == ARRAY && more == 0) { /* * Dump the literals where they are, padding out as appropriate */ if (*dim != -1 && sz > *dim) { /* * Ooops, initialised to long a string! */ warning(W_INIT2LONG); sz = *dim; gltptr = sz; *(glbq + sz - 1) = '\0'; /* Terminate string */ } dumplits(((size == 1) ? 0 : size), NO, gltptr, glblab, glbq); *dim -= sz; gltptr = 0; dumpzero(size, *dim); return; } else { /* * Store the literals in the queue! */ storeq(sz, glbq, &value); gltptr = 0; defword(); printlabel(litlab); outbyte('+'); outdec(value); nl(); --*dim; return; } } /* * djm, catch label names in structures (for (*name)() initialisation */ else { char sname[NAMEMAX + 1]; SYMBOL *ptr; if (symname(sname) && strcmp(sname,"sizeof") ) { /* We have got something.. */ if ((ptr = findglb(sname))) { /* Actually found sommat..very good! */ if (ident == POINTER || (ident == ARRAY && more)) { defword(); outname(ptr->name, dopref(ptr)); nl(); --*dim; } else if (ptr->type == ENUM) { value = ptr->size; goto constdecl; } else { error(E_DDECL); } } else error(E_UNSYMB, sname); } else if (rcmatch('}')) { #if 0 dumpzero(size,*dim); #endif } else if (constexpr(&value, 1)) { constdecl: if (ident == POINTER) { /* 24/1/03 dom - We want to be able to assign values to pointers or they're a bit useless.. */ #if 0 /* the only constant which can be assigned to a pointer is 0 */ if (value != 0) warning(W_ASSPTR); #endif size = 2; dump = YES; } if (dump) { /* struct member or array of pointer to char */ if (size == 4) { /* there appears to be a bug in z80asm regarding defl */ defbyte(); outdec((value % 65536UL) % 256); outbyte(','); outdec((value % 65536UL) / 256); outbyte(','); outdec((value / 65536UL) % 256); outbyte(','); outdec((value / 65536UL) / 256); } else { if (size == 1) defbyte(); else defword(); outdec(value); } nl(); /* Dump out a train of zeros as appropriate */ if (ident == ARRAY && more == 0) { dumpzero(size,(*dim)-1); } } else stowlit(value, size); --*dim; } } }