More properly keep track of register classes.

This commit is contained in:
David Given 2016-09-29 22:32:43 +02:00
parent b27758b7de
commit b32883b013
4 changed files with 27 additions and 4 deletions

View file

@ -3,6 +3,7 @@
#include <string.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>
#include <limits.h>
#include "iburg.h"

View file

@ -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);

View file

@ -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 */
};

View file

@ -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