shithub: mc

Download patch

ref: b2fa7003bf8809ce27699c88eecce4b55618dd5f
parent: 1692dfdd9688c970e0b5fb1def9758b229bc1402
author: Ori Bernstein <[email protected]>
date: Mon Jul 30 22:20:01 EDT 2012

Waste less space in unions.

--- a/6/asm.h
+++ b/6/asm.h
@@ -1,4 +1,5 @@
 #define Maxarg 4        /* maximum number of args an insn can have */
+#define Wordsz 4        /* the size of a "natural int" */
 #define Ptrsz 8         /* the size of a machine word (ie, pointer size) */
 #define K 14            /* the number of allocatable registers */
 
--- a/6/simp.c
+++ b/6/simp.c
@@ -54,6 +54,7 @@
 
 /* useful constants */
 static Type *tyintptr;
+static Type *tyword;
 static Type *tyvoid;
 
 static Type *base(Type *t)
@@ -151,6 +152,15 @@
     return n;
 }
 
+static Node *word(int line, uint v)
+{
+    Node *n;
+
+    n = mkintlit(line, v);
+    n->expr.type = tyword;
+    return n;
+}
+
 static size_t did(Node *n)
 {
     if (n->type == Ndecl) {
@@ -435,10 +445,10 @@
     Ucon *uc;
 
     if (exprop(n) != Ocons)
-        return load(add(addr(n, tyintptr), disp(n->line, off)));
+        return load(addk(addr(n, mkty(n->line, Tyuint)), off));
 
     uc = finducon(n);
-    return disp(uc->line, uc->id);
+    return word(uc->line, uc->id);
 }
 
 static Node *uval(Node *n, size_t off, Type *t)
@@ -486,7 +496,7 @@
             r = mkexpr(a->line, Oeq, x, y, NULL);
             r->expr.type = tyintptr;
             if (uc->etype) {
-                off += Ptrsz;
+                off += Wordsz;
                 v = ucompare(s, a, b, uc->etype, off);
                 r = mkexpr(a->line, Oland, r, v, NULL);
                 r->expr.type = tyintptr;
@@ -910,14 +920,19 @@
         tmp = dst;
     else
         tmp = temp(s, n);
-    u = addr(tmp, exprtype(n));
-    tag = disp(n->line, uc->id);
+
+    /* Set the tag on the ucon */
+    u = addr(tmp, mkty(n->line, Tyuint));
+    tag = mkintlit(n->line, uc->id);
+    tag->expr.type = mkty(n->line, Tyuint);
     append(s, store(u, tag));
+
+
+    /* fill the value, if needed */
     if (!uc->etype)
         return tmp;
-
     elt = rval(s, n->expr.args[1], NULL);
-    u = addk(u, Ptrsz);
+    u = addk(u, Wordsz);
     if (stacktype(uc->etype)) {
         elt = addr(elt, uc->etype);
         sz = disp(n->line, tysize(uc->utype));
@@ -1300,6 +1315,7 @@
 
     /* declare useful constants */
     tyintptr = mkty(-1, Tyuint64);
+    tyword = mkty(-1, Tyuint);
     tyvoid = mkty(-1, Tyvoid);
 
     fn = NULL;