static int nrules;
static SMAPOF(struct reg) registers;
-static SMAPOF(struct regclass) registerclasses;
+static SMAPOF(struct regattr) registerattrs;
static void print(char* fmt, ...);
static void ckreach(Nonterm p);
static void registerterminals(void);
+static struct regattr* makeregattr(const char* id);
static void emitclosure(Nonterm nts);
static void emitcost(Tree t, const char* v);
static void emitcostcalc(Rule r);
static void emitnts(Rule rules, int nrules);
static void emitpredicatedefinitions(Rule rules);
static void emitrecord(char* pre, Rule r, int cost);
-static void emitregisterclasses();
+static void emitregisterattrs();
static void emitregisters();
static void emitrule(Nonterm nts);
static void emitstate(Term terms, Nonterm start, int ntnumber);
registerterminals();
start = nonterm("stmt", true);
+ makeregattr("bytes1");
+ makeregattr("bytes2");
+ makeregattr("bytes4");
+ makeregattr("bytes8");
yyin = infp;
yyparse();
yyerror("can't reach non-terminal `%s'\n", p->name);
#endif
- emitregisterclasses();
+ emitregisterattrs();
emitregisters();
emitdefs(nts, ntnumber);
emitstruct(nts, ntnumber);
struct term t;
struct nonterm nt;
struct reg r;
- struct regclass rc;
+ struct regattr rc;
} sym;
struct entry* link;
} * table[211];
struct reg* makereg(const char* id)
{
struct reg* p = smap_get(®isters, id);
- static int number = 1;
+ static int number = 0;
if (p)
yyerror("redefinition of '%s'", id);
return p;
}
-void addregclass(struct reg* reg, const char* id)
+struct regattr* makeregattr(const char* id)
{
- struct regclass* p = smap_get(®isterclasses, id);
- static int number = 1;
+ struct regattr* p = smap_get(®isterattrs, id);
+ static int number = 0;
+
+ if (p)
+ yyerror("redefinition of '%s'", id);
+ p = calloc(1, sizeof(*p));
+ p->name = id;
+ p->number = number++;
+ smap_put(®isterattrs, id, p);
+
+ return p;
+}
+
+void addregattr(struct reg* reg, const char* id)
+{
+ struct regattr* p = smap_get(®isterattrs, id);
if (!p)
- {
- p = calloc(1, sizeof(*p));
- p->name = id;
- p->number = number++;
- smap_put(®isterclasses, id, p);
- }
+ p = makeregattr(id);
- reg->classes |= 1<<(p->number);
+ reg->attrs |= 1<<(p->number);
}
-struct regclass* getregclass(const char* id)
+struct regattr* getregattr(const char* id)
{
- struct regclass* p = smap_get(®isterclasses, id);
+ struct regattr* p = smap_get(®isterattrs, id);
if (!p)
yyerror("'%s' is not the name of a register class", id);
return p;
p->name, p->esn);
p->link = *q;
*q = p;
-
- if (esn != -1)
- print("enum { %s = %d };\n", id, esn);
return p;
}
fprintf(outfp, "%x", va_arg(ap, uint32_t));
break;
- case 'X':
- fprintf(outfp, "0x%" PRIx64 "ULL", va_arg(ap, uint64_t));
- break;
-
case 's':
fputs(va_arg(ap, char*), outfp);
break;
reach(r->pattern);
}
-static void emitregisterclasses(void)
+static void emitregisterattrs(void)
{
int i;
print("const char* %Pregister_class_names[] = {\n");
- print("%1NULL,\n"); /* register class id 0 is invalid */
- for (i=0; i<registerclasses.count; i++)
+ for (i=0; i<registerattrs.count; i++)
{
- struct regclass* rc = registerclasses.item[i].right;
- assert(rc->number == (i+1));
+ struct regattr* rc = registerattrs.item[i].right;
+ assert(rc->number == i);
print("%1\"%s\",\n", rc->name);
}
int i;
print("const struct %Pregister_data %Pregister_data[] = {\n");
- print("%1{ 0 },\n"); /* register id 0 is invalid */
for (i=0; i<registers.count; i++)
{
struct reg* r = registers.item[i].right;
- assert(r->number == (i+1));
+ assert(r->number == i);
- print("%1{ \"%s\", %X },\n", r->name, r->classes);
+ print("%1{ \"%s\", 0x%x },\n", r->name, r->attrs);
}
+ print("%1{ NULL }\n");
print("};\n\n");
}
Term p;
int k;
+ print("enum {\n");
+ for (k = 0, p = terms; p; p = p->link)
+ print("%1%S = %d,\n", p, p->esn);
+ print("};\n\n");
+
print("static const char %Parity[] = {\n");
for (k = 0, p = terms; p; p = p->link)
{
{
const char* name; /* register name */
int number; /* identifying number */
- uint64_t classes; // bitfield of classes */
+ uint32_t attrs; /* bitfield of register attributes */
};
-struct regclass
+struct regattr
{
const char* name; /* class name */
int number; /* identifying number */
};
extern struct reg* makereg(const char* name);
-extern void addregclass(struct reg* reg, const char* regclass);
-extern struct regclass* getregclass(const char* name);
+extern void addregattr(struct reg* reg, const char* regattr);
+extern struct regattr* getregattr(const char* name);
struct term
{ /* terminals: */
Rule chain; /* chain rules w/non-terminal on rhs */
Nonterm link; /* next terminal in number order */
bool is_fragment; /* these instructions are all fragments */
- struct regclass* allocate; /* allocate this kind of register */
+ struct regattr* allocate; /* allocate this kind of register */
};
extern void* lookup(const char* name);
extern Nonterm nonterm(const char* id, bool allocate);