/** * dump switch table */ void dumpsw(WHILE *ws) { int i,j; data_segment_gdata (); generate_label (ws->body_tab); if (ws->case_test != swstp) { j = ws->case_test; while (j < swstp) { gen_def_word (); i = 4; while (i--) { output_number (swstcase[j]); output_byte (','); print_label (swstlab[j++]); if ((i == 0) | (j >= swstp)) { newline (); break; } output_byte (','); } } } gen_def_word (); print_label (ws->incr_def); output_string (",0"); newline (); code_segment_gtext (); }
/** * evaluate one initializer, add data to table * @param symbol_name * @param type * @param identity * @param dim * @param tag * @return * returns size of initializer, or 0 for none (a null string is size 1) * */ int init(char *symbol_name, int type, int identity, int *dim, TAG_SYMBOL *tag) { int value, n; /* A pointer is initialized as a word holding the address of the struct or string etc that directly follows */ if(identity == POINTER) { int x = getlabel(); gen_def_word(); print_label(x); newline(); print_label(x); output_label_terminator(); newline(); } /* FIXME: may need to distinguish const string v data in future */ if(quoted_string(&n, NULL)) { if((identity == VARIABLE) || !(type & CCHAR)) error("found string: must assign to char pointer or array"); *dim = *dim - n; /* ??? FIXME arrays of char only */ return n; } if (type & CCHAR) gen_def_byte(); else gen_def_word(); if (!number(&value) && !quoted_char(&value)) return 0; *dim = *dim - 1; output_number(value); newline(); return (type & CCHAR) ? 1 : 2; }
/** * dump switch table */ dumpsw(loop_t *loop) { int i,j; data_segment_gdata (); generate_label (loop->body_label); if (loop->test_label != swstp) { j = loop->test_label; while (j < swstp) { gen_def_word (); i = 4; while (i--) { output_number (swstcase[j]); output_byte (','); print_label (swstlab[j++]); if ((i == 0) | (j >= swstp)) { newline (); break; } output_byte (','); } } } gen_def_word (); print_label (loop->cont_label); output_string (",0"); newline (); code_segment_gtext (); }
/** * dump all static variables */ void dumpglbs(void) { int dim, i, list_size, line_count, value; if (!glbflag) return; current_symbol_table_idx = rglobal_table_index; while (current_symbol_table_idx < global_table_index) { SYMBOL *symbol = &symbol_table[current_symbol_table_idx]; if (symbol->identity != FUNCTION) { ppubext(symbol); if (symbol->storage != EXTERN) { output_string(symbol->name); output_label_terminator(); dim = symbol->offset; list_size = 0; line_count = 0; if (find_symbol_initials(symbol->name)) { // has initials list_size = get_size(symbol->name); if (dim == -1) { dim = list_size; } } for (i=0; i<dim; i++) { if (symbol->type == STRUCT) { dump_struct(symbol, i); } else { if (line_count % 10 == 0) { newline(); if ((symbol->type & CINT) || (symbol->identity == POINTER)) { gen_def_word(); } else { gen_def_byte(); } } if (i < list_size) { // dump data value = get_item_at(symbol->name, i, &tag_table[symbol->tagidx]); output_number(value); } else { // dump zero, no more data available output_number(0); } line_count++; if (line_count % 10 == 0) { line_count = 0; } else { if (i < dim-1) { output_byte( ',' ); } } } } newline(); } } else { fpubext(symbol); } current_symbol_table_idx++; } }
/** * dump struct data * @param symbol struct variable * @param position position of the struct in the array, or zero */ void dump_struct(SYMBOL *symbol, int position) { int i, number_of_members, value; number_of_members = tag_table[symbol->tagidx].number_of_members; newline(); 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 & CINT) { gen_def_word(); } else { gen_def_byte(); } if (position < get_size(symbol->name)) { // dump data value = get_item_at(symbol->name, position*number_of_members+i, &tag_table[symbol->tagidx]); output_number(value); } else { // dump zero, no more data available output_number(0); } newline(); } }