mcg now uses dataf4 and dataf8 to emit floating point constants, and so doesn't
authorDavid Given <dg@cowlark.com>
Wed, 12 Sep 2018 21:19:32 +0000 (23:19 +0200)
committerDavid Given <dg@cowlark.com>
Wed, 12 Sep 2018 21:19:32 +0000 (23:19 +0200)
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.

mach/proto/as/comm1.h
mach/proto/as/comm2.y
mach/proto/as/comm5.c
mach/proto/as/comm7.c
mach/proto/mcg/build.lua
mach/proto/mcg/data.c
mach/proto/mcg/mcg.h

index 47f4302..206ae0b 100644 (file)
@@ -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 *);
index 0643928..3e1229a 100644 (file)
@@ -280,17 +280,22 @@ datalist
                        }
        ;
 
-dataflist
-       :   NUMBERF
+numberf
+       :       NUMBERF
                        {
-                               emitf((int)$<y_word>0);
+                               emitf((int)$<y_word>-1, 0);
                        }
-       |   dataflist ',' NUMBERF
+       |       '-' NUMBERF
                        {
-                               emitf((int)$<y_word>3);
+                               emitf((int)$<y_word>-1, 1);
                        }
        ;
 
+dataflist
+       :   numberf
+       |   dataflist ',' numberf
+       ;
+
 expr   :       error
                        {       serror("expr syntax err");
                                $$.val = 0; $$.typ = S_UND;
index 9dc7a80..0b448ef 100644 (file)
@@ -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)
        {
index c9e3401..02a7c1d 100644 (file)
@@ -369,9 +369,21 @@ void emitstr(int zero)
 #define gen1 emit1
 #include <con_float>
 
-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  ---------- */
index 387d14d..67c0645 100644 (file)
@@ -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",
index ff4ddb5..cbf1cd0 100644 (file)
@@ -1,13 +1,6 @@
 #include "mcg.h"
 #include <ctype.h>
 
-#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<size; i++)
-    {
-        fprintf(outputfile, ", ");
-        writehex(buffer[i], 1);
-    }
-    fprintf(outputfile, "\n");
+    fprintf(outputfile, "\t.dataf%d %s\n", size, data);
 }
 
 static bool istext(c)
index b813b79..dd810e4 100644 (file)
@@ -8,7 +8,6 @@
 #include <stdint.h>
 #include <string.h>
 #include <assert.h>
-#include "flt_arith.h"
 #include "em_arith.h"
 #include "em_label.h"
 #include "em.h"