aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Preud'homme <thomas.preudhomme@celest.fr>2010-05-06 02:19:00 +0200
committerThomas Preud'homme <thomas.preudhomme@celest.fr>2010-05-06 02:20:35 +0200
commit8eb86ab78d19cc9e97b09cd6107397221552817d (patch)
treeafffd4512483a57b718a006d5abab6531dc98efb
parent2220467fcf27dbdf6b0d6d8cc56eb65bc35a78ab (diff)
downloadtinycc-8eb86ab78d19cc9e97b09cd6107397221552817d.tar.gz
tinycc-8eb86ab78d19cc9e97b09cd6107397221552817d.tar.bz2
Add nan, snan and inf float constants
-rw-r--r--tccgen.c25
-rw-r--r--tcctok.h9
2 files changed, 32 insertions, 2 deletions
diff --git a/tccgen.c b/tccgen.c
index 6c8faa6..bf171fb 100644
--- a/tccgen.c
+++ b/tccgen.c
@@ -310,6 +310,16 @@ static void vpushll(long long v)
vsetc(&ctype, VT_CONST, &cval);
}
+/* push arbitrary 64bit constant */
+void vpush64(int ty, unsigned long long v)
+{
+ CValue cval;
+ CType ctype;
+ ctype.t = ty;
+ cval.ull = v;
+ vsetc(&ctype, VT_CONST, &cval);
+}
+
/* Return a static symbol pointing to a section */
ST_FUNC Sym *get_sym_ref(CType *type, Section *sec, unsigned long offset, unsigned long size)
{
@@ -3535,6 +3545,21 @@ ST_FUNC void unary(void)
vtop->sym = s;
next();
break;
+
+ // special qnan , snan and infinity values
+ case TOK___NAN__:
+ vpush64(VT_DOUBLE, 0x7ff8000000000000);
+ next();
+ break;
+ case TOK___SNAN__:
+ vpush64(VT_DOUBLE, 0x7ff0000000000001);
+ next();
+ break;
+ case TOK___INF__:
+ vpush64(VT_DOUBLE, 0x7ff0000000000000);
+ next();
+ break;
+
default:
tok_identifier:
t = tok;
diff --git a/tcctok.h b/tcctok.h
index 02ac767..28c4236 100644
--- a/tcctok.h
+++ b/tcctok.h
@@ -81,10 +81,15 @@
DEF(TOK___TIME__, "__TIME__")
DEF(TOK___FUNCTION__, "__FUNCTION__")
DEF(TOK___VA_ARGS__, "__VA_ARGS__")
-
+
/* special identifiers */
DEF(TOK___FUNC__, "__func__")
-
+
+/* special floating point values */
+ DEF(TOK___NAN__, "__nan__")
+ DEF(TOK___SNAN__, "__snan__")
+ DEF(TOK___INF__, "__inf__")
+
/* attribute identifiers */
/* XXX: handle all tokens generically since speed is not critical */
DEF(TOK_SECTION1, "section")