#include "mcg.h" #include #define IEEEFLOAT #define FL_MSL_AT_LOW_ADDRESS 1 #define FL_MSW_AT_LOW_ADDRESS 1 #define FL_MSB_AT_LOW_ADDRESS 1 #include "con_float" static struct symbol* pending; void data_label(const char* label) { if (pending) fatal("two consecutive data labels ('%s' and '%s')", pending->name, label); pending = symbol_get(label); if (pending->is_defined) fatal("label '%s' defined twice", pending->name); pending->is_defined = true; } static const char* section_to_str(int section) { switch (section) { case SECTION_ROM: return ".rom"; case SECTION_DATA: return ".data"; case SECTION_BSS: return ".bss"; case SECTION_TEXT: return ".text"; default: return "unknown"; } } static void emit_header(int desired_section) { if (pending) { if (pending->section == SECTION_UNKNOWN) pending->section = desired_section; else if (pending->section != desired_section) fatal("label '%s' can't change sections", pending->name); fprintf(outputfile, "\n.sect %s\n", section_to_str(pending->section)); fprintf(outputfile, "%s:\n", platform_label(pending->name)); pending = NULL; } } static void writehex(arith data, int size) { if (data < 0) fprintf(outputfile, "-0x%0*lx", size*2, -data); else fprintf(outputfile, "0x%0*lx", size*2, data); } void data_int(arith data, size_t size, bool is_ro) { emit_header(is_ro ? SECTION_ROM : SECTION_DATA); assert((size == 1) || (size == 2) || (size == 4) || (size == 8)); fprintf(outputfile, "\t.data%d ", size); writehex(data, size); fprintf(outputfile, "\n"); } void data_float(const char* data, size_t size, bool is_ro) { unsigned char buffer[8]; int i; emit_header(is_ro ? SECTION_ROM : SECTION_DATA); assert((size == 4) || (size == 8)); i = float_cst(data, size, (char*) buffer); if ((i != 0) && (i != 2)) /* 2 == overflow */ fatal("cannot parse floating point constant %s sz %d", data, size); fprintf(outputfile, "\t!float %s sz %d\n", data, size); fprintf(outputfile, "\t.data1 "); writehex(buffer[0], 1); for (i=1; i