From b32883b0131abaf9c9c0e4eab3672edf5ccd8a69 Mon Sep 17 00:00:00 2001 From: David Given Date: Thu, 29 Sep 2016 22:32:43 +0200 Subject: [PATCH] More properly keep track of register classes. --- util/mcgg/gram.y | 1 + util/mcgg/iburg.c | 21 +++++++++++++++++---- util/mcgg/iburg.h | 1 + util/mcgg/mcgg.h | 8 ++++++++ 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/util/mcgg/gram.y b/util/mcgg/gram.y index 177f33d72..26a0e9b5b 100644 --- a/util/mcgg/gram.y +++ b/util/mcgg/gram.y @@ -3,6 +3,7 @@ #include #include #include +#include #include #include "iburg.h" diff --git a/util/mcgg/iburg.c b/util/mcgg/iburg.c index 1fc0a7c22..fa3d7d0b1 100644 --- a/util/mcgg/iburg.c +++ b/util/mcgg/iburg.c @@ -289,6 +289,8 @@ void addregclass(struct reg* reg, const char* id) p->link = *q; *q = p; } + + reg->classes |= 1<<(p->number); } struct regclass* getregclass(const char* id) @@ -437,12 +439,19 @@ static void print(char* fmt, ...) case 'd': fprintf(outfp, "%d", va_arg(ap, int)); break; + + case 'x': + fprintf(outfp, "%x", va_arg(ap, uint32_t)); + break; + case 's': fputs(va_arg(ap, char*), outfp); break; + case 'P': fprintf(outfp, "%s_", prefix); break; + case 'T': { Tree t = va_arg(ap, Tree); @@ -453,15 +462,18 @@ static void print(char* fmt, ...) print("(%T)", t->left); break; } + case 'R': { Rule r = va_arg(ap, Rule); print("%S: %T", r->lhs, r->pattern); break; } + case 'S': fputs(va_arg(ap, Term)->name, outfp); break; + case '1': case '2': case '3': @@ -473,6 +485,7 @@ static void print(char* fmt, ...) putc('\t', outfp); break; } + default: putc(*fmt, outfp); break; @@ -530,14 +543,14 @@ static void emitregisterclasses(struct regclass* rc) static void emitregisters(struct reg* r) { int k = 0; - print("const char* %Pregister_names[] = {\n"); + print("const struct %Pregister_data %Pregister_data[] = {\n"); while (r) { for (; k < r->number; k++) - print("%1NULL,\n"); + print("%1{ 0 },\n"); k++; - print("%1\"%s\",\n", r->name); + print("%1{ \"%s\", %d },\n", r->name, r->classes); r = r->link; } print("};\n\n"); @@ -659,7 +672,7 @@ static void emitdefs(Nonterm nts, int ntnumber) for (p = nts; p; p = p->link) print("#define %P%S_NT %d\n", p, p->number); - print("static const int %Pmax_nt = %d;\n\n", ntnumber); + print("#define %Pmax_nt %d\n\n", ntnumber); print("const char *%Pntname[] = {\n%10,\n"); for (p = nts; p; p = p->link) print("%1\"%S\",\n", p); diff --git a/util/mcgg/iburg.h b/util/mcgg/iburg.h index 5709ae13e..7bf8b8a0e 100644 --- a/util/mcgg/iburg.h +++ b/util/mcgg/iburg.h @@ -20,6 +20,7 @@ struct reg const char* name; /* register name */ Kind kind; /* REG */ int number; /* identifying number */ + uint32_t classes; // bitfield of classes */ struct reg* link; /* next in list */ }; diff --git a/util/mcgg/mcgg.h b/util/mcgg/mcgg.h index 0bbe4ae93..a2f20b4b4 100644 --- a/util/mcgg/mcgg.h +++ b/util/mcgg/mcgg.h @@ -46,6 +46,14 @@ struct burm_instruction_data }; extern const struct burm_instruction_data burm_instruction_data[]; + +struct burm_register_data +{ + const char* name; + uint32_t classes; +}; + +extern const struct burm_register_data burm_register_data[]; extern const char* burm_register_class_names[]; #endif