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.
This commit is contained in:
parent
8105281534
commit
642956fa2f
|
@ -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 *);
|
||||
|
|
|
@ -280,15 +280,20 @@ datalist
|
|||
}
|
||||
;
|
||||
|
||||
numberf
|
||||
: NUMBERF
|
||||
{
|
||||
emitf((int)$<y_word>-1, 0);
|
||||
}
|
||||
| '-' NUMBERF
|
||||
{
|
||||
emitf((int)$<y_word>-1, 1);
|
||||
}
|
||||
;
|
||||
|
||||
dataflist
|
||||
: NUMBERF
|
||||
{
|
||||
emitf((int)$<y_word>0);
|
||||
}
|
||||
| dataflist ',' NUMBERF
|
||||
{
|
||||
emitf((int)$<y_word>3);
|
||||
}
|
||||
: numberf
|
||||
| dataflist ',' numberf
|
||||
;
|
||||
|
||||
expr : error
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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 ---------- */
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue