mcgg now checks that registers have at most one type attribute set.
authorDavid Given <dg@cowlark.com>
Mon, 3 Sep 2018 20:03:57 +0000 (22:03 +0200)
committerDavid Given <dg@cowlark.com>
Mon, 3 Sep 2018 20:03:57 +0000 (22:03 +0200)
util/mcgg/iburg.c
util/mcgg/ircodes.h

index 0477f21..9979627 100644 (file)
 #include "smap.h"
 #include "mcgg.h"
 
-static char rcsid[] = "$Id$";
+#define REGATTR_INT 0
+#define REGATTR_LONG 1
+#define REGATTR_FLOAT 2
+#define REGATTR_DOUBLE 3
 
 int maxcost = SHRT_MAX / 2;
 
@@ -162,6 +165,18 @@ int main(int argc, char* argv[])
                rule(&reg, tree(&NOPL, tree(&reg, NULL, NULL), NULL))->cost = 1;
                rule(&reg, tree(&NOPD, tree(&reg, NULL, NULL), NULL))->cost = 1;
                rule(NULL, tree(&RET, NULL, NULL))->cost = 1;
+
+       }
+
+       {
+               struct regattr* attr = makeregattr("int");
+               assert(attr->number == REGATTR_INT);
+               attr = makeregattr("long");
+               assert(attr->number == REGATTR_LONG);
+               attr = makeregattr("float");
+               assert(attr->number == REGATTR_FLOAT);
+               attr = makeregattr("double");
+               assert(attr->number == REGATTR_DOUBLE);
        }
 
        yyin = infp;
@@ -612,7 +627,8 @@ static void emitregisterattrs(void)
                assert(rc->number == i);
 
                print("%1\"%s\",\n", rc->name);
-               printh("#define %P%s_ATTR (1U<<%d)\n", rc->name, rc->number);
+               if (rc->number > REGATTR_DOUBLE)
+                       printh("#define %P%s_ATTR (1U<<%d)\n", rc->name, rc->number);
        }
        print("};\n\n");
        printh("\n");
@@ -655,7 +671,10 @@ static void emitregisters(void)
        for (i=0; i<registers.count; i++)
        {
                struct reg* r = registers.item[i].right;
+               uint32_t type = r->attrs & TYPE_ATTRS;
                assert(r->number == i);
+               if (type & (type-1))
+                       yyerror("register %s has more than one type attribute set", r->name);
 
                print("%1{ \"%s\", 0x%x, %Pregister_names_%d_%s, %Pregister_aliases_%d_%s },\n",
                        r->name, r->attrs, i, r->name, i, r->name);
index d9c0512..16be32a 100644 (file)
@@ -17,6 +17,11 @@ struct ir_data
 
 extern const struct ir_data ir_data[];
 
+#define burm_int_ATTR (1U<<0)
+#define burm_long_ATTR (1U<<1)
+#define burm_float_ATTR (1U<<2)
+#define burm_double_ATTR (1U<<3)
+
 #define TYPE_ATTRS \
     (burm_int_ATTR | burm_long_ATTR | burm_float_ATTR | burm_double_ATTR)