From 83cf1be6a8b02e92220c976be5c27ce22e8f9853 Mon Sep 17 00:00:00 2001 From: David Given Date: Mon, 3 Sep 2018 22:03:57 +0200 Subject: [PATCH] mcgg now checks that registers have at most one type attribute set. --- util/mcgg/iburg.c | 23 +++++++++++++++++++++-- util/mcgg/ircodes.h | 5 +++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/util/mcgg/iburg.c b/util/mcgg/iburg.c index 0477f216b..9979627c0 100644 --- a/util/mcgg/iburg.c +++ b/util/mcgg/iburg.c @@ -16,7 +16,10 @@ #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(®, tree(&NOPL, tree(®, NULL, NULL), NULL))->cost = 1; rule(®, tree(&NOPD, tree(®, 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; iattrs & 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); diff --git a/util/mcgg/ircodes.h b/util/mcgg/ircodes.h index d9c05126f..16be32a5b 100644 --- a/util/mcgg/ircodes.h +++ b/util/mcgg/ircodes.h @@ -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)