From: David Given Date: Sat, 29 Oct 2016 10:55:21 +0000 (+0200) Subject: Emit negative constants correctly. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=acaae765afea2657ec36144efab91b28c481ec81;p=ack.git Emit negative constants correctly. --- diff --git a/mach/proto/mcg/data.c b/mach/proto/mcg/data.c index 5eeca8fc2..2e27e37ca 100644 --- a/mach/proto/mcg/data.c +++ b/mach/proto/mcg/data.c @@ -49,13 +49,24 @@ static void emit_header(int desired_section) } } +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 0x%0*lld\n", size, size*2, data); + 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]; @@ -69,9 +80,13 @@ void data_float(const char* data, size_t size, bool is_ro) 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 0x%02x", buffer[0]); + fprintf(outputfile, "\t.data1 "); + writehex(buffer[0], 1); for (i=1; i