From: David Given Date: Wed, 12 Sep 2018 21:19:32 +0000 (+0200) Subject: mcg now uses dataf4 and dataf8 to emit floating point constants, and so doesn't X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=642956fa2f37086f782c1acfb5582010d3fc5dc1;p=ack.git mcg now uses dataf4 and dataf8 to emit floating point constants, and so doesn't need flt_arith any more. (And also generates them correctly on little-endian systems.) as now parses numbers properly, doesn't trash memory all over the place, and can handle negative numbers. --- diff --git a/mach/proto/as/comm1.h b/mach/proto/as/comm1.h index 47f4302b3..206ae0b5d 100644 --- a/mach/proto/as/comm1.h +++ b/mach/proto/as/comm1.h @@ -153,7 +153,7 @@ void emit1(int); void emit2(int); void emit4(long); void emitx(valu_t, int); -void emitf(int size); +void emitf(int size, int negative); void emitstr(int); void ffreopen(char *, FILE *); FILE *ffcreat(char *); diff --git a/mach/proto/as/comm2.y b/mach/proto/as/comm2.y index 0643928d8..3e1229a41 100644 --- a/mach/proto/as/comm2.y +++ b/mach/proto/as/comm2.y @@ -280,17 +280,22 @@ datalist } ; -dataflist - : NUMBERF +numberf + : NUMBERF { - emitf((int)$0); + emitf((int)$-1, 0); } - | dataflist ',' NUMBERF + | '-' NUMBERF { - emitf((int)$3); + emitf((int)$-1, 1); } ; +dataflist + : numberf + | dataflist ',' numberf + ; + expr : error { serror("expr syntax err"); $$.val = 0; $$.typ = S_UND; diff --git a/mach/proto/as/comm5.c b/mach/proto/as/comm5.c index 9dc7a80bb..0b448ef0e 100644 --- a/mach/proto/as/comm5.c +++ b/mach/proto/as/comm5.c @@ -19,6 +19,8 @@ static int instring(int); static int inescape(void); static int infbsym(const char*); +static int maxstring = 0; + int yylex(void) { int c, c0, c1; @@ -453,16 +455,21 @@ floatconstant: { if (--radix < 0) fatal("number too long"); - if (isupper(c)) - c += ('a' - 'A'); *p++ = c; c = nextchar(); - } while (isdigit(c) || (c == '.') || (c == 'E') || (c == '+') || (c == '-')); + if (isupper(c)) + c = tolower(c); + } while (isdigit(c) || (c == '.') || (c == 'e') || (c == '+') || (c == '-')); peekc = c; *p = '\0'; - stringbuf = strdup(num); stringlen = p - num; + if (stringlen > maxstring) + { + maxstring = stringlen; + stringbuf = realloc(stringbuf, maxstring); + } + strcpy(stringbuf, num); return NUMBERF; } @@ -470,7 +477,6 @@ static int instring(int termc) { char* p; int c; - static int maxstring = 0; if (!maxstring) { diff --git a/mach/proto/as/comm7.c b/mach/proto/as/comm7.c index c9e340191..02a7c1d58 100644 --- a/mach/proto/as/comm7.c +++ b/mach/proto/as/comm7.c @@ -369,9 +369,21 @@ void emitstr(int zero) #define gen1 emit1 #include -void emitf(int size) +void emitf(int size, int negative) { - con_float(stringbuf, size); + char buffer[40]; + + if (stringlen > sizeof(buffer)-1) + fatal("floating point constant too long"); + + if (negative) + { + buffer[0] = '-'; + strcpy(buffer+1, stringbuf); + con_float(buffer, size); + } + else + con_float(stringbuf, size); } /* ---------- Error checked file I/O ---------- */ diff --git a/mach/proto/mcg/build.lua b/mach/proto/mcg/build.lua index 387d14d26..67c0645b5 100644 --- a/mach/proto/mcg/build.lua +++ b/mach/proto/mcg/build.lua @@ -35,7 +35,6 @@ definerule("build_mcg", "modules/src/data+lib", "modules/src/em_code+lib_k", "modules/src/em_data+lib", - "modules/src/flt_arith+lib", "modules/src/idf+lib", "modules/src/object+lib", "modules/src/read_em+lib_kv", diff --git a/mach/proto/mcg/data.c b/mach/proto/mcg/data.c index ff4ddb5bd..cbf1cd04f 100644 --- a/mach/proto/mcg/data.c +++ b/mach/proto/mcg/data.c @@ -1,13 +1,6 @@ #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) @@ -80,19 +73,7 @@ void data_float(const char* data, size_t size, bool is_ro) 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 #include #include -#include "flt_arith.h" #include "em_arith.h" #include "em_label.h" #include "em.h"