summary refs log tree commit diff
path: root/lisc
diff options
context:
space:
mode:
Diffstat (limited to 'lisc')
-rw-r--r--lisc/lisc.h7
-rw-r--r--lisc/parse.c68
-rw-r--r--lisc/test/double.ssa8
3 files changed, 52 insertions, 31 deletions
diff --git a/lisc/lisc.h b/lisc/lisc.h
index 815c016..05c1977 100644
--- a/lisc/lisc.h
+++ b/lisc/lisc.h
@@ -383,9 +383,10 @@ struct Con {
 	char label[NString];
 	union {
 		int64_t i;
-		double f;
+		double d;
+		float s;
 	} bits;
-	char flt;
+	char flt; /* 1 for single precision, 2 for double */
 	char emit;
 };
 
@@ -440,6 +441,8 @@ struct Dat {
 	} type;
 	union {
 		int64_t num;
+		double fltd;
+		float flts;
 		char *str;
 	} u;
 };
diff --git a/lisc/parse.c b/lisc/parse.c
index 9b820e4..5e84350 100644
--- a/lisc/parse.c
+++ b/lisc/parse.c
@@ -91,7 +91,8 @@ enum {
 	TS,
 
 	TInt,
-	TFlt,
+	TFlts,
+	TFltd,
 	TTmp,
 	TLbl,
 	TGlo,
@@ -111,7 +112,8 @@ enum {
 static FILE *inf;
 static int thead;
 static struct {
-	double flt;
+	double fltd;
+	float flts;
 	int64_t num;
 	char *str;
 } tokval;
@@ -165,12 +167,13 @@ lex()
 		{ 0, TXXX }
 	};
 	static char tok[NString];
-	int c, i;
+	int c, c1, i;
 	int t;
 
 	do
 		c = fgetc(inf);
 	while (isblank(c));
+	t = TXXX;
 	switch (c) {
 	case EOF:
 		return TEOF;
@@ -186,10 +189,24 @@ lex()
 		return TRBrace;
 	case '=':
 		return TEq;
-	case '`':
-		if (fscanf(inf, "%lf", &tokval.flt) != 1)
+	case 's':
+		c1 = fgetc(inf);
+		if (c1 != '_') {
+			ungetc(c1, inf);
+			break;
+		}
+		if (fscanf(inf, "%f", &tokval.flts) != 1)
+			err("invalid floating point literal");
+		return TFlts;
+	case 'd':
+		c1 = fgetc(inf);
+		if (c1 != '_') {
+			ungetc(c1, inf);
+			break;
+		}
+		if (fscanf(inf, "%lf", &tokval.fltd) != 1)
 			err("invalid floating point literal");
-		return TFlt;
+		return TFltd;
 	case '%':
 		t = TTmp;
 		goto Alpha;
@@ -226,7 +243,6 @@ lex()
 			tokval.str[i] = c;
 		}
 	}
-	t = TXXX;
 	if (0)
 Alpha:		c = fgetc(inf);
 	if (!isalpha(c) && c != '.')
@@ -337,11 +353,16 @@ parseref()
 		c.type = CBits;
 		c.bits.i = tokval.num;
 		goto Look;
-	case TFlt:
+	case TFlts:
 		c.type = CBits;
-		c.bits.f = tokval.flt;
+		c.bits.s = tokval.flts;
 		c.flt = 1;
 		goto Look;
+	case TFltd:
+		c.type = CBits;
+		c.bits.d = tokval.fltd;
+		c.flt = 2;
+		goto Look;
 	case TGlo:
 		c.type = CAddr;
 		strcpy(c.label, tokval.str);
@@ -740,8 +761,6 @@ static void
 parsedat(void cb(Dat *))
 {
 	char s[NString];
-	float fs;
-	double fd;
 	int t;
 	Dat d;
 
@@ -780,23 +799,20 @@ parsedat(void cb(Dat *))
 			case TD: d.type = DL; break;
 			}
 			t = nextnl();
-			if (t != TInt && t != TFlt)
-				err("number expected");
 			do {
 
-				if (t == TFlt) {
-					fd = tokval.flt;
-					fs = tokval.flt;
-					d.u.num = 0;
-					if (d.type == DL)
-						memcpy(&d.u.num, &fd, sizeof fd);
-					else
-						memcpy(&d.u.num, &fs, sizeof fs);
-				} else
+				memset(&d.u, 0, sizeof d.u);
+				if (t == TFlts)
+					d.u.flts = tokval.flts;
+				else if (t == TFltd)
+					d.u.fltd = tokval.fltd;
+				else if (t == TInt)
 					d.u.num = tokval.num;
+				else
+					err("constant literal expected");
 				cb(&d);
 				t = nextnl();
-			} while (t == TInt || t == TFlt);
+			} while (t == TInt || t == TFlts || t == TFltd);
 			if (t == TRBrace)
 				break;
 			if (t != TComma)
@@ -845,8 +861,10 @@ printcon(Con *c, FILE *f)
 			fprintf(f, "%+"PRIi64, c->bits.i);
 		break;
 	case CBits:
-		if (c->flt)
-			fprintf(f, "`%lf", c->bits.f);
+		if (c->flt == 1)
+			fprintf(f, "s_%f", c->bits.s);
+		else if (c->flt == 2)
+			fprintf(f, "d_%lf", c->bits.d);
 		else
 			fprintf(f, "%"PRIi64, c->bits.i);
 		break;
diff --git a/lisc/test/double.ssa b/lisc/test/double.ssa
index 7c8cb2a..9fc2e90 100644
--- a/lisc/test/double.ssa
+++ b/lisc/test/double.ssa
@@ -1,15 +1,15 @@
 function $test() {
 @start
-	%x1 =d copy `0.1
-	%x2 =d add `0.2, %x1
-	%x3 =d sub %x2, `0.3
+	%x1 =d copy d_0.1
+	%x2 =d add d_0.2, %x1
+	%x3 =d sub %x2, d_0.3
 
 @loop
 	%x4 =d phi @start %x3, @loop %x5
 	%i1 =w phi @start 0, @loop %i2
 	%x5 =d add %x4, %x4
 	%i2 =w add %i1, 1
-	%c0 =w cled %x5, `1
+	%c0 =w cled %x5, d_1
 	jnz %c0, @loop, @end
 
 @end