2016-09-20 18:37:16 +00:00
|
|
|
#ifndef BURG_INCLUDED
|
|
|
|
#define BURG_INCLUDED
|
|
|
|
|
2016-10-09 10:32:36 +00:00
|
|
|
#include "em_arith.h"
|
2016-09-25 10:18:39 +00:00
|
|
|
#include "stringlist.h"
|
2016-10-01 11:56:52 +00:00
|
|
|
#include "array.h"
|
2016-09-20 22:43:10 +00:00
|
|
|
|
2016-09-25 10:18:39 +00:00
|
|
|
extern char* stringf(char* fmt, ...);
|
2016-09-20 18:37:16 +00:00
|
|
|
|
2016-09-20 19:00:16 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
TERM = 1,
|
2016-09-25 20:17:14 +00:00
|
|
|
NONTERM,
|
|
|
|
REG,
|
|
|
|
REGCLASS
|
2016-09-20 19:00:16 +00:00
|
|
|
} Kind;
|
|
|
|
typedef struct rule* Rule;
|
|
|
|
typedef struct term* Term;
|
2016-09-25 20:17:14 +00:00
|
|
|
|
2016-10-02 19:51:25 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
CONSTRAINT_ATTR,
|
|
|
|
CONSTRAINT_EQUALS,
|
|
|
|
CONSTRAINT_NOTEQUALS
|
|
|
|
};
|
|
|
|
|
|
|
|
struct constraint
|
|
|
|
{
|
|
|
|
int type;
|
|
|
|
const char* left;
|
|
|
|
const char* right;
|
|
|
|
struct constraint* next;
|
|
|
|
};
|
|
|
|
|
2016-10-09 10:32:36 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PREDICATE_FUNCTION,
|
|
|
|
PREDICATE_NODE,
|
|
|
|
PREDICATE_NUMBER
|
|
|
|
};
|
|
|
|
|
2016-10-01 11:56:52 +00:00
|
|
|
struct expr
|
|
|
|
{
|
2016-10-09 10:32:36 +00:00
|
|
|
int type;
|
2016-10-01 11:56:52 +00:00
|
|
|
struct expr* next;
|
2016-10-09 10:32:36 +00:00
|
|
|
union
|
|
|
|
{
|
|
|
|
const char* name;
|
|
|
|
arith number;
|
|
|
|
} u;
|
2016-10-01 11:56:52 +00:00
|
|
|
};
|
|
|
|
|
2016-10-01 10:17:14 +00:00
|
|
|
struct terminfo
|
|
|
|
{
|
|
|
|
const char* name;
|
|
|
|
const char* label;
|
2016-10-05 20:56:25 +00:00
|
|
|
const char* attr;
|
2016-10-01 10:17:14 +00:00
|
|
|
};
|
|
|
|
|
2016-09-25 20:17:14 +00:00
|
|
|
struct reg
|
|
|
|
{
|
|
|
|
const char* name; /* register name */
|
|
|
|
int number; /* identifying number */
|
2016-10-05 19:00:28 +00:00
|
|
|
uint32_t attrs; /* bitfield of register attributes */
|
2016-10-12 20:58:46 +00:00
|
|
|
uint32_t type; /* register type */
|
2016-09-25 20:17:14 +00:00
|
|
|
};
|
|
|
|
|
2016-10-05 19:00:28 +00:00
|
|
|
struct regattr
|
2016-09-25 20:17:14 +00:00
|
|
|
{
|
|
|
|
const char* name; /* class name */
|
|
|
|
int number; /* identifying number */
|
|
|
|
};
|
|
|
|
|
|
|
|
extern struct reg* makereg(const char* name);
|
2016-10-12 20:58:46 +00:00
|
|
|
extern void addregattr(struct reg* reg, const char* regattr, bool exact);
|
2016-10-05 19:00:28 +00:00
|
|
|
extern struct regattr* getregattr(const char* name);
|
2016-09-25 20:17:14 +00:00
|
|
|
|
2016-09-20 19:00:16 +00:00
|
|
|
struct term
|
|
|
|
{ /* terminals: */
|
|
|
|
char* name; /* terminal name */
|
|
|
|
Kind kind; /* TERM */
|
|
|
|
int esn; /* external symbol number */
|
|
|
|
int arity; /* operator arity */
|
|
|
|
Term link; /* next terminal in esn order */
|
|
|
|
Rule rules; /* rules whose pattern starts with term */
|
2016-09-20 18:37:16 +00:00
|
|
|
};
|
|
|
|
|
2016-09-20 19:00:16 +00:00
|
|
|
typedef struct nonterm* Nonterm;
|
|
|
|
struct nonterm
|
|
|
|
{ /* non-terminals: */
|
2016-09-25 20:17:14 +00:00
|
|
|
char* name; /* non-terminal name */
|
|
|
|
Kind kind; /* NONTERM */
|
|
|
|
int number; /* identifying number */
|
|
|
|
int lhscount; /* # times nt appears in a rule lhs */
|
|
|
|
int reached; /* 1 iff reached from start non-terminal */
|
|
|
|
Rule rules; /* rules w/non-terminal on lhs */
|
|
|
|
Rule chain; /* chain rules w/non-terminal on rhs */
|
|
|
|
Nonterm link; /* next terminal in number order */
|
|
|
|
bool is_fragment; /* these instructions are all fragments */
|
2016-09-20 18:37:16 +00:00
|
|
|
};
|
2016-09-25 20:17:14 +00:00
|
|
|
extern void* lookup(const char* name);
|
|
|
|
extern Nonterm nonterm(const char* id, bool allocate);
|
2016-09-24 10:11:30 +00:00
|
|
|
extern Term term(const char* id, int esn);
|
2016-09-20 18:37:16 +00:00
|
|
|
|
2016-09-20 19:00:16 +00:00
|
|
|
typedef struct tree* Tree;
|
|
|
|
struct tree
|
|
|
|
{ /* tree patterns: */
|
2016-09-24 10:11:30 +00:00
|
|
|
void* op; /* a terminal or non-terminal */
|
|
|
|
const char* label; /* user label for this node */
|
|
|
|
Tree left, right; /* operands */
|
|
|
|
int nterms; /* number of terminal nodes in this tree */
|
2016-10-09 13:09:34 +00:00
|
|
|
struct regattr* attr; /* input register attribute */
|
2016-09-20 18:37:16 +00:00
|
|
|
};
|
2016-10-05 20:56:25 +00:00
|
|
|
extern Tree tree(const struct terminfo* ti, Tree left, Tree right);
|
2016-09-20 18:37:16 +00:00
|
|
|
|
2016-09-20 19:00:16 +00:00
|
|
|
struct rule
|
|
|
|
{ /* rules: */
|
2016-09-25 10:18:39 +00:00
|
|
|
Nonterm lhs; /* lefthand side non-terminal */
|
|
|
|
Tree pattern; /* rule pattern */
|
|
|
|
int lineno; /* line number where allocated */
|
|
|
|
int ern; /* external rule number */
|
|
|
|
int packed; /* packed external rule number */
|
|
|
|
int cost; /* associated cost */
|
2016-10-05 20:56:25 +00:00
|
|
|
const char* label; /* label for LHS */
|
|
|
|
struct regattr* attr; /* register attribute of result */
|
2016-09-25 10:18:39 +00:00
|
|
|
Rule link; /* next rule in ern order */
|
|
|
|
Rule next; /* next rule with same pattern root */
|
|
|
|
Rule chain; /* next chain rule with same rhs */
|
|
|
|
Rule decode; /* next rule with same lhs */
|
|
|
|
Rule kids; /* next rule with same burm_kids pattern */
|
2016-10-02 19:51:25 +00:00
|
|
|
ARRAYOF(struct expr) prefers; /* C predicates */
|
|
|
|
ARRAYOF(struct expr) requires; /* C predicates */
|
|
|
|
ARRAYOF(struct constraint) constraints; /* register constraints */
|
2016-09-25 10:18:39 +00:00
|
|
|
struct stringlist code; /* compiler output code strings */
|
2016-09-20 18:37:16 +00:00
|
|
|
};
|
2016-10-05 20:56:25 +00:00
|
|
|
extern Rule rule(const struct terminfo* ti, Tree pattern);
|
2016-09-20 19:00:16 +00:00
|
|
|
extern int maxcost; /* maximum cost */
|
2016-09-20 18:37:16 +00:00
|
|
|
|
|
|
|
/* gram.y: */
|
2016-09-20 19:00:16 +00:00
|
|
|
void yyerror(char* fmt, ...);
|
2016-09-20 18:37:16 +00:00
|
|
|
int yyparse(void);
|
2016-09-20 19:00:16 +00:00
|
|
|
void yywarn(char* fmt, ...);
|
2016-09-20 18:37:16 +00:00
|
|
|
extern int errcnt;
|
2016-09-20 19:00:16 +00:00
|
|
|
extern FILE* infp;
|
|
|
|
extern FILE* outfp;
|
2016-09-20 18:37:16 +00:00
|
|
|
|
2016-09-20 22:43:10 +00:00
|
|
|
/* Stupid flex imports --- why mo header file? */
|
|
|
|
|
|
|
|
extern FILE* yyin;
|
|
|
|
extern int yylineno;
|
|
|
|
|
|
|
|
extern void printlineno(void);
|
|
|
|
|
2016-09-24 20:46:08 +00:00
|
|
|
#include "mcgg.h"
|
2016-09-24 16:31:35 +00:00
|
|
|
|
2016-09-20 18:37:16 +00:00
|
|
|
#endif
|