mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-11-23 16:19:52 +00:00
Eliminate tabs and trailing spaces
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21441 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -94,7 +94,7 @@ public:
|
|||||||
/// are to match.
|
/// are to match.
|
||||||
///
|
///
|
||||||
bool debugPassMiscompilation(const PassInfo *ThePass,
|
bool debugPassMiscompilation(const PassInfo *ThePass,
|
||||||
const std::string &ReferenceOutput);
|
const std::string &ReferenceOutput);
|
||||||
|
|
||||||
/// compileSharedObject - This method creates a SharedObject from a given
|
/// compileSharedObject - This method creates a SharedObject from a given
|
||||||
/// BytecodeFile for debugging a code generator.
|
/// BytecodeFile for debugging a code generator.
|
||||||
@@ -227,7 +227,7 @@ public:
|
|||||||
///
|
///
|
||||||
bool runPasses(const std::vector<const PassInfo*> &PassesToRun,
|
bool runPasses(const std::vector<const PassInfo*> &PassesToRun,
|
||||||
std::string &OutputFilename, bool DeleteOutput = false,
|
std::string &OutputFilename, bool DeleteOutput = false,
|
||||||
bool Quiet = false) const;
|
bool Quiet = false) const;
|
||||||
|
|
||||||
/// writeProgramToFile - This writes the current "Program" to the named
|
/// writeProgramToFile - This writes the current "Program" to the named
|
||||||
/// bytecode file. If an error occurs, true is returned.
|
/// bytecode file. If an error occurs, true is returned.
|
||||||
|
|||||||
@@ -564,7 +564,7 @@ bool BugDriver::debugMiscompilation() {
|
|||||||
// Make sure something was miscompiled...
|
// Make sure something was miscompiled...
|
||||||
if (!ReduceMiscompilingPasses(*this).reduceList(PassesToRun)) {
|
if (!ReduceMiscompilingPasses(*this).reduceList(PassesToRun)) {
|
||||||
std::cerr << "*** Optimized program matches reference output! No problem "
|
std::cerr << "*** Optimized program matches reference output! No problem "
|
||||||
<< "detected...\nbugpoint can't help you with your problem!\n";
|
<< "detected...\nbugpoint can't help you with your problem!\n";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ using namespace llvm;
|
|||||||
/// file. If an error occurs, true is returned.
|
/// file. If an error occurs, true is returned.
|
||||||
///
|
///
|
||||||
bool BugDriver::writeProgramToFile(const std::string &Filename,
|
bool BugDriver::writeProgramToFile(const std::string &Filename,
|
||||||
Module *M) const {
|
Module *M) const {
|
||||||
std::ios::openmode io_mode = std::ios::out | std::ios::trunc |
|
std::ios::openmode io_mode = std::ios::out | std::ios::trunc |
|
||||||
std::ios::binary;
|
std::ios::binary;
|
||||||
std::ofstream Out(Filename.c_str(), io_mode);
|
std::ofstream Out(Filename.c_str(), io_mode);
|
||||||
@@ -127,7 +127,7 @@ static void RunChild(Module *Program,const std::vector<const PassInfo*> &Passes,
|
|||||||
///
|
///
|
||||||
bool BugDriver::runPasses(const std::vector<const PassInfo*> &Passes,
|
bool BugDriver::runPasses(const std::vector<const PassInfo*> &Passes,
|
||||||
std::string &OutputFilename, bool DeleteOutput,
|
std::string &OutputFilename, bool DeleteOutput,
|
||||||
bool Quiet) const{
|
bool Quiet) const{
|
||||||
std::cout << std::flush;
|
std::cout << std::flush;
|
||||||
sys::Path uniqueFilename("bugpoint-output.bc");
|
sys::Path uniqueFilename("bugpoint-output.bc");
|
||||||
uniqueFilename.makeUnique();
|
uniqueFilename.makeUnique();
|
||||||
|
|||||||
276
utils/Burg/b.h
276
utils/Burg/b.h
@@ -1,6 +1,6 @@
|
|||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
#define MAX_ARITY 2
|
#define MAX_ARITY 2
|
||||||
|
|
||||||
typedef int ItemSetNum;
|
typedef int ItemSetNum;
|
||||||
typedef int OperatorNum;
|
typedef int OperatorNum;
|
||||||
@@ -9,11 +9,11 @@ typedef int RuleNum;
|
|||||||
typedef int ArityNum;
|
typedef int ArityNum;
|
||||||
typedef int ERuleNum;
|
typedef int ERuleNum;
|
||||||
|
|
||||||
extern NonTerminalNum last_user_nonterminal;
|
extern NonTerminalNum last_user_nonterminal;
|
||||||
extern NonTerminalNum max_nonterminal;
|
extern NonTerminalNum max_nonterminal;
|
||||||
extern RuleNum max_rule;
|
extern RuleNum max_rule;
|
||||||
extern ERuleNum max_erule_num;
|
extern ERuleNum max_erule_num;
|
||||||
extern int max_arity;
|
extern int max_arity;
|
||||||
|
|
||||||
#ifdef __STDC__
|
#ifdef __STDC__
|
||||||
#define ARGS(x) x
|
#define ARGS(x) x
|
||||||
@@ -22,7 +22,7 @@ extern int max_arity;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef NOLEX
|
#ifndef NOLEX
|
||||||
#define DELTAWIDTH 4
|
#define DELTAWIDTH 4
|
||||||
typedef short DeltaCost[DELTAWIDTH];
|
typedef short DeltaCost[DELTAWIDTH];
|
||||||
typedef short *DeltaPtr;
|
typedef short *DeltaPtr;
|
||||||
extern void ASSIGNCOST ARGS((DeltaPtr, DeltaPtr));
|
extern void ASSIGNCOST ARGS((DeltaPtr, DeltaPtr));
|
||||||
@@ -31,179 +31,179 @@ extern void MINUSCOST ARGS((DeltaPtr, DeltaPtr));
|
|||||||
extern void ZEROCOST ARGS((DeltaPtr));
|
extern void ZEROCOST ARGS((DeltaPtr));
|
||||||
extern int LESSCOST ARGS((DeltaPtr, DeltaPtr));
|
extern int LESSCOST ARGS((DeltaPtr, DeltaPtr));
|
||||||
extern int EQUALCOST ARGS((DeltaPtr, DeltaPtr));
|
extern int EQUALCOST ARGS((DeltaPtr, DeltaPtr));
|
||||||
#define PRINCIPLECOST(x) (x[0])
|
#define PRINCIPLECOST(x) (x[0])
|
||||||
#else
|
#else
|
||||||
#define DELTAWIDTH 1
|
#define DELTAWIDTH 1
|
||||||
typedef int DeltaCost;
|
typedef int DeltaCost;
|
||||||
typedef int DeltaPtr;
|
typedef int DeltaPtr;
|
||||||
#define ASSIGNCOST(l, r) ((l) = (r))
|
#define ASSIGNCOST(l, r) ((l) = (r))
|
||||||
#define ADDCOST(l, r) ((l) += (r))
|
#define ADDCOST(l, r) ((l) += (r))
|
||||||
#define MINUSCOST(l, r) ((l) -= (r))
|
#define MINUSCOST(l, r) ((l) -= (r))
|
||||||
#define ZEROCOST(x) ((x) = 0)
|
#define ZEROCOST(x) ((x) = 0)
|
||||||
#define LESSCOST(l, r) ((l) < (r))
|
#define LESSCOST(l, r) ((l) < (r))
|
||||||
#define EQUALCOST(l, r) ((l) == (r))
|
#define EQUALCOST(l, r) ((l) == (r))
|
||||||
#define PRINCIPLECOST(x) (x)
|
#define PRINCIPLECOST(x) (x)
|
||||||
#endif /* NOLEX */
|
#endif /* NOLEX */
|
||||||
#define NODIVERGE(c,state,nt,base) if (prevent_divergence > 0) CHECKDIVERGE(c,state,nt,base);
|
#define NODIVERGE(c,state,nt,base) if (prevent_divergence > 0) CHECKDIVERGE(c,state,nt,base);
|
||||||
|
|
||||||
struct list {
|
struct list {
|
||||||
void *x;
|
void *x;
|
||||||
struct list *next;
|
struct list *next;
|
||||||
};
|
};
|
||||||
typedef struct list *List;
|
typedef struct list *List;
|
||||||
|
|
||||||
struct intlist {
|
struct intlist {
|
||||||
int x;
|
int x;
|
||||||
struct intlist *next;
|
struct intlist *next;
|
||||||
};
|
};
|
||||||
typedef struct intlist *IntList;
|
typedef struct intlist *IntList;
|
||||||
|
|
||||||
struct operator {
|
struct operator {
|
||||||
char *name;
|
char *name;
|
||||||
unsigned int ref:1;
|
unsigned int ref:1;
|
||||||
OperatorNum num;
|
OperatorNum num;
|
||||||
ItemSetNum baseNum;
|
ItemSetNum baseNum;
|
||||||
ItemSetNum stateCount;
|
ItemSetNum stateCount;
|
||||||
ArityNum arity;
|
ArityNum arity;
|
||||||
struct table *table;
|
struct table *table;
|
||||||
};
|
};
|
||||||
typedef struct operator *Operator;
|
typedef struct operator *Operator;
|
||||||
|
|
||||||
struct nonterminal {
|
struct nonterminal {
|
||||||
char *name;
|
char *name;
|
||||||
NonTerminalNum num;
|
NonTerminalNum num;
|
||||||
ItemSetNum baseNum;
|
ItemSetNum baseNum;
|
||||||
ItemSetNum ruleCount;
|
ItemSetNum ruleCount;
|
||||||
struct plankMap *pmap;
|
struct plankMap *pmap;
|
||||||
|
|
||||||
struct rule *sampleRule; /* diagnostic---gives "a" rule that with this lhs */
|
struct rule *sampleRule; /* diagnostic---gives "a" rule that with this lhs */
|
||||||
};
|
};
|
||||||
typedef struct nonterminal *NonTerminal;
|
typedef struct nonterminal *NonTerminal;
|
||||||
|
|
||||||
struct pattern {
|
struct pattern {
|
||||||
NonTerminal normalizer;
|
NonTerminal normalizer;
|
||||||
Operator op; /* NULL if NonTerm -> NonTerm */
|
Operator op; /* NULL if NonTerm -> NonTerm */
|
||||||
NonTerminal children[MAX_ARITY];
|
NonTerminal children[MAX_ARITY];
|
||||||
};
|
};
|
||||||
typedef struct pattern *Pattern;
|
typedef struct pattern *Pattern;
|
||||||
|
|
||||||
struct rule {
|
struct rule {
|
||||||
DeltaCost delta;
|
DeltaCost delta;
|
||||||
ERuleNum erulenum;
|
ERuleNum erulenum;
|
||||||
RuleNum num;
|
RuleNum num;
|
||||||
RuleNum newNum;
|
RuleNum newNum;
|
||||||
NonTerminal lhs;
|
NonTerminal lhs;
|
||||||
Pattern pat;
|
Pattern pat;
|
||||||
unsigned int used:1;
|
unsigned int used:1;
|
||||||
};
|
};
|
||||||
typedef struct rule *Rule;
|
typedef struct rule *Rule;
|
||||||
|
|
||||||
struct item {
|
struct item {
|
||||||
DeltaCost delta;
|
DeltaCost delta;
|
||||||
Rule rule;
|
Rule rule;
|
||||||
};
|
};
|
||||||
typedef struct item Item;
|
typedef struct item Item;
|
||||||
|
|
||||||
typedef short *Relevant; /* relevant non-terminals */
|
typedef short *Relevant; /* relevant non-terminals */
|
||||||
|
|
||||||
typedef Item *ItemArray;
|
typedef Item *ItemArray;
|
||||||
|
|
||||||
struct item_set { /* indexed by NonTerminal */
|
struct item_set { /* indexed by NonTerminal */
|
||||||
ItemSetNum num;
|
ItemSetNum num;
|
||||||
ItemSetNum newNum;
|
ItemSetNum newNum;
|
||||||
Operator op;
|
Operator op;
|
||||||
struct item_set *kids[2];
|
struct item_set *kids[2];
|
||||||
struct item_set *representative;
|
struct item_set *representative;
|
||||||
Relevant relevant;
|
Relevant relevant;
|
||||||
ItemArray virgin;
|
ItemArray virgin;
|
||||||
ItemArray closed;
|
ItemArray closed;
|
||||||
};
|
};
|
||||||
typedef struct item_set *Item_Set;
|
typedef struct item_set *Item_Set;
|
||||||
|
|
||||||
#define DIM_MAP_SIZE (1 << 8)
|
#define DIM_MAP_SIZE (1 << 8)
|
||||||
#define GLOBAL_MAP_SIZE (1 << 15)
|
#define GLOBAL_MAP_SIZE (1 << 15)
|
||||||
|
|
||||||
struct mapping { /* should be a hash table for TS -> int */
|
struct mapping { /* should be a hash table for TS -> int */
|
||||||
List *hash;
|
List *hash;
|
||||||
int hash_size;
|
int hash_size;
|
||||||
int max_size;
|
int max_size;
|
||||||
ItemSetNum count;
|
ItemSetNum count;
|
||||||
Item_Set *set; /* map: int <-> Item_Set */
|
Item_Set *set; /* map: int <-> Item_Set */
|
||||||
};
|
};
|
||||||
typedef struct mapping *Mapping;
|
typedef struct mapping *Mapping;
|
||||||
|
|
||||||
struct index_map {
|
struct index_map {
|
||||||
ItemSetNum max_size;
|
ItemSetNum max_size;
|
||||||
Item_Set *class;
|
Item_Set *class;
|
||||||
};
|
};
|
||||||
typedef struct index_map Index_Map;
|
typedef struct index_map Index_Map;
|
||||||
|
|
||||||
struct dimension {
|
struct dimension {
|
||||||
Relevant relevant;
|
Relevant relevant;
|
||||||
Index_Map index_map;
|
Index_Map index_map;
|
||||||
Mapping map;
|
Mapping map;
|
||||||
ItemSetNum max_size;
|
ItemSetNum max_size;
|
||||||
struct plankMap *pmap;
|
struct plankMap *pmap;
|
||||||
};
|
};
|
||||||
typedef struct dimension *Dimension;
|
typedef struct dimension *Dimension;
|
||||||
|
|
||||||
|
|
||||||
struct table {
|
struct table {
|
||||||
Operator op;
|
Operator op;
|
||||||
List rules;
|
List rules;
|
||||||
Relevant relevant;
|
Relevant relevant;
|
||||||
Dimension dimen[MAX_ARITY]; /* 1 for each dimension */
|
Dimension dimen[MAX_ARITY]; /* 1 for each dimension */
|
||||||
Item_Set *transition; /* maps local indices to global
|
Item_Set *transition; /* maps local indices to global
|
||||||
itemsets */
|
itemsets */
|
||||||
};
|
};
|
||||||
typedef struct table *Table;
|
typedef struct table *Table;
|
||||||
|
|
||||||
struct relation {
|
struct relation {
|
||||||
Rule rule;
|
Rule rule;
|
||||||
DeltaCost chain;
|
DeltaCost chain;
|
||||||
NonTerminalNum nextchain;
|
NonTerminalNum nextchain;
|
||||||
DeltaCost sibling;
|
DeltaCost sibling;
|
||||||
int sibFlag;
|
int sibFlag;
|
||||||
int sibComputed;
|
int sibComputed;
|
||||||
};
|
};
|
||||||
typedef struct relation *Relation;
|
typedef struct relation *Relation;
|
||||||
|
|
||||||
struct queue {
|
struct queue {
|
||||||
List head;
|
List head;
|
||||||
List tail;
|
List tail;
|
||||||
};
|
};
|
||||||
typedef struct queue *Queue;
|
typedef struct queue *Queue;
|
||||||
|
|
||||||
struct plank {
|
struct plank {
|
||||||
char *name;
|
char *name;
|
||||||
List fields;
|
List fields;
|
||||||
int width;
|
int width;
|
||||||
};
|
};
|
||||||
typedef struct plank *Plank;
|
typedef struct plank *Plank;
|
||||||
|
|
||||||
struct except {
|
struct except {
|
||||||
short index;
|
short index;
|
||||||
short value;
|
short value;
|
||||||
};
|
};
|
||||||
typedef struct except *Exception;
|
typedef struct except *Exception;
|
||||||
|
|
||||||
struct plankMap {
|
struct plankMap {
|
||||||
List exceptions;
|
List exceptions;
|
||||||
int offset;
|
int offset;
|
||||||
struct stateMap *values;
|
struct stateMap *values;
|
||||||
};
|
};
|
||||||
typedef struct plankMap *PlankMap;
|
typedef struct plankMap *PlankMap;
|
||||||
|
|
||||||
struct stateMap {
|
struct stateMap {
|
||||||
char *fieldname;
|
char *fieldname;
|
||||||
Plank plank;
|
Plank plank;
|
||||||
int width;
|
int width;
|
||||||
short *value;
|
short *value;
|
||||||
};
|
};
|
||||||
typedef struct stateMap *StateMap;
|
typedef struct stateMap *StateMap;
|
||||||
|
|
||||||
struct stateMapTable {
|
struct stateMapTable {
|
||||||
List maps;
|
List maps;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern void CHECKDIVERGE ARGS((DeltaPtr, Item_Set, int, int));
|
extern void CHECKDIVERGE ARGS((DeltaPtr, Item_Set, int, int));
|
||||||
@@ -232,7 +232,7 @@ extern Item_Set encode ARGS((Mapping, Item_Set, int *));
|
|||||||
extern void build ARGS((void));
|
extern void build ARGS((void));
|
||||||
extern Item_Set *transLval ARGS((Table, int, int));
|
extern Item_Set *transLval ARGS((Table, int, int));
|
||||||
|
|
||||||
typedef void * (*ListFn) ARGS((void *));
|
typedef void * (*ListFn) ARGS((void *));
|
||||||
extern void foreachList ARGS((ListFn, List));
|
extern void foreachList ARGS((ListFn, List));
|
||||||
extern void reveachList ARGS((ListFn, List));
|
extern void reveachList ARGS((ListFn, List));
|
||||||
|
|
||||||
@@ -247,23 +247,23 @@ extern void addRelevant ARGS((Relevant, NonTerminalNum));
|
|||||||
extern void *zalloc ARGS((unsigned int));
|
extern void *zalloc ARGS((unsigned int));
|
||||||
extern void zfree ARGS((void *));
|
extern void zfree ARGS((void *));
|
||||||
|
|
||||||
extern NonTerminal start;
|
extern NonTerminal start;
|
||||||
extern List rules;
|
extern List rules;
|
||||||
extern List chainrules;
|
extern List chainrules;
|
||||||
extern List operators;
|
extern List operators;
|
||||||
extern List leaves;
|
extern List leaves;
|
||||||
extern List nonterminals;
|
extern List nonterminals;
|
||||||
extern List grammarNts;
|
extern List grammarNts;
|
||||||
extern Queue globalQ;
|
extern Queue globalQ;
|
||||||
extern Mapping globalMap;
|
extern Mapping globalMap;
|
||||||
extern int exceptionTolerance;
|
extern int exceptionTolerance;
|
||||||
extern int prevent_divergence;
|
extern int prevent_divergence;
|
||||||
extern int principleCost;
|
extern int principleCost;
|
||||||
extern int lexical;
|
extern int lexical;
|
||||||
extern struct rule stub_rule;
|
extern struct rule stub_rule;
|
||||||
extern Relation *allpairs;
|
extern Relation *allpairs;
|
||||||
extern Item_Set *sortedStates;
|
extern Item_Set *sortedStates;
|
||||||
extern Item_Set errorState;
|
extern Item_Set errorState;
|
||||||
|
|
||||||
extern void dumpRelevant ARGS((Relevant));
|
extern void dumpRelevant ARGS((Relevant));
|
||||||
extern void dumpOperator ARGS((Operator, int));
|
extern void dumpOperator ARGS((Operator, int));
|
||||||
@@ -289,14 +289,14 @@ extern void dumpSortedRules ARGS((void));
|
|||||||
extern int debugTrim;
|
extern int debugTrim;
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
#define debug(a,b) if (a) b
|
#define debug(a,b) if (a) b
|
||||||
#else
|
#else
|
||||||
#define debug(a,b)
|
#define debug(a,b)
|
||||||
#endif
|
#endif
|
||||||
extern int debugTables;
|
extern int debugTables;
|
||||||
|
|
||||||
#define TABLE_INCR 8
|
#define TABLE_INCR 8
|
||||||
#define STATES_INCR 64
|
#define STATES_INCR 64
|
||||||
|
|
||||||
#ifdef NDEBUG
|
#ifdef NDEBUG
|
||||||
#define assert(c) ((void) 0)
|
#define assert(c) ((void) 0)
|
||||||
|
|||||||
1454
utils/Burg/be.c
1454
utils/Burg/be.c
File diff suppressed because it is too large
Load Diff
@@ -9,63 +9,63 @@ static void doLeaf ARGS((Operator));
|
|||||||
static void
|
static void
|
||||||
doLeaf(leaf) Operator leaf;
|
doLeaf(leaf) Operator leaf;
|
||||||
{
|
{
|
||||||
int new;
|
int new;
|
||||||
List pl;
|
List pl;
|
||||||
Item_Set ts;
|
Item_Set ts;
|
||||||
Item_Set tmp;
|
Item_Set tmp;
|
||||||
|
|
||||||
assert(leaf->arity == 0);
|
assert(leaf->arity == 0);
|
||||||
|
|
||||||
ts = newItem_Set(leaf->table->relevant);
|
ts = newItem_Set(leaf->table->relevant);
|
||||||
|
|
||||||
for (pl = rules; pl; pl = pl->next) {
|
for (pl = rules; pl; pl = pl->next) {
|
||||||
Rule p = (Rule) pl->x;
|
Rule p = (Rule) pl->x;
|
||||||
if (p->pat->op == leaf) {
|
if (p->pat->op == leaf) {
|
||||||
if (!ts->virgin[p->lhs->num].rule || p->delta < ts->virgin[p->lhs->num].delta) {
|
if (!ts->virgin[p->lhs->num].rule || p->delta < ts->virgin[p->lhs->num].delta) {
|
||||||
ts->virgin[p->lhs->num].rule = p;
|
ts->virgin[p->lhs->num].rule = p;
|
||||||
ASSIGNCOST(ts->virgin[p->lhs->num].delta, p->delta);
|
ASSIGNCOST(ts->virgin[p->lhs->num].delta, p->delta);
|
||||||
ts->op = leaf;
|
ts->op = leaf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
trim(ts);
|
trim(ts);
|
||||||
zero(ts);
|
zero(ts);
|
||||||
tmp = encode(globalMap, ts, &new);
|
tmp = encode(globalMap, ts, &new);
|
||||||
if (new) {
|
if (new) {
|
||||||
closure(ts);
|
closure(ts);
|
||||||
leaf->table->transition[0] = ts;
|
leaf->table->transition[0] = ts;
|
||||||
addQ(globalQ, ts);
|
addQ(globalQ, ts);
|
||||||
} else {
|
} else {
|
||||||
leaf->table->transition[0] = tmp;
|
leaf->table->transition[0] = tmp;
|
||||||
freeItem_Set(ts);
|
freeItem_Set(ts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
build()
|
build()
|
||||||
{
|
{
|
||||||
int new;
|
int new;
|
||||||
List ol;
|
List ol;
|
||||||
Item_Set ts;
|
Item_Set ts;
|
||||||
|
|
||||||
globalQ = newQ();
|
globalQ = newQ();
|
||||||
globalMap = newMapping(GLOBAL_MAP_SIZE);
|
globalMap = newMapping(GLOBAL_MAP_SIZE);
|
||||||
|
|
||||||
ts = newItem_Set(0);
|
ts = newItem_Set(0);
|
||||||
errorState = encode(globalMap, ts, &new);
|
errorState = encode(globalMap, ts, &new);
|
||||||
ts->closed = ts->virgin;
|
ts->closed = ts->virgin;
|
||||||
addQ(globalQ, ts);
|
addQ(globalQ, ts);
|
||||||
|
|
||||||
foreachList((ListFn) doLeaf, leaves);
|
foreachList((ListFn) doLeaf, leaves);
|
||||||
|
|
||||||
debug(debugTables, printf("---initial set of states ---\n"));
|
debug(debugTables, printf("---initial set of states ---\n"));
|
||||||
debug(debugTables, dumpMapping(globalMap));
|
debug(debugTables, dumpMapping(globalMap));
|
||||||
debug(debugTables, foreachList((ListFn) dumpItem_Set, globalQ->head));
|
debug(debugTables, foreachList((ListFn) dumpItem_Set, globalQ->head));
|
||||||
|
|
||||||
for (ts = popQ(globalQ); ts; ts = popQ(globalQ)) {
|
for (ts = popQ(globalQ); ts; ts = popQ(globalQ)) {
|
||||||
for (ol = operators; ol; ol = ol->next) {
|
for (ol = operators; ol; ol = ol->next) {
|
||||||
Operator op = (Operator) ol->x;
|
Operator op = (Operator) ol->x;
|
||||||
addToTable(op->table, ts);
|
addToTable(op->table, ts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,86 +10,86 @@ List chainrules;
|
|||||||
void
|
void
|
||||||
findChainRules()
|
findChainRules()
|
||||||
{
|
{
|
||||||
List pl;
|
List pl;
|
||||||
|
|
||||||
assert(!chainrules);
|
assert(!chainrules);
|
||||||
|
|
||||||
for (pl = rules; pl; pl = pl->next) {
|
for (pl = rules; pl; pl = pl->next) {
|
||||||
Rule p = (Rule) pl->x;
|
Rule p = (Rule) pl->x;
|
||||||
if (!p->pat->op) {
|
if (!p->pat->op) {
|
||||||
chainrules = newList(p, chainrules);
|
chainrules = newList(p, chainrules);
|
||||||
} else {
|
} else {
|
||||||
p->pat->op->table->rules = newList(p, p->pat->op->table->rules);
|
p->pat->op->table->rules = newList(p, p->pat->op->table->rules);
|
||||||
addRelevant(p->pat->op->table->relevant, p->lhs->num);
|
addRelevant(p->pat->op->table->relevant, p->lhs->num);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
zero(t) Item_Set t;
|
zero(t) Item_Set t;
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
DeltaCost base;
|
DeltaCost base;
|
||||||
int exists;
|
int exists;
|
||||||
int base_nt = 0;
|
int base_nt = 0;
|
||||||
|
|
||||||
assert(!t->closed);
|
assert(!t->closed);
|
||||||
|
|
||||||
ZEROCOST(base);
|
ZEROCOST(base);
|
||||||
exists = 0;
|
exists = 0;
|
||||||
for (i = 0; i < max_nonterminal; i++) {
|
for (i = 0; i < max_nonterminal; i++) {
|
||||||
if (t->virgin[i].rule) {
|
if (t->virgin[i].rule) {
|
||||||
if (exists) {
|
if (exists) {
|
||||||
if (LESSCOST(t->virgin[i].delta, base)) {
|
if (LESSCOST(t->virgin[i].delta, base)) {
|
||||||
ASSIGNCOST(base, t->virgin[i].delta);
|
ASSIGNCOST(base, t->virgin[i].delta);
|
||||||
base_nt = i;
|
base_nt = i;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ASSIGNCOST(base, t->virgin[i].delta);
|
ASSIGNCOST(base, t->virgin[i].delta);
|
||||||
exists = 1;
|
exists = 1;
|
||||||
base_nt = i;
|
base_nt = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!exists) {
|
if (!exists) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (i = 0; i < max_nonterminal; i++) {
|
for (i = 0; i < max_nonterminal; i++) {
|
||||||
if (t->virgin[i].rule) {
|
if (t->virgin[i].rule) {
|
||||||
MINUSCOST(t->virgin[i].delta, base);
|
MINUSCOST(t->virgin[i].delta, base);
|
||||||
}
|
}
|
||||||
NODIVERGE(t->virgin[i].delta, t, i, base_nt);
|
NODIVERGE(t->virgin[i].delta, t, i, base_nt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
closure(t) Item_Set t;
|
closure(t) Item_Set t;
|
||||||
{
|
{
|
||||||
int changes;
|
int changes;
|
||||||
List pl;
|
List pl;
|
||||||
|
|
||||||
assert(!t->closed);
|
assert(!t->closed);
|
||||||
t->closed = itemArrayCopy(t->virgin);
|
t->closed = itemArrayCopy(t->virgin);
|
||||||
|
|
||||||
changes = 1;
|
changes = 1;
|
||||||
while (changes) {
|
while (changes) {
|
||||||
changes = 0;
|
changes = 0;
|
||||||
for (pl = chainrules; pl; pl = pl->next) {
|
for (pl = chainrules; pl; pl = pl->next) {
|
||||||
Rule p = (Rule) pl->x;
|
Rule p = (Rule) pl->x;
|
||||||
register Item *rhs_item = &t->closed[p->pat->children[0]->num];
|
register Item *rhs_item = &t->closed[p->pat->children[0]->num];
|
||||||
|
|
||||||
if (rhs_item->rule) { /* rhs is active */
|
if (rhs_item->rule) { /* rhs is active */
|
||||||
DeltaCost dc;
|
DeltaCost dc;
|
||||||
register Item *lhs_item = &t->closed[p->lhs->num];
|
register Item *lhs_item = &t->closed[p->lhs->num];
|
||||||
|
|
||||||
ASSIGNCOST(dc, rhs_item->delta);
|
ASSIGNCOST(dc, rhs_item->delta);
|
||||||
ADDCOST(dc, p->delta);
|
ADDCOST(dc, p->delta);
|
||||||
if (LESSCOST(dc, lhs_item->delta) || !lhs_item->rule) {
|
if (LESSCOST(dc, lhs_item->delta) || !lhs_item->rule) {
|
||||||
ASSIGNCOST(lhs_item->delta, dc);
|
ASSIGNCOST(lhs_item->delta, dc);
|
||||||
lhs_item->rule = p;
|
lhs_item->rule = p;
|
||||||
changes = 1;
|
changes = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,133 +11,133 @@ int lexical = 0;
|
|||||||
void
|
void
|
||||||
ASSIGNCOST(l, r) DeltaPtr l; DeltaPtr r;
|
ASSIGNCOST(l, r) DeltaPtr l; DeltaPtr r;
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (lexical) {
|
if (lexical) {
|
||||||
for (i = 0; i < DELTAWIDTH; i++) {
|
for (i = 0; i < DELTAWIDTH; i++) {
|
||||||
l[i] = r[i];
|
l[i] = r[i];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
l[0] = r[0];
|
l[0] = r[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ADDCOST(l, r) DeltaPtr l; DeltaPtr r;
|
ADDCOST(l, r) DeltaPtr l; DeltaPtr r;
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (lexical) {
|
if (lexical) {
|
||||||
for (i = 0; i < DELTAWIDTH; i++) {
|
for (i = 0; i < DELTAWIDTH; i++) {
|
||||||
l[i] += r[i];
|
l[i] += r[i];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
l[0] += r[0];
|
l[0] += r[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
MINUSCOST(l, r) DeltaPtr l; DeltaPtr r;
|
MINUSCOST(l, r) DeltaPtr l; DeltaPtr r;
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (lexical) {
|
if (lexical) {
|
||||||
for (i = 0; i < DELTAWIDTH; i++) {
|
for (i = 0; i < DELTAWIDTH; i++) {
|
||||||
l[i] -= r[i];
|
l[i] -= r[i];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
l[0] -= r[0];
|
l[0] -= r[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ZEROCOST(x) DeltaPtr x;
|
ZEROCOST(x) DeltaPtr x;
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (lexical) {
|
if (lexical) {
|
||||||
for (i = 0; i < DELTAWIDTH; i++) {
|
for (i = 0; i < DELTAWIDTH; i++) {
|
||||||
x[i] = 0;
|
x[i] = 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
x[0] = 0;
|
x[0] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
LESSCOST(l, r) DeltaPtr l; DeltaPtr r;
|
LESSCOST(l, r) DeltaPtr l; DeltaPtr r;
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (lexical) {
|
if (lexical) {
|
||||||
for (i = 0; i < DELTAWIDTH; i++) {
|
for (i = 0; i < DELTAWIDTH; i++) {
|
||||||
if (l[i] < r[i]) {
|
if (l[i] < r[i]) {
|
||||||
return 1;
|
return 1;
|
||||||
} else if (l[i] > r[i]) {
|
} else if (l[i] > r[i]) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
return l[0] < r[0];
|
return l[0] < r[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
EQUALCOST(l, r) DeltaPtr l; DeltaPtr r;
|
EQUALCOST(l, r) DeltaPtr l; DeltaPtr r;
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (lexical) {
|
if (lexical) {
|
||||||
for (i = 0; i < DELTAWIDTH; i++) {
|
for (i = 0; i < DELTAWIDTH; i++) {
|
||||||
if (l[i] != r[i]) {
|
if (l[i] != r[i]) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
return l[0] == r[0];
|
return l[0] == r[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* NOLEX */
|
#endif /* NOLEX */
|
||||||
|
|
||||||
void
|
void
|
||||||
CHECKDIVERGE(c, its, nt, base) DeltaPtr c; Item_Set its; int nt; int base;
|
CHECKDIVERGE(c, its, nt, base) DeltaPtr c; Item_Set its; int nt; int base;
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (prevent_divergence <= 0) {
|
if (prevent_divergence <= 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (lexical) {
|
if (lexical) {
|
||||||
#ifndef NOLEX
|
#ifndef NOLEX
|
||||||
for (i = 0; i < DELTAWIDTH; i++) {
|
for (i = 0; i < DELTAWIDTH; i++) {
|
||||||
if (c[i] > prevent_divergence) {
|
if (c[i] > prevent_divergence) {
|
||||||
char ntname[100];
|
char ntname[100];
|
||||||
char basename[100];
|
char basename[100];
|
||||||
nonTerminalName(ntname, nt);
|
nonTerminalName(ntname, nt);
|
||||||
nonTerminalName(basename, base);
|
nonTerminalName(basename, base);
|
||||||
fprintf(stderr, "ERROR: The grammar appears to diverge\n");
|
fprintf(stderr, "ERROR: The grammar appears to diverge\n");
|
||||||
fprintf(stderr, "\tRelative Costs: %s(0), %s(%d)\n", basename, ntname, c[i]);
|
fprintf(stderr, "\tRelative Costs: %s(0), %s(%d)\n", basename, ntname, c[i]);
|
||||||
fprintf(stderr, "\tOffending Operator: %s\n", its->op->name);
|
fprintf(stderr, "\tOffending Operator: %s\n", its->op->name);
|
||||||
fprintf(stderr, "\tOffending Tree: ");
|
fprintf(stderr, "\tOffending Tree: ");
|
||||||
printRepresentative(stderr, its);
|
printRepresentative(stderr, its);
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /*NOLEX*/
|
#endif /*NOLEX*/
|
||||||
} else if (PRINCIPLECOST(c) > prevent_divergence) {
|
} else if (PRINCIPLECOST(c) > prevent_divergence) {
|
||||||
char ntname[100];
|
char ntname[100];
|
||||||
char basename[100];
|
char basename[100];
|
||||||
nonTerminalName(ntname, nt);
|
nonTerminalName(ntname, nt);
|
||||||
nonTerminalName(basename, base);
|
nonTerminalName(basename, base);
|
||||||
fprintf(stderr, "ERROR: The grammar appears to diverge\n");
|
fprintf(stderr, "ERROR: The grammar appears to diverge\n");
|
||||||
fprintf(stderr, "\tRelative Costs: %s(0), %s(%d)\n", basename, ntname, PRINCIPLECOST(c));
|
fprintf(stderr, "\tRelative Costs: %s(0), %s(%d)\n", basename, ntname, PRINCIPLECOST(c));
|
||||||
fprintf(stderr, "\tOffending Operator: %s\n", its->op->name);
|
fprintf(stderr, "\tOffending Operator: %s\n", its->op->name);
|
||||||
fprintf(stderr, "\tOffending Tree: ");
|
fprintf(stderr, "\tOffending Tree: ");
|
||||||
printRepresentative(stderr, its);
|
printRepresentative(stderr, its);
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
506
utils/Burg/fe.c
506
utils/Burg/fe.c
@@ -9,8 +9,8 @@ int grammarflag;
|
|||||||
|
|
||||||
static int arity;
|
static int arity;
|
||||||
|
|
||||||
List ruleASTs;
|
List ruleASTs;
|
||||||
List grammarNts;
|
List grammarNts;
|
||||||
|
|
||||||
static void doBinding ARGS((Binding));
|
static void doBinding ARGS((Binding));
|
||||||
static void doDecl ARGS((Arity));
|
static void doDecl ARGS((Arity));
|
||||||
@@ -23,29 +23,29 @@ static void doTable ARGS((Operator));
|
|||||||
static void
|
static void
|
||||||
doBinding(b) Binding b;
|
doBinding(b) Binding b;
|
||||||
{
|
{
|
||||||
int new;
|
int new;
|
||||||
Symbol s;
|
Symbol s;
|
||||||
|
|
||||||
s = enter(b->name, &new);
|
s = enter(b->name, &new);
|
||||||
if (!new) {
|
if (!new) {
|
||||||
fprintf(stderr, "Non-unique name: %s\n", b->name);
|
fprintf(stderr, "Non-unique name: %s\n", b->name);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
s->tag = OPERATOR;
|
s->tag = OPERATOR;
|
||||||
s->u.op = newOperator(b->name, b->opnum, arity);
|
s->u.op = newOperator(b->name, b->opnum, arity);
|
||||||
if (arity == 0) {
|
if (arity == 0) {
|
||||||
leaves = newList(s->u.op, leaves);
|
leaves = newList(s->u.op, leaves);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
doDecl(a) Arity a;
|
doDecl(a) Arity a;
|
||||||
{
|
{
|
||||||
if (!a) {
|
if (!a) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
arity = a->arity;
|
arity = a->arity;
|
||||||
foreachList((ListFn) doBinding, a->bindings);
|
foreachList((ListFn) doBinding, a->bindings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -55,263 +55,263 @@ static int tcount;
|
|||||||
static NonTerminal
|
static NonTerminal
|
||||||
lookup(p) Pattern p;
|
lookup(p) Pattern p;
|
||||||
{
|
{
|
||||||
char buf[10];
|
char buf[10];
|
||||||
char *s;
|
char *s;
|
||||||
List l;
|
List l;
|
||||||
NonTerminal n;
|
NonTerminal n;
|
||||||
DeltaCost dummy;
|
DeltaCost dummy;
|
||||||
|
|
||||||
for (l = xpatterns; l; l = l->next) {
|
for (l = xpatterns; l; l = l->next) {
|
||||||
Pattern x = (Pattern) l->x;
|
Pattern x = (Pattern) l->x;
|
||||||
if (x->op == p->op
|
if (x->op == p->op
|
||||||
&& x->children[0] == p->children[0]
|
&& x->children[0] == p->children[0]
|
||||||
&& x->children[1] == p->children[1]) {
|
&& x->children[1] == p->children[1]) {
|
||||||
return x->normalizer;
|
return x->normalizer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sprintf(buf, "n%%%d", tcount++);
|
sprintf(buf, "n%%%d", tcount++);
|
||||||
s = (char *) zalloc(strlen(buf)+1);
|
s = (char *) zalloc(strlen(buf)+1);
|
||||||
strcpy(s, buf);
|
strcpy(s, buf);
|
||||||
n = newNonTerminal(s);
|
n = newNonTerminal(s);
|
||||||
p->normalizer = n;
|
p->normalizer = n;
|
||||||
xpatterns = newList(p, xpatterns);
|
xpatterns = newList(p, xpatterns);
|
||||||
ZEROCOST(dummy);
|
ZEROCOST(dummy);
|
||||||
(void) newRule(dummy, 0, n, p);
|
(void) newRule(dummy, 0, n, p);
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
static NonTerminal
|
static NonTerminal
|
||||||
normalize(ast, nt, patt) PatternAST ast; NonTerminal nt; Pattern *patt;
|
normalize(ast, nt, patt) PatternAST ast; NonTerminal nt; Pattern *patt;
|
||||||
{
|
{
|
||||||
Symbol s;
|
Symbol s;
|
||||||
int new;
|
int new;
|
||||||
Pattern dummy;
|
Pattern dummy;
|
||||||
|
|
||||||
s = enter(ast->op, &new);
|
s = enter(ast->op, &new);
|
||||||
ast->sym = s;
|
ast->sym = s;
|
||||||
if (new) {
|
if (new) {
|
||||||
fprintf(stderr, "Illegal use of %s --- undefined symbol\n", s->name);
|
fprintf(stderr, "Illegal use of %s --- undefined symbol\n", s->name);
|
||||||
exit(1);
|
exit(1);
|
||||||
return 0; /* shut up compilers */
|
return 0; /* shut up compilers */
|
||||||
} else if (s->tag == NONTERMINAL) {
|
} else if (s->tag == NONTERMINAL) {
|
||||||
if (ast->children) {
|
if (ast->children) {
|
||||||
fprintf(stderr, "Illegal use of %s, a non-terminal, as a terminal\n", s->name);
|
fprintf(stderr, "Illegal use of %s, a non-terminal, as a terminal\n", s->name);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
*patt = newPattern(0);
|
*patt = newPattern(0);
|
||||||
(*patt)->children[0] = s->u.nt;
|
(*patt)->children[0] = s->u.nt;
|
||||||
return s->u.nt;
|
return s->u.nt;
|
||||||
} else {
|
} else {
|
||||||
s->u.op->ref = 1;
|
s->u.op->ref = 1;
|
||||||
*patt = newPattern(s->u.op);
|
*patt = newPattern(s->u.op);
|
||||||
if (s->u.op->arity == -1) {
|
if (s->u.op->arity == -1) {
|
||||||
if (!ast->children) {
|
if (!ast->children) {
|
||||||
s->u.op->arity = 0;
|
s->u.op->arity = 0;
|
||||||
leaves = newList(s->u.op, leaves);
|
leaves = newList(s->u.op, leaves);
|
||||||
} else if (!ast->children->next) {
|
} else if (!ast->children->next) {
|
||||||
s->u.op->arity = 1;
|
s->u.op->arity = 1;
|
||||||
} else if (!ast->children->next->next) {
|
} else if (!ast->children->next->next) {
|
||||||
s->u.op->arity = 2;
|
s->u.op->arity = 2;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "ERROR: Too many children (max = 2) for \"%s\"\n", s->name);
|
fprintf(stderr, "ERROR: Too many children (max = 2) for \"%s\"\n", s->name);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if (s->u.op->arity > max_arity) {
|
if (s->u.op->arity > max_arity) {
|
||||||
max_arity = s->u.op->arity;
|
max_arity = s->u.op->arity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
switch (s->u.op->arity) {
|
switch (s->u.op->arity) {
|
||||||
default:
|
default:
|
||||||
assert(0);
|
assert(0);
|
||||||
break;
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
if (ast->children) {
|
if (ast->children) {
|
||||||
fprintf(stderr, "ERROR: Incorrect number of children for leaf operator, \"%s\"\n", s->name);
|
fprintf(stderr, "ERROR: Incorrect number of children for leaf operator, \"%s\"\n", s->name);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
if (!ast->children || ast->children->next) {
|
if (!ast->children || ast->children->next) {
|
||||||
fprintf(stderr, "ERROR: Incorrect number of children for unary operator, \"%s\"\n", s->name);
|
fprintf(stderr, "ERROR: Incorrect number of children for unary operator, \"%s\"\n", s->name);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
(*patt)->children[0] = normalize((PatternAST) ast->children->x, 0, &dummy);
|
(*patt)->children[0] = normalize((PatternAST) ast->children->x, 0, &dummy);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
if (!ast->children || !ast->children->next) {
|
if (!ast->children || !ast->children->next) {
|
||||||
fprintf(stderr, "ERROR: Incorrect number of children for binary operator, \"%s\"\n", s->name);
|
fprintf(stderr, "ERROR: Incorrect number of children for binary operator, \"%s\"\n", s->name);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
(*patt)->children[0] = normalize((PatternAST) ast->children->x, 0, &dummy);
|
(*patt)->children[0] = normalize((PatternAST) ast->children->x, 0, &dummy);
|
||||||
(*patt)->children[1] = normalize((PatternAST) ast->children->next->x, 0, &dummy);
|
(*patt)->children[1] = normalize((PatternAST) ast->children->next->x, 0, &dummy);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (nt) {
|
if (nt) {
|
||||||
(*patt)->normalizer = nt;
|
(*patt)->normalizer = nt;
|
||||||
return nt;
|
return nt;
|
||||||
} else {
|
} else {
|
||||||
return lookup(*patt);
|
return lookup(*patt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
doEnterNonTerm(ast) RuleAST ast;
|
doEnterNonTerm(ast) RuleAST ast;
|
||||||
{
|
{
|
||||||
int new;
|
int new;
|
||||||
Symbol s;
|
Symbol s;
|
||||||
DeltaCost delta;
|
DeltaCost delta;
|
||||||
int i;
|
int i;
|
||||||
IntList p;
|
IntList p;
|
||||||
|
|
||||||
|
|
||||||
s = enter(ast->lhs, &new);
|
s = enter(ast->lhs, &new);
|
||||||
if (new) {
|
if (new) {
|
||||||
s->u.nt = newNonTerminal(s->name);
|
s->u.nt = newNonTerminal(s->name);
|
||||||
s->tag = NONTERMINAL;
|
s->tag = NONTERMINAL;
|
||||||
} else {
|
} else {
|
||||||
if (s->tag != NONTERMINAL) {
|
if (s->tag != NONTERMINAL) {
|
||||||
fprintf(stderr, "Illegal use of %s as a non-terminal\n", s->name);
|
fprintf(stderr, "Illegal use of %s as a non-terminal\n", s->name);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ZEROCOST(delta);
|
ZEROCOST(delta);
|
||||||
for (p = ast->cost, i = 0; p; p = p->next, i++) {
|
for (p = ast->cost, i = 0; p; p = p->next, i++) {
|
||||||
int x = p->x;
|
int x = p->x;
|
||||||
#ifndef NOLEX
|
#ifndef NOLEX
|
||||||
if (lexical) {
|
if (lexical) {
|
||||||
if (i < DELTAWIDTH) {
|
if (i < DELTAWIDTH) {
|
||||||
delta[i] = x;
|
delta[i] = x;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
#endif /* NOLEX */
|
#endif /* NOLEX */
|
||||||
{
|
{
|
||||||
if (i == principleCost) {
|
if (i == principleCost) {
|
||||||
PRINCIPLECOST(delta) = x;
|
PRINCIPLECOST(delta) = x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ast->rule = newRule(delta, ast->erulenum, s->u.nt, 0);
|
ast->rule = newRule(delta, ast->erulenum, s->u.nt, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
doRule(ast) RuleAST ast;
|
doRule(ast) RuleAST ast;
|
||||||
{
|
{
|
||||||
Pattern pat;
|
Pattern pat;
|
||||||
|
|
||||||
(void) normalize(ast->pat, ast->rule->lhs, &pat);
|
(void) normalize(ast->pat, ast->rule->lhs, &pat);
|
||||||
ast->rule->pat = pat;
|
ast->rule->pat = pat;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
doTable(op) Operator op;
|
doTable(op) Operator op;
|
||||||
{
|
{
|
||||||
op->table = newTable(op);
|
op->table = newTable(op);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
doSpec(decls, rules) List decls; List rules;
|
doSpec(decls, rules) List decls; List rules;
|
||||||
{
|
{
|
||||||
foreachList((ListFn) doDecl, decls);
|
foreachList((ListFn) doDecl, decls);
|
||||||
debug(debugTables, foreachList((ListFn) dumpOperator_l, operators));
|
debug(debugTables, foreachList((ListFn) dumpOperator_l, operators));
|
||||||
|
|
||||||
ruleASTs = rules;
|
ruleASTs = rules;
|
||||||
reveachList((ListFn) doEnterNonTerm, rules);
|
reveachList((ListFn) doEnterNonTerm, rules);
|
||||||
|
|
||||||
last_user_nonterminal = max_nonterminal;
|
last_user_nonterminal = max_nonterminal;
|
||||||
|
|
||||||
reveachList((ListFn) doRule, rules);
|
reveachList((ListFn) doRule, rules);
|
||||||
debug(debugTables, foreachList((ListFn) dumpRule, rules));
|
debug(debugTables, foreachList((ListFn) dumpRule, rules));
|
||||||
|
|
||||||
foreachList((ListFn) doTable, operators);
|
foreachList((ListFn) doTable, operators);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
doStart(name) char *name;
|
doStart(name) char *name;
|
||||||
{
|
{
|
||||||
Symbol s;
|
Symbol s;
|
||||||
int new;
|
int new;
|
||||||
|
|
||||||
if (start) {
|
if (start) {
|
||||||
yyerror1("Redeclaration of start symbol to be ");
|
yyerror1("Redeclaration of start symbol to be ");
|
||||||
fprintf(stderr, "\"%s\"\n", name);
|
fprintf(stderr, "\"%s\"\n", name);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
s = enter(name, &new);
|
s = enter(name, &new);
|
||||||
if (new) {
|
if (new) {
|
||||||
s->u.nt = newNonTerminal(s->name);
|
s->u.nt = newNonTerminal(s->name);
|
||||||
s->tag = NONTERMINAL;
|
s->tag = NONTERMINAL;
|
||||||
} else {
|
} else {
|
||||||
if (s->tag != NONTERMINAL) {
|
if (s->tag != NONTERMINAL) {
|
||||||
fprintf(stderr, "Illegal use of %s as a non-terminal\n", s->name);
|
fprintf(stderr, "Illegal use of %s as a non-terminal\n", s->name);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
doGrammarNts()
|
doGrammarNts()
|
||||||
{
|
{
|
||||||
List l;
|
List l;
|
||||||
int new;
|
int new;
|
||||||
|
|
||||||
for (l = grammarNts; l; l = l->next) {
|
for (l = grammarNts; l; l = l->next) {
|
||||||
char *n = (char*) l->x;
|
char *n = (char*) l->x;
|
||||||
Symbol s;
|
Symbol s;
|
||||||
|
|
||||||
s = enter(n, &new);
|
s = enter(n, &new);
|
||||||
if (new) {
|
if (new) {
|
||||||
fprintf(stderr, "ERROR: %%gram, unused non-terminal: \"%s\"\n", n);
|
fprintf(stderr, "ERROR: %%gram, unused non-terminal: \"%s\"\n", n);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if (s->tag != NONTERMINAL) {
|
if (s->tag != NONTERMINAL) {
|
||||||
fprintf(stderr, "ERROR: %%gram, Not a non-terminal: \"%s\"\n", n);
|
fprintf(stderr, "ERROR: %%gram, Not a non-terminal: \"%s\"\n", n);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
l->x = s;
|
l->x = s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
doGram(nts) List nts;
|
doGram(nts) List nts;
|
||||||
{
|
{
|
||||||
if (grammarNts) {
|
if (grammarNts) {
|
||||||
yyerror1("Redeclaration of %%gram\n");
|
yyerror1("Redeclaration of %%gram\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
grammarNts = nts;
|
grammarNts = nts;
|
||||||
}
|
}
|
||||||
|
|
||||||
Arity
|
Arity
|
||||||
newArity(ar, b) int ar; List b;
|
newArity(ar, b) int ar; List b;
|
||||||
{
|
{
|
||||||
Arity a = (Arity) zalloc(sizeof(struct arity));
|
Arity a = (Arity) zalloc(sizeof(struct arity));
|
||||||
a->arity = ar;
|
a->arity = ar;
|
||||||
a->bindings = b;
|
a->bindings = b;
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
Binding
|
Binding
|
||||||
newBinding(name, opnum) char *name; int opnum;
|
newBinding(name, opnum) char *name; int opnum;
|
||||||
{
|
{
|
||||||
Binding b = (Binding) zalloc(sizeof(struct binding));
|
Binding b = (Binding) zalloc(sizeof(struct binding));
|
||||||
if (opnum == 0) {
|
if (opnum == 0) {
|
||||||
yyerror1("ERROR: Non-positive external symbol number, ");
|
yyerror1("ERROR: Non-positive external symbol number, ");
|
||||||
fprintf(stderr, "%d", opnum);
|
fprintf(stderr, "%d", opnum);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
b->name = name;
|
b->name = name;
|
||||||
b->opnum = opnum;
|
b->opnum = opnum;
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
PatternAST
|
PatternAST
|
||||||
newPatternAST(op, children) char *op; List children;
|
newPatternAST(op, children) char *op; List children;
|
||||||
{
|
{
|
||||||
PatternAST p = (PatternAST) zalloc(sizeof(struct patternAST));
|
PatternAST p = (PatternAST) zalloc(sizeof(struct patternAST));
|
||||||
p->op = op;
|
p->op = op;
|
||||||
p->children = children;
|
p->children = children;
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
int max_ruleAST;
|
int max_ruleAST;
|
||||||
@@ -319,85 +319,85 @@ int max_ruleAST;
|
|||||||
RuleAST
|
RuleAST
|
||||||
newRuleAST(lhs, pat, erulenum, cost) char *lhs; PatternAST pat; int erulenum; IntList cost;
|
newRuleAST(lhs, pat, erulenum, cost) char *lhs; PatternAST pat; int erulenum; IntList cost;
|
||||||
{
|
{
|
||||||
RuleAST p = (RuleAST) zalloc(sizeof(struct ruleAST));
|
RuleAST p = (RuleAST) zalloc(sizeof(struct ruleAST));
|
||||||
p->lhs = lhs;
|
p->lhs = lhs;
|
||||||
p->pat = pat;
|
p->pat = pat;
|
||||||
if (erulenum <= 0) {
|
if (erulenum <= 0) {
|
||||||
yyerror1("External Rulenumber ");
|
yyerror1("External Rulenumber ");
|
||||||
fprintf(stderr, "(%d) <= 0\n", erulenum);
|
fprintf(stderr, "(%d) <= 0\n", erulenum);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
p->erulenum = erulenum;
|
p->erulenum = erulenum;
|
||||||
p->cost = cost;
|
p->cost = cost;
|
||||||
max_ruleAST++;
|
max_ruleAST++;
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dumpBinding(b) Binding b;
|
dumpBinding(b) Binding b;
|
||||||
{
|
{
|
||||||
printf("%s=%d ", b->name, b->opnum);
|
printf("%s=%d ", b->name, b->opnum);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dumpArity(a) Arity a;
|
dumpArity(a) Arity a;
|
||||||
{
|
{
|
||||||
List l;
|
List l;
|
||||||
|
|
||||||
printf("Arity(%d) ", a->arity);
|
printf("Arity(%d) ", a->arity);
|
||||||
for (l = a->bindings; l; l = l->next) {
|
for (l = a->bindings; l; l = l->next) {
|
||||||
Binding b = (Binding) l->x;
|
Binding b = (Binding) l->x;
|
||||||
dumpBinding(b);
|
dumpBinding(b);
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dumpPatternAST(p) PatternAST p;
|
dumpPatternAST(p) PatternAST p;
|
||||||
{
|
{
|
||||||
List l;
|
List l;
|
||||||
|
|
||||||
printf("%s", p->op);
|
printf("%s", p->op);
|
||||||
if (p->children) {
|
if (p->children) {
|
||||||
printf("(");
|
printf("(");
|
||||||
for (l = p->children; l; l = l->next) {
|
for (l = p->children; l; l = l->next) {
|
||||||
PatternAST past = (PatternAST) l->x;
|
PatternAST past = (PatternAST) l->x;
|
||||||
dumpPatternAST(past);
|
dumpPatternAST(past);
|
||||||
if (l->next) {
|
if (l->next) {
|
||||||
printf(", ");
|
printf(", ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf(")");
|
printf(")");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dumpRuleAST(p) RuleAST p;
|
dumpRuleAST(p) RuleAST p;
|
||||||
{
|
{
|
||||||
printf("%s : ", p->lhs);
|
printf("%s : ", p->lhs);
|
||||||
dumpPatternAST(p->pat);
|
dumpPatternAST(p->pat);
|
||||||
printf(" = %d (%ld)\n", p->erulenum, (long) p->cost);
|
printf(" = %d (%ld)\n", p->erulenum, (long) p->cost);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dumpDecls(decls) List decls;
|
dumpDecls(decls) List decls;
|
||||||
{
|
{
|
||||||
List l;
|
List l;
|
||||||
|
|
||||||
for (l = decls; l; l = l->next) {
|
for (l = decls; l; l = l->next) {
|
||||||
Arity a = (Arity) l->x;
|
Arity a = (Arity) l->x;
|
||||||
dumpArity(a);
|
dumpArity(a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dumpRules(rules) List rules;
|
dumpRules(rules) List rules;
|
||||||
{
|
{
|
||||||
List l;
|
List l;
|
||||||
|
|
||||||
for (l = rules; l; l = l->next) {
|
for (l = rules; l; l = l->next) {
|
||||||
RuleAST p = (RuleAST) l->x;
|
RuleAST p = (RuleAST) l->x;
|
||||||
dumpRuleAST(p);
|
dumpRuleAST(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,62 +1,62 @@
|
|||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
struct binding {
|
struct binding {
|
||||||
char *name;
|
char *name;
|
||||||
int opnum;
|
int opnum;
|
||||||
};
|
};
|
||||||
typedef struct binding *Binding;
|
typedef struct binding *Binding;
|
||||||
|
|
||||||
struct arity {
|
struct arity {
|
||||||
int arity;
|
int arity;
|
||||||
List bindings;
|
List bindings;
|
||||||
};
|
};
|
||||||
typedef struct arity *Arity;
|
typedef struct arity *Arity;
|
||||||
|
|
||||||
struct patternAST {
|
struct patternAST {
|
||||||
struct symbol *sym;
|
struct symbol *sym;
|
||||||
char *op;
|
char *op;
|
||||||
List children;
|
List children;
|
||||||
};
|
};
|
||||||
typedef struct patternAST *PatternAST;
|
typedef struct patternAST *PatternAST;
|
||||||
|
|
||||||
struct ruleAST {
|
struct ruleAST {
|
||||||
char *lhs;
|
char *lhs;
|
||||||
PatternAST pat;
|
PatternAST pat;
|
||||||
int erulenum;
|
int erulenum;
|
||||||
IntList cost;
|
IntList cost;
|
||||||
struct rule *rule;
|
struct rule *rule;
|
||||||
struct strTableElement *kids;
|
struct strTableElement *kids;
|
||||||
struct strTableElement *nts;
|
struct strTableElement *nts;
|
||||||
};
|
};
|
||||||
typedef struct ruleAST *RuleAST;
|
typedef struct ruleAST *RuleAST;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
UNKNOWN,
|
UNKNOWN,
|
||||||
OPERATOR,
|
OPERATOR,
|
||||||
NONTERMINAL
|
NONTERMINAL
|
||||||
} TagType;
|
} TagType;
|
||||||
|
|
||||||
struct symbol {
|
struct symbol {
|
||||||
char *name;
|
char *name;
|
||||||
TagType tag;
|
TagType tag;
|
||||||
union {
|
union {
|
||||||
NonTerminal nt;
|
NonTerminal nt;
|
||||||
Operator op;
|
Operator op;
|
||||||
} u;
|
} u;
|
||||||
};
|
};
|
||||||
typedef struct symbol *Symbol;
|
typedef struct symbol *Symbol;
|
||||||
|
|
||||||
struct strTableElement {
|
struct strTableElement {
|
||||||
char *str;
|
char *str;
|
||||||
IntList erulenos;
|
IntList erulenos;
|
||||||
char *ename;
|
char *ename;
|
||||||
};
|
};
|
||||||
typedef struct strTableElement *StrTableElement;
|
typedef struct strTableElement *StrTableElement;
|
||||||
|
|
||||||
struct strTable {
|
struct strTable {
|
||||||
List elems;
|
List elems;
|
||||||
};
|
};
|
||||||
typedef struct strTable *StrTable;
|
typedef struct strTable *StrTable;
|
||||||
|
|
||||||
extern void doGrammarNts ARGS((void));
|
extern void doGrammarNts ARGS((void));
|
||||||
void makeRuleDescArray ARGS((void));
|
void makeRuleDescArray ARGS((void));
|
||||||
@@ -122,11 +122,11 @@ extern void dumpStrTable ARGS((StrTable));
|
|||||||
extern int yylex ARGS((void));
|
extern int yylex ARGS((void));
|
||||||
extern int yyparse ARGS((void));
|
extern int yyparse ARGS((void));
|
||||||
|
|
||||||
extern int max_ruleAST;
|
extern int max_ruleAST;
|
||||||
extern List ruleASTs;
|
extern List ruleASTs;
|
||||||
|
|
||||||
extern FILE *outfile;
|
extern FILE *outfile;
|
||||||
extern const char *prefix;
|
extern const char *prefix;
|
||||||
extern int trimflag;
|
extern int trimflag;
|
||||||
extern int speedflag;
|
extern int speedflag;
|
||||||
extern int grammarflag;
|
extern int grammarflag;
|
||||||
|
|||||||
@@ -10,124 +10,124 @@ static Item_Set fptr;
|
|||||||
ItemArray
|
ItemArray
|
||||||
newItemArray()
|
newItemArray()
|
||||||
{
|
{
|
||||||
ItemArray ia;
|
ItemArray ia;
|
||||||
ia = (ItemArray) zalloc(max_nonterminal *sizeof(*ia));
|
ia = (ItemArray) zalloc(max_nonterminal *sizeof(*ia));
|
||||||
return ia;
|
return ia;
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemArray
|
ItemArray
|
||||||
itemArrayCopy(src) ItemArray src;
|
itemArrayCopy(src) ItemArray src;
|
||||||
{
|
{
|
||||||
ItemArray dst;
|
ItemArray dst;
|
||||||
|
|
||||||
dst = newItemArray();
|
dst = newItemArray();
|
||||||
memcpy(dst, src, max_nonterminal * sizeof(*dst));
|
memcpy(dst, src, max_nonterminal * sizeof(*dst));
|
||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
Item_Set
|
Item_Set
|
||||||
newItem_Set(relevant) Relevant relevant;
|
newItem_Set(relevant) Relevant relevant;
|
||||||
{
|
{
|
||||||
Item_Set ts;
|
Item_Set ts;
|
||||||
|
|
||||||
if (fptr) {
|
if (fptr) {
|
||||||
ts = fptr;
|
ts = fptr;
|
||||||
fptr = 0;
|
fptr = 0;
|
||||||
memset(ts->virgin, 0, max_nonterminal * sizeof(struct item));
|
memset(ts->virgin, 0, max_nonterminal * sizeof(struct item));
|
||||||
if (ts->closed) {
|
if (ts->closed) {
|
||||||
zfree(ts->closed);
|
zfree(ts->closed);
|
||||||
ts->closed = 0;
|
ts->closed = 0;
|
||||||
}
|
}
|
||||||
ts->num = 0;
|
ts->num = 0;
|
||||||
ts->op = 0;
|
ts->op = 0;
|
||||||
} else {
|
} else {
|
||||||
ts = (Item_Set) zalloc(sizeof(struct item_set));
|
ts = (Item_Set) zalloc(sizeof(struct item_set));
|
||||||
ts->virgin = newItemArray();
|
ts->virgin = newItemArray();
|
||||||
}
|
}
|
||||||
ts->relevant = relevant;
|
ts->relevant = relevant;
|
||||||
return ts;
|
return ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
freeItem_Set(ts) Item_Set ts;
|
freeItem_Set(ts) Item_Set ts;
|
||||||
{
|
{
|
||||||
assert(!fptr);
|
assert(!fptr);
|
||||||
fptr = ts;
|
fptr = ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
equivSet(a, b) Item_Set a; Item_Set b;
|
equivSet(a, b) Item_Set a; Item_Set b;
|
||||||
{
|
{
|
||||||
register Relevant r;
|
register Relevant r;
|
||||||
register int nt;
|
register int nt;
|
||||||
register Item *aa = a->virgin;
|
register Item *aa = a->virgin;
|
||||||
register Item *ba = b->virgin;
|
register Item *ba = b->virgin;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
return !bcmp(a->virgin, b->virgin, max_nonterminal * sizeof(Item));
|
return !bcmp(a->virgin, b->virgin, max_nonterminal * sizeof(Item));
|
||||||
*/
|
*/
|
||||||
|
|
||||||
r = a->relevant ? a->relevant : b->relevant;
|
r = a->relevant ? a->relevant : b->relevant;
|
||||||
assert(r);
|
assert(r);
|
||||||
|
|
||||||
if (a->op && b->op && a->op != b->op) {
|
if (a->op && b->op && a->op != b->op) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
for (; (nt = *r) != 0; r++) {
|
for (; (nt = *r) != 0; r++) {
|
||||||
if (aa[nt].rule != ba[nt].rule || !EQUALCOST(aa[nt].delta, ba[nt].delta)) {
|
if (aa[nt].rule != ba[nt].rule || !EQUALCOST(aa[nt].delta, ba[nt].delta)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
printRepresentative(f, s) FILE *f; Item_Set s;
|
printRepresentative(f, s) FILE *f; Item_Set s;
|
||||||
{
|
{
|
||||||
if (!s) {
|
if (!s) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fprintf(f, "%s", s->op->name);
|
fprintf(f, "%s", s->op->name);
|
||||||
switch (s->op->arity) {
|
switch (s->op->arity) {
|
||||||
case 1:
|
case 1:
|
||||||
fprintf(f, "(");
|
fprintf(f, "(");
|
||||||
printRepresentative(f, s->kids[0]);
|
printRepresentative(f, s->kids[0]);
|
||||||
fprintf(f, ")");
|
fprintf(f, ")");
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
fprintf(f, "(");
|
fprintf(f, "(");
|
||||||
printRepresentative(f, s->kids[0]);
|
printRepresentative(f, s->kids[0]);
|
||||||
fprintf(f, ", ");
|
fprintf(f, ", ");
|
||||||
printRepresentative(f, s->kids[1]);
|
printRepresentative(f, s->kids[1]);
|
||||||
fprintf(f, ")");
|
fprintf(f, ")");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dumpItem(t) Item *t;
|
dumpItem(t) Item *t;
|
||||||
{
|
{
|
||||||
printf("[%s #%d]", t->rule->lhs->name, t->rule->num);
|
printf("[%s #%d]", t->rule->lhs->name, t->rule->num);
|
||||||
dumpCost(t->delta);
|
dumpCost(t->delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dumpItem_Set(ts) Item_Set ts;
|
dumpItem_Set(ts) Item_Set ts;
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
printf("Item_Set #%d: [", ts->num);
|
printf("Item_Set #%d: [", ts->num);
|
||||||
for (i = 1; i < max_nonterminal; i++) {
|
for (i = 1; i < max_nonterminal; i++) {
|
||||||
if (ts->virgin[i].rule) {
|
if (ts->virgin[i].rule) {
|
||||||
printf(" %d", i);
|
printf(" %d", i);
|
||||||
dumpCost(ts->virgin[i].delta);
|
dumpCost(ts->virgin[i].delta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf(" ]\n");
|
printf(" ]\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dumpCost(dc) DeltaCost dc;
|
dumpCost(dc) DeltaCost dc;
|
||||||
{
|
{
|
||||||
printf("(%ld)", (long) dc);
|
printf("(%ld)", (long) dc);
|
||||||
}
|
}
|
||||||
|
|||||||
354
utils/Burg/lex.c
354
utils/Burg/lex.c
@@ -23,237 +23,237 @@ static void ReadOldComment ARGS((ReadFn));
|
|||||||
static char *
|
static char *
|
||||||
StrCopy(s) char *s;
|
StrCopy(s) char *s;
|
||||||
{
|
{
|
||||||
char *t = (char *)zalloc(strlen(s) + 1);
|
char *t = (char *)zalloc(strlen(s) + 1);
|
||||||
strcpy(t,s);
|
strcpy(t,s);
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
simple_get()
|
simple_get()
|
||||||
{
|
{
|
||||||
int ch;
|
int ch;
|
||||||
if ((ch = getchar()) == '\n') {
|
if ((ch = getchar()) == '\n') {
|
||||||
yyline++;
|
yyline++;
|
||||||
}
|
}
|
||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
code_get()
|
code_get()
|
||||||
{
|
{
|
||||||
int ch;
|
int ch;
|
||||||
if ((ch = getchar()) == '\n') {
|
if ((ch = getchar()) == '\n') {
|
||||||
yyline++;
|
yyline++;
|
||||||
}
|
}
|
||||||
if (ch != EOF) {
|
if (ch != EOF) {
|
||||||
fputc(ch, outfile);
|
fputc(ch, outfile);
|
||||||
}
|
}
|
||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
yypurge()
|
yypurge()
|
||||||
{
|
{
|
||||||
while (code_get() != EOF) ;
|
while (code_get() != EOF) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ReadCharString(rdfn, which) ReadFn rdfn; int which;
|
ReadCharString(rdfn, which) ReadFn rdfn; int which;
|
||||||
{
|
{
|
||||||
int ch;
|
int ch;
|
||||||
int backslash = 0;
|
int backslash = 0;
|
||||||
int firstline = yyline;
|
int firstline = yyline;
|
||||||
|
|
||||||
while ((ch = rdfn()) != EOF) {
|
while ((ch = rdfn()) != EOF) {
|
||||||
if (ch == which && !backslash) {
|
if (ch == which && !backslash) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (ch == '\\' && !backslash) {
|
if (ch == '\\' && !backslash) {
|
||||||
backslash = 1;
|
backslash = 1;
|
||||||
} else {
|
} else {
|
||||||
backslash = 0;
|
backslash = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
yyerror1("Unexpected EOF in string on line ");
|
yyerror1("Unexpected EOF in string on line ");
|
||||||
fprintf(stderr, "%d\n", firstline);
|
fprintf(stderr, "%d\n", firstline);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ReadOldComment(rdfn) ReadFn rdfn;
|
ReadOldComment(rdfn) ReadFn rdfn;
|
||||||
{
|
{
|
||||||
/* will not work for comments delimiter in string */
|
/* will not work for comments delimiter in string */
|
||||||
|
|
||||||
int ch;
|
int ch;
|
||||||
int starred = 0;
|
int starred = 0;
|
||||||
int firstline = yyline;
|
int firstline = yyline;
|
||||||
|
|
||||||
while ((ch = rdfn()) != EOF) {
|
while ((ch = rdfn()) != EOF) {
|
||||||
if (ch == '*') {
|
if (ch == '*') {
|
||||||
starred = 1;
|
starred = 1;
|
||||||
} else if (ch == '/' && starred) {
|
} else if (ch == '/' && starred) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
starred = 0;
|
starred = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
yyerror1("Unexpected EOF in comment on line ");
|
yyerror1("Unexpected EOF in comment on line ");
|
||||||
fprintf(stderr, "%d\n", firstline);
|
fprintf(stderr, "%d\n", firstline);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ReadCodeBlock()
|
ReadCodeBlock()
|
||||||
{
|
{
|
||||||
int ch;
|
int ch;
|
||||||
int firstline = yyline;
|
int firstline = yyline;
|
||||||
|
|
||||||
while ((ch = getchar()) != EOF) {
|
while ((ch = getchar()) != EOF) {
|
||||||
if (ch == '%') {
|
if (ch == '%') {
|
||||||
ch = getchar();
|
ch = getchar();
|
||||||
if (ch != '}') {
|
if (ch != '}') {
|
||||||
yyerror("bad %%");
|
yyerror("bad %%");
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fputc(ch, outfile);
|
fputc(ch, outfile);
|
||||||
if (ch == '\n') {
|
if (ch == '\n') {
|
||||||
yyline++;
|
yyline++;
|
||||||
}
|
}
|
||||||
if (ch == '"' || ch == '\'') {
|
if (ch == '"' || ch == '\'') {
|
||||||
ReadCharString(code_get, ch);
|
ReadCharString(code_get, ch);
|
||||||
} else if (ch == '/') {
|
} else if (ch == '/') {
|
||||||
ch = getchar();
|
ch = getchar();
|
||||||
if (ch == '*') {
|
if (ch == '*') {
|
||||||
fputc(ch, outfile);
|
fputc(ch, outfile);
|
||||||
ReadOldComment(code_get);
|
ReadOldComment(code_get);
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
ungetc(ch, stdin);
|
ungetc(ch, stdin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
yyerror1("Unclosed block of C code started on line ");
|
yyerror1("Unclosed block of C code started on line ");
|
||||||
fprintf(stderr, "%d\n", firstline);
|
fprintf(stderr, "%d\n", firstline);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int done;
|
static int done;
|
||||||
void
|
void
|
||||||
yyfinished()
|
yyfinished()
|
||||||
{
|
{
|
||||||
done = 1;
|
done = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
yylex()
|
yylex()
|
||||||
{
|
{
|
||||||
int ch;
|
int ch;
|
||||||
char *ptr = buf;
|
char *ptr = buf;
|
||||||
|
|
||||||
if (done) return 0;
|
if (done) return 0;
|
||||||
while ((ch = getchar()) != EOF) {
|
while ((ch = getchar()) != EOF) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case ' ':
|
case ' ':
|
||||||
case '\f':
|
case '\f':
|
||||||
case '\t':
|
case '\t':
|
||||||
continue;
|
continue;
|
||||||
case '\n':
|
case '\n':
|
||||||
yyline++;
|
yyline++;
|
||||||
continue;
|
continue;
|
||||||
case '(':
|
case '(':
|
||||||
case ')':
|
case ')':
|
||||||
case ',':
|
case ',':
|
||||||
case ':':
|
case ':':
|
||||||
case ';':
|
case ';':
|
||||||
case '=':
|
case '=':
|
||||||
return(ch);
|
return(ch);
|
||||||
case '/':
|
case '/':
|
||||||
ch = getchar();
|
ch = getchar();
|
||||||
if (ch == '*') {
|
if (ch == '*') {
|
||||||
ReadOldComment(simple_get);
|
ReadOldComment(simple_get);
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
ungetc(ch, stdin);
|
ungetc(ch, stdin);
|
||||||
yyerror("illegal char /");
|
yyerror("illegal char /");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
case '%':
|
case '%':
|
||||||
ch = getchar();
|
ch = getchar();
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case '%':
|
case '%':
|
||||||
return (K_PPERCENT);
|
return (K_PPERCENT);
|
||||||
case '{':
|
case '{':
|
||||||
ReadCodeBlock();
|
ReadCodeBlock();
|
||||||
continue;
|
continue;
|
||||||
case 's':
|
case 's':
|
||||||
case 'g':
|
case 'g':
|
||||||
case 't':
|
case 't':
|
||||||
do {
|
do {
|
||||||
if (ptr >= &buf[BUFSIZ]) {
|
if (ptr >= &buf[BUFSIZ]) {
|
||||||
yyerror("ID too long");
|
yyerror("ID too long");
|
||||||
return(ERROR);
|
return(ERROR);
|
||||||
} else {
|
} else {
|
||||||
*ptr++ = ch;
|
*ptr++ = ch;
|
||||||
}
|
}
|
||||||
ch = getchar();
|
ch = getchar();
|
||||||
} while (isalpha(ch) || isdigit(ch) || ch == '_');
|
} while (isalpha(ch) || isdigit(ch) || ch == '_');
|
||||||
ungetc(ch, stdin);
|
ungetc(ch, stdin);
|
||||||
*ptr = '\0';
|
*ptr = '\0';
|
||||||
if (!strcmp(buf, "term")) return K_TERM;
|
if (!strcmp(buf, "term")) return K_TERM;
|
||||||
if (!strcmp(buf, "start")) return K_START;
|
if (!strcmp(buf, "start")) return K_START;
|
||||||
if (!strcmp(buf, "gram")) return K_GRAM;
|
if (!strcmp(buf, "gram")) return K_GRAM;
|
||||||
yyerror("illegal character after %%");
|
yyerror("illegal character after %%");
|
||||||
continue;
|
continue;
|
||||||
default:
|
default:
|
||||||
yyerror("illegal character after %%");
|
yyerror("illegal character after %%");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
if (isalpha(ch) ) {
|
if (isalpha(ch) ) {
|
||||||
do {
|
do {
|
||||||
if (ptr >= &buf[BUFSIZ]) {
|
if (ptr >= &buf[BUFSIZ]) {
|
||||||
yyerror("ID too long");
|
yyerror("ID too long");
|
||||||
return(ERROR);
|
return(ERROR);
|
||||||
} else {
|
} else {
|
||||||
*ptr++ = ch;
|
*ptr++ = ch;
|
||||||
}
|
}
|
||||||
ch = getchar();
|
ch = getchar();
|
||||||
} while (isalpha(ch) || isdigit(ch) || ch == '_');
|
} while (isalpha(ch) || isdigit(ch) || ch == '_');
|
||||||
ungetc(ch, stdin);
|
ungetc(ch, stdin);
|
||||||
*ptr = '\0';
|
*ptr = '\0';
|
||||||
yylval.y_string = StrCopy(buf);
|
yylval.y_string = StrCopy(buf);
|
||||||
return(ID);
|
return(ID);
|
||||||
}
|
}
|
||||||
if (isdigit(ch)) {
|
if (isdigit(ch)) {
|
||||||
int val=0;
|
int val=0;
|
||||||
do {
|
do {
|
||||||
val *= 10;
|
val *= 10;
|
||||||
val += (ch - '0');
|
val += (ch - '0');
|
||||||
ch = getchar();
|
ch = getchar();
|
||||||
} while (isdigit(ch));
|
} while (isdigit(ch));
|
||||||
ungetc(ch, stdin);
|
ungetc(ch, stdin);
|
||||||
yylval.y_int = val;
|
yylval.y_int = val;
|
||||||
return(INT);
|
return(INT);
|
||||||
}
|
}
|
||||||
yyerror1("illegal char ");
|
yyerror1("illegal char ");
|
||||||
fprintf(stderr, "(\\%03o)\n", ch);
|
fprintf(stderr, "(\\%03o)\n", ch);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void yyerror1(const char *str)
|
void yyerror1(const char *str)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "line %d: %s", yyline, str);
|
fprintf(stderr, "line %d: %s", yyline, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
yyerror(const char *str)
|
yyerror(const char *str)
|
||||||
{
|
{
|
||||||
yyerror1(str);
|
yyerror1(str);
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,71 +5,71 @@ char rcsid_list[] = "$Id$";
|
|||||||
IntList
|
IntList
|
||||||
newIntList(x, next) int x; IntList next;
|
newIntList(x, next) int x; IntList next;
|
||||||
{
|
{
|
||||||
IntList l;
|
IntList l;
|
||||||
|
|
||||||
l = (IntList) zalloc(sizeof(*l));
|
l = (IntList) zalloc(sizeof(*l));
|
||||||
assert(l);
|
assert(l);
|
||||||
l->x = x;
|
l->x = x;
|
||||||
l->next = next;
|
l->next = next;
|
||||||
|
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
List
|
List
|
||||||
newList(x, next) void *x; List next;
|
newList(x, next) void *x; List next;
|
||||||
{
|
{
|
||||||
List l;
|
List l;
|
||||||
|
|
||||||
l = (List) zalloc(sizeof(*l));
|
l = (List) zalloc(sizeof(*l));
|
||||||
assert(l);
|
assert(l);
|
||||||
l->x = x;
|
l->x = x;
|
||||||
l->next = next;
|
l->next = next;
|
||||||
|
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
List
|
List
|
||||||
appendList(x, l) void *x; List l;
|
appendList(x, l) void *x; List l;
|
||||||
{
|
{
|
||||||
List last;
|
List last;
|
||||||
List p;
|
List p;
|
||||||
|
|
||||||
last = 0;
|
last = 0;
|
||||||
for (p = l; p; p = p->next) {
|
for (p = l; p; p = p->next) {
|
||||||
last = p;
|
last = p;
|
||||||
}
|
}
|
||||||
if (last) {
|
if (last) {
|
||||||
last->next = newList(x, 0);
|
last->next = newList(x, 0);
|
||||||
return l;
|
return l;
|
||||||
} else {
|
} else {
|
||||||
return newList(x, 0);
|
return newList(x, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
foreachList(f, l) ListFn f; List l;
|
foreachList(f, l) ListFn f; List l;
|
||||||
{
|
{
|
||||||
for (; l; l = l->next) {
|
for (; l; l = l->next) {
|
||||||
(*f)(l->x);
|
(*f)(l->x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
reveachList(f, l) ListFn f; List l;
|
reveachList(f, l) ListFn f; List l;
|
||||||
{
|
{
|
||||||
if (l) {
|
if (l) {
|
||||||
reveachList(f, l->next);
|
reveachList(f, l->next);
|
||||||
(*f)(l->x);
|
(*f)(l->x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
length(l) List l;
|
length(l) List l;
|
||||||
{
|
{
|
||||||
int c = 0;
|
int c = 0;
|
||||||
|
|
||||||
for(; l; l = l->next) {
|
for(; l; l = l->next) {
|
||||||
c++;
|
c++;
|
||||||
}
|
}
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,163 +20,163 @@ extern int main ARGS((int argc, char **argv));
|
|||||||
int
|
int
|
||||||
main(argc, argv) int argc; char **argv;
|
main(argc, argv) int argc; char **argv;
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
extern int atoi ARGS((const char *));
|
extern int atoi ARGS((const char *));
|
||||||
|
|
||||||
for (i = 1; argv[i]; i++) {
|
for (i = 1; argv[i]; i++) {
|
||||||
char **needStr = 0;
|
char **needStr = 0;
|
||||||
int *needInt = 0;
|
int *needInt = 0;
|
||||||
|
|
||||||
if (argv[i][0] == '-') {
|
if (argv[i][0] == '-') {
|
||||||
switch (argv[i][1]) {
|
switch (argv[i][1]) {
|
||||||
case 'V':
|
case 'V':
|
||||||
fprintf(stderr, "%s\n", version);
|
fprintf(stderr, "%s\n", version);
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
needStr = (char**)&prefix;
|
needStr = (char**)&prefix;
|
||||||
break;
|
break;
|
||||||
case 'o':
|
case 'o':
|
||||||
needStr = &outFileName;
|
needStr = &outFileName;
|
||||||
break;
|
break;
|
||||||
case 'I':
|
case 'I':
|
||||||
internals = 1;
|
internals = 1;
|
||||||
break;
|
break;
|
||||||
case 'T':
|
case 'T':
|
||||||
simpleTables = 1;
|
simpleTables = 1;
|
||||||
break;
|
break;
|
||||||
case '=':
|
case '=':
|
||||||
#ifdef NOLEX
|
#ifdef NOLEX
|
||||||
fprintf(stderr, "'%s' was not compiled to support lexicographic ordering\n", argv[0]);
|
fprintf(stderr, "'%s' was not compiled to support lexicographic ordering\n", argv[0]);
|
||||||
#else
|
#else
|
||||||
lexical = 1;
|
lexical = 1;
|
||||||
#endif /* NOLEX */
|
#endif /* NOLEX */
|
||||||
break;
|
break;
|
||||||
case 'O':
|
case 'O':
|
||||||
needInt = &principleCost;
|
needInt = &principleCost;
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
needInt = &prevent_divergence;
|
needInt = &prevent_divergence;
|
||||||
break;
|
break;
|
||||||
case 'e':
|
case 'e':
|
||||||
needInt = &exceptionTolerance;
|
needInt = &exceptionTolerance;
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
diagnostics = 1;
|
diagnostics = 1;
|
||||||
break;
|
break;
|
||||||
case 'S':
|
case 'S':
|
||||||
speedflag = 1;
|
speedflag = 1;
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
trimflag = 1;
|
trimflag = 1;
|
||||||
break;
|
break;
|
||||||
case 'G':
|
case 'G':
|
||||||
grammarflag = 1;
|
grammarflag = 1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "Bad option (%s)\n", argv[i]);
|
fprintf(stderr, "Bad option (%s)\n", argv[i]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (inFileName) {
|
if (inFileName) {
|
||||||
fprintf(stderr, "Unexpected Filename (%s) after (%s)\n", argv[i], inFileName);
|
fprintf(stderr, "Unexpected Filename (%s) after (%s)\n", argv[i], inFileName);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
inFileName = argv[i];
|
inFileName = argv[i];
|
||||||
}
|
}
|
||||||
if (needInt || needStr) {
|
if (needInt || needStr) {
|
||||||
char *v;
|
char *v;
|
||||||
char *opt = argv[i];
|
char *opt = argv[i];
|
||||||
|
|
||||||
if (argv[i][2]) {
|
if (argv[i][2]) {
|
||||||
v = &argv[i][2];
|
v = &argv[i][2];
|
||||||
} else {
|
} else {
|
||||||
v = argv[++i];
|
v = argv[++i];
|
||||||
if (!v) {
|
if (!v) {
|
||||||
fprintf(stderr, "Expection argument after %s\n", opt);
|
fprintf(stderr, "Expection argument after %s\n", opt);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (needInt) {
|
if (needInt) {
|
||||||
*needInt = atoi(v);
|
*needInt = atoi(v);
|
||||||
} else if (needStr) {
|
} else if (needStr) {
|
||||||
*needStr = v;
|
*needStr = v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inFileName) {
|
if (inFileName) {
|
||||||
if(freopen(inFileName, "r", stdin)==NULL) {
|
if(freopen(inFileName, "r", stdin)==NULL) {
|
||||||
fprintf(stderr, "Failed opening (%s)", inFileName);
|
fprintf(stderr, "Failed opening (%s)", inFileName);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (outFileName) {
|
if (outFileName) {
|
||||||
if ((outfile = fopen(outFileName, "w")) == NULL) {
|
if ((outfile = fopen(outFileName, "w")) == NULL) {
|
||||||
fprintf(stderr, "Failed opening (%s)", outFileName);
|
fprintf(stderr, "Failed opening (%s)", outFileName);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
outfile = stdout;
|
outfile = stdout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
yyparse();
|
yyparse();
|
||||||
|
|
||||||
if (!rules) {
|
if (!rules) {
|
||||||
fprintf(stderr, "ERROR: No rules present\n");
|
fprintf(stderr, "ERROR: No rules present\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
findChainRules();
|
findChainRules();
|
||||||
findAllPairs();
|
findAllPairs();
|
||||||
doGrammarNts();
|
doGrammarNts();
|
||||||
build();
|
build();
|
||||||
|
|
||||||
debug(debugTables, foreachList((ListFn) dumpOperator_l, operators));
|
debug(debugTables, foreachList((ListFn) dumpOperator_l, operators));
|
||||||
debug(debugTables, printf("---final set of states ---\n"));
|
debug(debugTables, printf("---final set of states ---\n"));
|
||||||
debug(debugTables, dumpMapping(globalMap));
|
debug(debugTables, dumpMapping(globalMap));
|
||||||
|
|
||||||
|
|
||||||
startBurm();
|
startBurm();
|
||||||
makeNts();
|
makeNts();
|
||||||
if (simpleTables) {
|
if (simpleTables) {
|
||||||
makeSimple();
|
makeSimple();
|
||||||
} else {
|
} else {
|
||||||
makePlanks();
|
makePlanks();
|
||||||
}
|
}
|
||||||
|
|
||||||
startOptional();
|
startOptional();
|
||||||
makeLabel();
|
makeLabel();
|
||||||
makeKids();
|
makeKids();
|
||||||
|
|
||||||
if (internals) {
|
if (internals) {
|
||||||
makeChild();
|
makeChild();
|
||||||
makeOpLabel();
|
makeOpLabel();
|
||||||
makeStateLabel();
|
makeStateLabel();
|
||||||
}
|
}
|
||||||
endOptional();
|
endOptional();
|
||||||
|
|
||||||
makeOperatorVector();
|
makeOperatorVector();
|
||||||
makeNonterminals();
|
makeNonterminals();
|
||||||
if (internals) {
|
if (internals) {
|
||||||
makeOperators();
|
makeOperators();
|
||||||
makeStringArray();
|
makeStringArray();
|
||||||
makeRuleDescArray();
|
makeRuleDescArray();
|
||||||
makeCostArray();
|
makeCostArray();
|
||||||
makeDeltaCostArray();
|
makeDeltaCostArray();
|
||||||
makeStateStringArray();
|
makeStateStringArray();
|
||||||
makeNonterminalArray();
|
makeNonterminalArray();
|
||||||
/*
|
/*
|
||||||
makeLHSmap();
|
makeLHSmap();
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
makeClosureArray();
|
makeClosureArray();
|
||||||
|
|
||||||
if (diagnostics) {
|
if (diagnostics) {
|
||||||
reportDiagnostics();
|
reportDiagnostics();
|
||||||
}
|
}
|
||||||
|
|
||||||
yypurge();
|
yypurge();
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|||||||
162
utils/Burg/map.c
162
utils/Burg/map.c
@@ -13,123 +13,123 @@ static int hash ARGS((Item_Set, int));
|
|||||||
Mapping
|
Mapping
|
||||||
newMapping(size) int size;
|
newMapping(size) int size;
|
||||||
{
|
{
|
||||||
Mapping m;
|
Mapping m;
|
||||||
|
|
||||||
m = (Mapping) zalloc(sizeof(struct mapping));
|
m = (Mapping) zalloc(sizeof(struct mapping));
|
||||||
assert(m);
|
assert(m);
|
||||||
|
|
||||||
m->count = 0;
|
m->count = 0;
|
||||||
m->hash = (List*) zalloc(size * sizeof(List));
|
m->hash = (List*) zalloc(size * sizeof(List));
|
||||||
m->hash_size = size;
|
m->hash_size = size;
|
||||||
m->max_size = STATES_INCR;
|
m->max_size = STATES_INCR;
|
||||||
m->set = (Item_Set*) zalloc(m->max_size * sizeof(Item_Set));
|
m->set = (Item_Set*) zalloc(m->max_size * sizeof(Item_Set));
|
||||||
assert(m->set);
|
assert(m->set);
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
growMapping(m) Mapping m;
|
growMapping(m) Mapping m;
|
||||||
{
|
{
|
||||||
Item_Set *tmp;
|
Item_Set *tmp;
|
||||||
|
|
||||||
m->max_size += STATES_INCR;
|
m->max_size += STATES_INCR;
|
||||||
tmp = (Item_Set*) zalloc(m->max_size * sizeof(Item_Set));
|
tmp = (Item_Set*) zalloc(m->max_size * sizeof(Item_Set));
|
||||||
memcpy(tmp, m->set, m->count * sizeof(Item_Set));
|
memcpy(tmp, m->set, m->count * sizeof(Item_Set));
|
||||||
zfree(m->set);
|
zfree(m->set);
|
||||||
m->set = tmp;
|
m->set = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
hash(ts, mod) Item_Set ts; int mod;
|
hash(ts, mod) Item_Set ts; int mod;
|
||||||
{
|
{
|
||||||
register Item *p = ts->virgin;
|
register Item *p = ts->virgin;
|
||||||
register int v;
|
register int v;
|
||||||
register Relevant r = ts->relevant;
|
register Relevant r = ts->relevant;
|
||||||
register int nt;
|
register int nt;
|
||||||
|
|
||||||
if (!ts->op) {
|
if (!ts->op) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
v = 0;
|
v = 0;
|
||||||
for (; (nt = *r) != 0; r++) {
|
for (; (nt = *r) != 0; r++) {
|
||||||
v ^= ((long)p[nt].rule) + (PRINCIPLECOST(p[nt].delta)<<4);
|
v ^= ((long)p[nt].rule) + (PRINCIPLECOST(p[nt].delta)<<4);
|
||||||
}
|
}
|
||||||
v >>= 4;
|
v >>= 4;
|
||||||
v &= (mod-1);
|
v &= (mod-1);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
Item_Set
|
Item_Set
|
||||||
encode(m, ts, new) Mapping m; Item_Set ts; int *new;
|
encode(m, ts, new) Mapping m; Item_Set ts; int *new;
|
||||||
{
|
{
|
||||||
int h;
|
int h;
|
||||||
List l;
|
List l;
|
||||||
|
|
||||||
assert(m);
|
assert(m);
|
||||||
assert(ts);
|
assert(ts);
|
||||||
assert(m->count <= m->max_size);
|
assert(m->count <= m->max_size);
|
||||||
|
|
||||||
if (grammarNts && errorState && m == globalMap) {
|
if (grammarNts && errorState && m == globalMap) {
|
||||||
List l;
|
List l;
|
||||||
int found;
|
int found;
|
||||||
|
|
||||||
found = 0;
|
found = 0;
|
||||||
for (l = grammarNts; l; l = l->next) {
|
for (l = grammarNts; l; l = l->next) {
|
||||||
Symbol s;
|
Symbol s;
|
||||||
s = (Symbol) l->x;
|
s = (Symbol) l->x;
|
||||||
|
|
||||||
if (ts->virgin[s->u.nt->num].rule) {
|
if (ts->virgin[s->u.nt->num].rule) {
|
||||||
found = 1;
|
found = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found) {
|
if (!found) {
|
||||||
*new = 0;
|
*new = 0;
|
||||||
return errorState;
|
return errorState;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*new = 0;
|
*new = 0;
|
||||||
h = hash(ts, m->hash_size);
|
h = hash(ts, m->hash_size);
|
||||||
for (l = m->hash[h]; l; l = l->next) {
|
for (l = m->hash[h]; l; l = l->next) {
|
||||||
Item_Set s = (Item_Set) l->x;
|
Item_Set s = (Item_Set) l->x;
|
||||||
if (ts->op == s->op && equivSet(ts, s)) {
|
if (ts->op == s->op && equivSet(ts, s)) {
|
||||||
ts->num = s->num;
|
ts->num = s->num;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (m->count >= m->max_size) {
|
if (m->count >= m->max_size) {
|
||||||
growMapping(m);
|
growMapping(m);
|
||||||
}
|
}
|
||||||
assert(m->count < m->max_size);
|
assert(m->count < m->max_size);
|
||||||
m->set[m->count] = ts;
|
m->set[m->count] = ts;
|
||||||
ts->num = m->count++;
|
ts->num = m->count++;
|
||||||
*new = 1;
|
*new = 1;
|
||||||
m->hash[h] = newList(ts, m->hash[h]);
|
m->hash[h] = newList(ts, m->hash[h]);
|
||||||
return ts;
|
return ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
Item_Set
|
Item_Set
|
||||||
decode(m, t) Mapping m; ItemSetNum t;
|
decode(m, t) Mapping m; ItemSetNum t;
|
||||||
{
|
{
|
||||||
assert(m);
|
assert(m);
|
||||||
assert(t);
|
assert(t);
|
||||||
assert(m->count < m->max_size);
|
assert(m->count < m->max_size);
|
||||||
assert(t < m->count);
|
assert(t < m->count);
|
||||||
|
|
||||||
return m->set[t];
|
return m->set[t];
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dumpMapping(m) Mapping m;
|
dumpMapping(m) Mapping m;
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
printf("BEGIN Mapping: Size=%d\n", m->count);
|
printf("BEGIN Mapping: Size=%d\n", m->count);
|
||||||
for (i = 0; i < m->count; i++) {
|
for (i = 0; i < m->count; i++) {
|
||||||
dumpItem_Set(m->set[i]);
|
dumpItem_Set(m->set[i]);
|
||||||
}
|
}
|
||||||
printf("END Mapping\n");
|
printf("END Mapping\n");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,46 +4,46 @@ char rcsid_nonterminal[] = "$Id$";
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
NonTerminal start;
|
NonTerminal start;
|
||||||
NonTerminalNum max_nonterminal = 1;
|
NonTerminalNum max_nonterminal = 1;
|
||||||
NonTerminalNum last_user_nonterminal;
|
NonTerminalNum last_user_nonterminal;
|
||||||
List nonterminals;
|
List nonterminals;
|
||||||
|
|
||||||
NonTerminal
|
NonTerminal
|
||||||
newNonTerminal(name) char *name;
|
newNonTerminal(name) char *name;
|
||||||
{
|
{
|
||||||
NonTerminal nt;
|
NonTerminal nt;
|
||||||
|
|
||||||
nt = (NonTerminal) zalloc(sizeof(struct nonterminal));
|
nt = (NonTerminal) zalloc(sizeof(struct nonterminal));
|
||||||
assert(nt);
|
assert(nt);
|
||||||
if (max_nonterminal == 1) {
|
if (max_nonterminal == 1) {
|
||||||
start = nt;
|
start = nt;
|
||||||
}
|
}
|
||||||
nt->name = name;
|
nt->name = name;
|
||||||
nt->num = max_nonterminal++;
|
nt->num = max_nonterminal++;
|
||||||
nonterminals = newList(nt, nonterminals);
|
nonterminals = newList(nt, nonterminals);
|
||||||
|
|
||||||
return nt;
|
return nt;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
nonTerminalName(buf, i) char *buf; int i;
|
nonTerminalName(buf, i) char *buf; int i;
|
||||||
{
|
{
|
||||||
List l;
|
List l;
|
||||||
|
|
||||||
for (l = nonterminals; l; l = l->next) {
|
for (l = nonterminals; l; l = l->next) {
|
||||||
NonTerminal nt = (NonTerminal) l->x;
|
NonTerminal nt = (NonTerminal) l->x;
|
||||||
if (nt->num == i) {
|
if (nt->num == i) {
|
||||||
strcpy(buf, nt->name);
|
strcpy(buf, nt->name);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
strcpy(buf, "(Unknown NonTerminal)");
|
strcpy(buf, "(Unknown NonTerminal)");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dumpNonTerminal(n) NonTerminal n;
|
dumpNonTerminal(n) NonTerminal n;
|
||||||
{
|
{
|
||||||
printf("%s(%d)", n->name, n->num);
|
printf("%s(%d)", n->name, n->num);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,38 +11,38 @@ List leaves;
|
|||||||
Operator
|
Operator
|
||||||
newOperator(name, num, arity) char *name; OperatorNum num; ArityNum arity;
|
newOperator(name, num, arity) char *name; OperatorNum num; ArityNum arity;
|
||||||
{
|
{
|
||||||
Operator op;
|
Operator op;
|
||||||
|
|
||||||
assert(arity <= MAX_ARITY);
|
assert(arity <= MAX_ARITY);
|
||||||
op = (Operator) zalloc(sizeof(struct operator));
|
op = (Operator) zalloc(sizeof(struct operator));
|
||||||
assert(op);
|
assert(op);
|
||||||
op->name = name;
|
op->name = name;
|
||||||
op->num = num;
|
op->num = num;
|
||||||
op->arity = arity;
|
op->arity = arity;
|
||||||
|
|
||||||
operators = newList(op, operators);
|
operators = newList(op, operators);
|
||||||
|
|
||||||
return op;
|
return op;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dumpOperator_s(op) Operator op;
|
dumpOperator_s(op) Operator op;
|
||||||
{
|
{
|
||||||
printf("Op: %s(%d)=%d\n", op->name, op->arity, op->num);
|
printf("Op: %s(%d)=%d\n", op->name, op->arity, op->num);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dumpOperator(op, full) Operator op; int full;
|
dumpOperator(op, full) Operator op; int full;
|
||||||
{
|
{
|
||||||
dumpOperator_s(op);
|
dumpOperator_s(op);
|
||||||
if (full) {
|
if (full) {
|
||||||
dumpTable(op->table, 0);
|
dumpTable(op->table, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dumpOperator_l(op) Operator op;
|
dumpOperator_l(op) Operator op;
|
||||||
{
|
{
|
||||||
dumpOperator(op, 1);
|
dumpOperator(op, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,33 +6,33 @@ char rcsid_pattern[] = "$Id$";
|
|||||||
Pattern
|
Pattern
|
||||||
newPattern(op) Operator op;
|
newPattern(op) Operator op;
|
||||||
{
|
{
|
||||||
Pattern p;
|
Pattern p;
|
||||||
|
|
||||||
p = (Pattern) zalloc(sizeof(struct pattern));
|
p = (Pattern) zalloc(sizeof(struct pattern));
|
||||||
p->op = op;
|
p->op = op;
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dumpPattern(p) Pattern p;
|
dumpPattern(p) Pattern p;
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (!p) {
|
if (!p) {
|
||||||
printf("[no-pattern]");
|
printf("[no-pattern]");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p->op) {
|
if (p->op) {
|
||||||
printf("%s", p->op->name);
|
printf("%s", p->op->name);
|
||||||
if (p->op->arity > 0) {
|
if (p->op->arity > 0) {
|
||||||
printf("(");
|
printf("(");
|
||||||
for (i = 0; i < p->op->arity; i++) {
|
for (i = 0; i < p->op->arity; i++) {
|
||||||
printf("%s ", p->children[i]->name);
|
printf("%s ", p->children[i]->name);
|
||||||
}
|
}
|
||||||
printf(")");
|
printf(")");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
printf("%s", p->children[0]->name);
|
printf("%s", p->children[0]->name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1370
utils/Burg/plank.c
1370
utils/Burg/plank.c
File diff suppressed because it is too large
Load Diff
@@ -8,57 +8,57 @@ Queue globalQ;
|
|||||||
Queue
|
Queue
|
||||||
newQ()
|
newQ()
|
||||||
{
|
{
|
||||||
Queue q;
|
Queue q;
|
||||||
|
|
||||||
q = (Queue) zalloc(sizeof(struct queue));
|
q = (Queue) zalloc(sizeof(struct queue));
|
||||||
assert(q);
|
assert(q);
|
||||||
q->head = 0;
|
q->head = 0;
|
||||||
q->tail = 0;
|
q->tail = 0;
|
||||||
|
|
||||||
return q;
|
return q;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
addQ(q, ts) Queue q; Item_Set ts;
|
addQ(q, ts) Queue q; Item_Set ts;
|
||||||
{
|
{
|
||||||
List qe;
|
List qe;
|
||||||
|
|
||||||
assert(q);
|
assert(q);
|
||||||
assert(ts);
|
assert(ts);
|
||||||
|
|
||||||
qe = newList(ts, 0);
|
qe = newList(ts, 0);
|
||||||
if (q->head) {
|
if (q->head) {
|
||||||
assert(q->tail);
|
assert(q->tail);
|
||||||
q->tail->next = qe;
|
q->tail->next = qe;
|
||||||
q->tail = qe;
|
q->tail = qe;
|
||||||
} else {
|
} else {
|
||||||
q->head = q->tail = qe;
|
q->head = q->tail = qe;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Item_Set
|
Item_Set
|
||||||
popQ(q) Queue q;
|
popQ(q) Queue q;
|
||||||
{
|
{
|
||||||
List qe;
|
List qe;
|
||||||
Item_Set ts;
|
Item_Set ts;
|
||||||
|
|
||||||
assert(q);
|
assert(q);
|
||||||
|
|
||||||
if (q->head) {
|
if (q->head) {
|
||||||
qe = q->head;
|
qe = q->head;
|
||||||
q->head = q->head->next;
|
q->head = q->head->next;
|
||||||
ts = (Item_Set) qe->x;
|
ts = (Item_Set) qe->x;
|
||||||
zfree(qe);
|
zfree(qe);
|
||||||
return ts;
|
return ts;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dumpQ(q) Queue q;
|
dumpQ(q) Queue q;
|
||||||
{
|
{
|
||||||
printf("Begin Queue\n");
|
printf("Begin Queue\n");
|
||||||
foreachList((ListFn)dumpItem_Set, q->head);
|
foreachList((ListFn)dumpItem_Set, q->head);
|
||||||
printf("End Queue\n");
|
printf("End Queue\n");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,37 +13,37 @@ List rules;
|
|||||||
Rule
|
Rule
|
||||||
newRule(delta, erulenum, lhs, pat) DeltaPtr delta; ERuleNum erulenum; NonTerminal lhs; Pattern pat;
|
newRule(delta, erulenum, lhs, pat) DeltaPtr delta; ERuleNum erulenum; NonTerminal lhs; Pattern pat;
|
||||||
{
|
{
|
||||||
Rule p;
|
Rule p;
|
||||||
|
|
||||||
p = (Rule) zalloc(sizeof(struct rule));
|
p = (Rule) zalloc(sizeof(struct rule));
|
||||||
assert(p);
|
assert(p);
|
||||||
ASSIGNCOST(p->delta, delta);
|
ASSIGNCOST(p->delta, delta);
|
||||||
p->erulenum = erulenum;
|
p->erulenum = erulenum;
|
||||||
if (erulenum > max_erule_num) {
|
if (erulenum > max_erule_num) {
|
||||||
max_erule_num = erulenum;
|
max_erule_num = erulenum;
|
||||||
}
|
}
|
||||||
p->num = max_rule++;
|
p->num = max_rule++;
|
||||||
p->lhs = lhs;
|
p->lhs = lhs;
|
||||||
p->pat = pat;
|
p->pat = pat;
|
||||||
|
|
||||||
rules = newList(p, rules);
|
rules = newList(p, rules);
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dumpRule(p) Rule p;
|
dumpRule(p) Rule p;
|
||||||
{
|
{
|
||||||
dumpNonTerminal(p->lhs);
|
dumpNonTerminal(p->lhs);
|
||||||
printf(" : ");
|
printf(" : ");
|
||||||
dumpPattern(p->pat);
|
dumpPattern(p->pat);
|
||||||
printf(" ");
|
printf(" ");
|
||||||
dumpCost(p->delta);
|
dumpCost(p->delta);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dumpRuleList(l) List l;
|
dumpRuleList(l) List l;
|
||||||
{
|
{
|
||||||
foreachList((ListFn)dumpRule, l);
|
foreachList((ListFn)dumpRule, l);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,56 +10,56 @@ static StrTableElement newStrTableElement ARGS((void));
|
|||||||
StrTable
|
StrTable
|
||||||
newStrTable()
|
newStrTable()
|
||||||
{
|
{
|
||||||
return (StrTable) zalloc(sizeof(struct strTable));
|
return (StrTable) zalloc(sizeof(struct strTable));
|
||||||
}
|
}
|
||||||
|
|
||||||
static StrTableElement
|
static StrTableElement
|
||||||
newStrTableElement()
|
newStrTableElement()
|
||||||
{
|
{
|
||||||
return (StrTableElement) zalloc(sizeof(struct strTableElement));
|
return (StrTableElement) zalloc(sizeof(struct strTableElement));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dumpStrTable(t) StrTable t;
|
dumpStrTable(t) StrTable t;
|
||||||
{
|
{
|
||||||
List e;
|
List e;
|
||||||
IntList r;
|
IntList r;
|
||||||
|
|
||||||
printf("Begin StrTable\n");
|
printf("Begin StrTable\n");
|
||||||
for (e = t->elems; e; e = e->next) {
|
for (e = t->elems; e; e = e->next) {
|
||||||
StrTableElement el = (StrTableElement) e->x;
|
StrTableElement el = (StrTableElement) e->x;
|
||||||
printf("%s: ", el->str);
|
printf("%s: ", el->str);
|
||||||
for (r = el->erulenos; r; r = r->next) {
|
for (r = el->erulenos; r; r = r->next) {
|
||||||
int i = r->x;
|
int i = r->x;
|
||||||
printf("(%d)", i);
|
printf("(%d)", i);
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
printf("End StrTable\n");
|
printf("End StrTable\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
StrTableElement
|
StrTableElement
|
||||||
addString(t, s, eruleno, new) StrTable t; char *s; int eruleno; int *new;
|
addString(t, s, eruleno, new) StrTable t; char *s; int eruleno; int *new;
|
||||||
{
|
{
|
||||||
List l;
|
List l;
|
||||||
StrTableElement ste;
|
StrTableElement ste;
|
||||||
|
|
||||||
assert(t);
|
assert(t);
|
||||||
for (l = t->elems; l; l = l->next) {
|
for (l = t->elems; l; l = l->next) {
|
||||||
StrTableElement e = (StrTableElement) l->x;
|
StrTableElement e = (StrTableElement) l->x;
|
||||||
|
|
||||||
assert(e);
|
assert(e);
|
||||||
if (!strcmp(s, e->str)) {
|
if (!strcmp(s, e->str)) {
|
||||||
e->erulenos = newIntList(eruleno, e->erulenos);
|
e->erulenos = newIntList(eruleno, e->erulenos);
|
||||||
*new = 0;
|
*new = 0;
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ste = newStrTableElement();
|
ste = newStrTableElement();
|
||||||
ste->erulenos = newIntList(eruleno, 0);
|
ste->erulenos = newIntList(eruleno, 0);
|
||||||
ste->str = (char *) zalloc(strlen(s) + 1);
|
ste->str = (char *) zalloc(strlen(s) + 1);
|
||||||
strcpy(ste->str, s);
|
strcpy(ste->str, s);
|
||||||
t->elems = newList(ste, t->elems);
|
t->elems = newList(ste, t->elems);
|
||||||
*new = 1;
|
*new = 1;
|
||||||
return ste;
|
return ste;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,29 +10,29 @@ static List symtab;
|
|||||||
Symbol
|
Symbol
|
||||||
newSymbol(name) char *name;
|
newSymbol(name) char *name;
|
||||||
{
|
{
|
||||||
Symbol s;
|
Symbol s;
|
||||||
|
|
||||||
s = (Symbol) zalloc(sizeof(struct symbol));
|
s = (Symbol) zalloc(sizeof(struct symbol));
|
||||||
assert(s);
|
assert(s);
|
||||||
s->name = name;
|
s->name = name;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
Symbol
|
Symbol
|
||||||
enter(name, new) char *name; int *new;
|
enter(name, new) char *name; int *new;
|
||||||
{
|
{
|
||||||
List l;
|
List l;
|
||||||
Symbol s;
|
Symbol s;
|
||||||
|
|
||||||
*new = 0;
|
*new = 0;
|
||||||
for (l = symtab; l; l = l->next) {
|
for (l = symtab; l; l = l->next) {
|
||||||
s = (Symbol) l->x;
|
s = (Symbol) l->x;
|
||||||
if (!strcmp(name, s->name)) {
|
if (!strcmp(name, s->name)) {
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*new = 1;
|
*new = 1;
|
||||||
s = newSymbol(name);
|
s = newSymbol(name);
|
||||||
symtab = newList(s, symtab);
|
symtab = newList(s, symtab);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,533 +20,533 @@ static void addHyperPlane ARGS((Table, int, Item_Set));
|
|||||||
static void
|
static void
|
||||||
growIndex_Map(r) Index_Map *r;
|
growIndex_Map(r) Index_Map *r;
|
||||||
{
|
{
|
||||||
Index_Map new;
|
Index_Map new;
|
||||||
|
|
||||||
new.max_size = r->max_size + STATES_INCR;
|
new.max_size = r->max_size + STATES_INCR;
|
||||||
new.class = (Item_Set*) zalloc(new.max_size * sizeof(Item_Set));
|
new.class = (Item_Set*) zalloc(new.max_size * sizeof(Item_Set));
|
||||||
assert(new.class);
|
assert(new.class);
|
||||||
memcpy(new.class, r->class, r->max_size * sizeof(Item_Set));
|
memcpy(new.class, r->class, r->max_size * sizeof(Item_Set));
|
||||||
zfree(r->class);
|
zfree(r->class);
|
||||||
*r = new;
|
*r = new;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Relevant
|
static Relevant
|
||||||
newRelevant()
|
newRelevant()
|
||||||
{
|
{
|
||||||
Relevant r = (Relevant) zalloc(max_nonterminal * sizeof(*r));
|
Relevant r = (Relevant) zalloc(max_nonterminal * sizeof(*r));
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
addRelevant(r, nt) Relevant r; NonTerminalNum nt;
|
addRelevant(r, nt) Relevant r; NonTerminalNum nt;
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; r[i]; i++) {
|
for (i = 0; r[i]; i++) {
|
||||||
if (r[i] == nt) {
|
if (r[i] == nt) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!r[i]) {
|
if (!r[i]) {
|
||||||
r[i] = nt;
|
r[i] = nt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Dimension
|
static Dimension
|
||||||
newDimension(op, index) Operator op; ArityNum index;
|
newDimension(op, index) Operator op; ArityNum index;
|
||||||
{
|
{
|
||||||
Dimension d;
|
Dimension d;
|
||||||
List pl;
|
List pl;
|
||||||
Relevant r;
|
Relevant r;
|
||||||
|
|
||||||
assert(op);
|
assert(op);
|
||||||
assert(index >= 0 && index < op->arity);
|
assert(index >= 0 && index < op->arity);
|
||||||
d = (Dimension) zalloc(sizeof(struct dimension));
|
d = (Dimension) zalloc(sizeof(struct dimension));
|
||||||
assert(d);
|
assert(d);
|
||||||
|
|
||||||
r = d->relevant = newRelevant();
|
r = d->relevant = newRelevant();
|
||||||
for (pl = rules; pl; pl = pl->next) {
|
for (pl = rules; pl; pl = pl->next) {
|
||||||
Rule pr = (Rule) pl->x;
|
Rule pr = (Rule) pl->x;
|
||||||
if (pr->pat->op == op) {
|
if (pr->pat->op == op) {
|
||||||
addRelevant(r, pr->pat->children[index]->num);
|
addRelevant(r, pr->pat->children[index]->num);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
d->index_map.max_size = STATES_INCR;
|
d->index_map.max_size = STATES_INCR;
|
||||||
d->index_map.class = (Item_Set*)
|
d->index_map.class = (Item_Set*)
|
||||||
zalloc(d->index_map.max_size * sizeof(Item_Set));
|
zalloc(d->index_map.max_size * sizeof(Item_Set));
|
||||||
d->map = newMapping(DIM_MAP_SIZE);
|
d->map = newMapping(DIM_MAP_SIZE);
|
||||||
d->max_size = TABLE_INCR;
|
d->max_size = TABLE_INCR;
|
||||||
|
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
Table
|
Table
|
||||||
newTable(op) Operator op;
|
newTable(op) Operator op;
|
||||||
{
|
{
|
||||||
Table t;
|
Table t;
|
||||||
int i, size;
|
int i, size;
|
||||||
|
|
||||||
assert(op);
|
assert(op);
|
||||||
|
|
||||||
t = (Table) zalloc(sizeof(struct table));
|
t = (Table) zalloc(sizeof(struct table));
|
||||||
assert(t);
|
assert(t);
|
||||||
|
|
||||||
t->op = op;
|
t->op = op;
|
||||||
|
|
||||||
for (i = 0; i < op->arity; i++) {
|
for (i = 0; i < op->arity; i++) {
|
||||||
t->dimen[i] = newDimension(op, i);
|
t->dimen[i] = newDimension(op, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
size = 1;
|
size = 1;
|
||||||
for (i = 0; i < op->arity; i++) {
|
for (i = 0; i < op->arity; i++) {
|
||||||
size *= t->dimen[i]->max_size;
|
size *= t->dimen[i]->max_size;
|
||||||
}
|
}
|
||||||
t->transition = (Item_Set*) zalloc(size * sizeof(Item_Set));
|
t->transition = (Item_Set*) zalloc(size * sizeof(Item_Set));
|
||||||
t->relevant = newRelevant();
|
t->relevant = newRelevant();
|
||||||
assert(t->transition);
|
assert(t->transition);
|
||||||
|
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
GT_1(t) Table t;
|
GT_1(t) Table t;
|
||||||
{
|
{
|
||||||
Item_Set *ts;
|
Item_Set *ts;
|
||||||
ItemSetNum oldsize = t->dimen[0]->max_size;
|
ItemSetNum oldsize = t->dimen[0]->max_size;
|
||||||
ItemSetNum newsize = t->dimen[0]->max_size + TABLE_INCR;
|
ItemSetNum newsize = t->dimen[0]->max_size + TABLE_INCR;
|
||||||
|
|
||||||
t->dimen[0]->max_size = newsize;
|
t->dimen[0]->max_size = newsize;
|
||||||
|
|
||||||
ts = (Item_Set*) zalloc(newsize * sizeof(Item_Set));
|
ts = (Item_Set*) zalloc(newsize * sizeof(Item_Set));
|
||||||
assert(ts);
|
assert(ts);
|
||||||
memcpy(ts, t->transition, oldsize * sizeof(Item_Set));
|
memcpy(ts, t->transition, oldsize * sizeof(Item_Set));
|
||||||
zfree(t->transition);
|
zfree(t->transition);
|
||||||
t->transition = ts;
|
t->transition = ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
GT_2_0(t) Table t;
|
GT_2_0(t) Table t;
|
||||||
{
|
{
|
||||||
Item_Set *ts;
|
Item_Set *ts;
|
||||||
ItemSetNum oldsize = t->dimen[0]->max_size;
|
ItemSetNum oldsize = t->dimen[0]->max_size;
|
||||||
ItemSetNum newsize = t->dimen[0]->max_size + TABLE_INCR;
|
ItemSetNum newsize = t->dimen[0]->max_size + TABLE_INCR;
|
||||||
int size;
|
int size;
|
||||||
|
|
||||||
t->dimen[0]->max_size = newsize;
|
t->dimen[0]->max_size = newsize;
|
||||||
|
|
||||||
size = newsize * t->dimen[1]->max_size;
|
size = newsize * t->dimen[1]->max_size;
|
||||||
|
|
||||||
ts = (Item_Set*) zalloc(size * sizeof(Item_Set));
|
ts = (Item_Set*) zalloc(size * sizeof(Item_Set));
|
||||||
assert(ts);
|
assert(ts);
|
||||||
memcpy(ts, t->transition, oldsize*t->dimen[1]->max_size * sizeof(Item_Set));
|
memcpy(ts, t->transition, oldsize*t->dimen[1]->max_size * sizeof(Item_Set));
|
||||||
zfree(t->transition);
|
zfree(t->transition);
|
||||||
t->transition = ts;
|
t->transition = ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
GT_2_1(t) Table t;
|
GT_2_1(t) Table t;
|
||||||
{
|
{
|
||||||
Item_Set *ts;
|
Item_Set *ts;
|
||||||
ItemSetNum oldsize = t->dimen[1]->max_size;
|
ItemSetNum oldsize = t->dimen[1]->max_size;
|
||||||
ItemSetNum newsize = t->dimen[1]->max_size + TABLE_INCR;
|
ItemSetNum newsize = t->dimen[1]->max_size + TABLE_INCR;
|
||||||
int size;
|
int size;
|
||||||
Item_Set *from;
|
Item_Set *from;
|
||||||
Item_Set *to;
|
Item_Set *to;
|
||||||
int i1, i2;
|
int i1, i2;
|
||||||
|
|
||||||
t->dimen[1]->max_size = newsize;
|
t->dimen[1]->max_size = newsize;
|
||||||
|
|
||||||
size = newsize * t->dimen[0]->max_size;
|
size = newsize * t->dimen[0]->max_size;
|
||||||
|
|
||||||
ts = (Item_Set*) zalloc(size * sizeof(Item_Set));
|
ts = (Item_Set*) zalloc(size * sizeof(Item_Set));
|
||||||
assert(ts);
|
assert(ts);
|
||||||
|
|
||||||
from = t->transition;
|
from = t->transition;
|
||||||
to = ts;
|
to = ts;
|
||||||
for (i1 = 0; i1 < t->dimen[0]->max_size; i1++) {
|
for (i1 = 0; i1 < t->dimen[0]->max_size; i1++) {
|
||||||
for (i2 = 0; i2 < oldsize; i2++) {
|
for (i2 = 0; i2 < oldsize; i2++) {
|
||||||
to[i2] = from[i2];
|
to[i2] = from[i2];
|
||||||
}
|
}
|
||||||
to += newsize;
|
to += newsize;
|
||||||
from += oldsize;
|
from += oldsize;
|
||||||
}
|
}
|
||||||
zfree(t->transition);
|
zfree(t->transition);
|
||||||
t->transition = ts;
|
t->transition = ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
growTransition(t, dim) Table t; ArityNum dim;
|
growTransition(t, dim) Table t; ArityNum dim;
|
||||||
{
|
{
|
||||||
|
|
||||||
assert(t);
|
assert(t);
|
||||||
assert(t->op);
|
assert(t->op);
|
||||||
assert(dim < t->op->arity);
|
assert(dim < t->op->arity);
|
||||||
|
|
||||||
switch (t->op->arity) {
|
switch (t->op->arity) {
|
||||||
default:
|
default:
|
||||||
assert(0);
|
assert(0);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
GT_1(t);
|
GT_1(t);
|
||||||
return;
|
return;
|
||||||
case 2:
|
case 2:
|
||||||
switch (dim) {
|
switch (dim) {
|
||||||
default:
|
default:
|
||||||
assert(0);
|
assert(0);
|
||||||
break;
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
GT_2_0(t);
|
GT_2_0(t);
|
||||||
return;
|
return;
|
||||||
case 1:
|
case 1:
|
||||||
GT_2_1(t);
|
GT_2_1(t);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Item_Set
|
static Item_Set
|
||||||
restrict(d, ts) Dimension d; Item_Set ts;
|
restrict(d, ts) Dimension d; Item_Set ts;
|
||||||
{
|
{
|
||||||
DeltaCost base;
|
DeltaCost base;
|
||||||
Item_Set r;
|
Item_Set r;
|
||||||
int found;
|
int found;
|
||||||
register Relevant r_ptr = d->relevant;
|
register Relevant r_ptr = d->relevant;
|
||||||
register Item *ts_current = ts->closed;
|
register Item *ts_current = ts->closed;
|
||||||
register Item *r_current;
|
register Item *r_current;
|
||||||
register int i;
|
register int i;
|
||||||
register int nt;
|
register int nt;
|
||||||
|
|
||||||
ZEROCOST(base);
|
ZEROCOST(base);
|
||||||
found = 0;
|
found = 0;
|
||||||
r = newItem_Set(d->relevant);
|
r = newItem_Set(d->relevant);
|
||||||
r_current = r->virgin;
|
r_current = r->virgin;
|
||||||
for (i = 0; (nt = r_ptr[i]) != 0; i++) {
|
for (i = 0; (nt = r_ptr[i]) != 0; i++) {
|
||||||
if (ts_current[nt].rule) {
|
if (ts_current[nt].rule) {
|
||||||
r_current[nt].rule = &stub_rule;
|
r_current[nt].rule = &stub_rule;
|
||||||
if (!found) {
|
if (!found) {
|
||||||
found = 1;
|
found = 1;
|
||||||
ASSIGNCOST(base, ts_current[nt].delta);
|
ASSIGNCOST(base, ts_current[nt].delta);
|
||||||
} else {
|
} else {
|
||||||
if (LESSCOST(ts_current[nt].delta, base)) {
|
if (LESSCOST(ts_current[nt].delta, base)) {
|
||||||
ASSIGNCOST(base, ts_current[nt].delta);
|
ASSIGNCOST(base, ts_current[nt].delta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* zero align */
|
/* zero align */
|
||||||
for (i = 0; (nt = r_ptr[i]) != 0; i++) {
|
for (i = 0; (nt = r_ptr[i]) != 0; i++) {
|
||||||
if (r_current[nt].rule) {
|
if (r_current[nt].rule) {
|
||||||
ASSIGNCOST(r_current[nt].delta, ts_current[nt].delta);
|
ASSIGNCOST(r_current[nt].delta, ts_current[nt].delta);
|
||||||
MINUSCOST(r_current[nt].delta, base);
|
MINUSCOST(r_current[nt].delta, base);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert(!r->closed);
|
assert(!r->closed);
|
||||||
r->representative = ts;
|
r->representative = ts;
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
addHP_1(t, ts) Table t; Item_Set ts;
|
addHP_1(t, ts) Table t; Item_Set ts;
|
||||||
{
|
{
|
||||||
List pl;
|
List pl;
|
||||||
Item_Set e;
|
Item_Set e;
|
||||||
Item_Set tmp;
|
Item_Set tmp;
|
||||||
int new;
|
int new;
|
||||||
|
|
||||||
e = newItem_Set(t->relevant);
|
e = newItem_Set(t->relevant);
|
||||||
assert(e);
|
assert(e);
|
||||||
e->kids[0] = ts->representative;
|
e->kids[0] = ts->representative;
|
||||||
for (pl = t->rules; pl; pl = pl->next) {
|
for (pl = t->rules; pl; pl = pl->next) {
|
||||||
Rule p = (Rule) pl->x;
|
Rule p = (Rule) pl->x;
|
||||||
if (t->op == p->pat->op && ts->virgin[p->pat->children[0]->num].rule) {
|
if (t->op == p->pat->op && ts->virgin[p->pat->children[0]->num].rule) {
|
||||||
DeltaCost dc;
|
DeltaCost dc;
|
||||||
ASSIGNCOST(dc, ts->virgin[p->pat->children[0]->num].delta);
|
ASSIGNCOST(dc, ts->virgin[p->pat->children[0]->num].delta);
|
||||||
ADDCOST(dc, p->delta);
|
ADDCOST(dc, p->delta);
|
||||||
if (!e->virgin[p->lhs->num].rule || LESSCOST(dc, e->virgin[p->lhs->num].delta)) {
|
if (!e->virgin[p->lhs->num].rule || LESSCOST(dc, e->virgin[p->lhs->num].delta)) {
|
||||||
e->virgin[p->lhs->num].rule = p;
|
e->virgin[p->lhs->num].rule = p;
|
||||||
ASSIGNCOST(e->virgin[p->lhs->num].delta, dc);
|
ASSIGNCOST(e->virgin[p->lhs->num].delta, dc);
|
||||||
e->op = t->op;
|
e->op = t->op;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
trim(e);
|
trim(e);
|
||||||
zero(e);
|
zero(e);
|
||||||
tmp = encode(globalMap, e, &new);
|
tmp = encode(globalMap, e, &new);
|
||||||
assert(ts->num < t->dimen[0]->map->max_size);
|
assert(ts->num < t->dimen[0]->map->max_size);
|
||||||
t->transition[ts->num] = tmp;
|
t->transition[ts->num] = tmp;
|
||||||
if (new) {
|
if (new) {
|
||||||
closure(e);
|
closure(e);
|
||||||
addQ(globalQ, tmp);
|
addQ(globalQ, tmp);
|
||||||
} else {
|
} else {
|
||||||
freeItem_Set(e);
|
freeItem_Set(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
addHP_2_0(t, ts) Table t; Item_Set ts;
|
addHP_2_0(t, ts) Table t; Item_Set ts;
|
||||||
{
|
{
|
||||||
List pl;
|
List pl;
|
||||||
register Item_Set e;
|
register Item_Set e;
|
||||||
Item_Set tmp;
|
Item_Set tmp;
|
||||||
int new;
|
int new;
|
||||||
int i2;
|
int i2;
|
||||||
|
|
||||||
assert(t->dimen[1]->map->count <= t->dimen[1]->map->max_size);
|
assert(t->dimen[1]->map->count <= t->dimen[1]->map->max_size);
|
||||||
for (i2 = 0; i2 < t->dimen[1]->map->count; i2++) {
|
for (i2 = 0; i2 < t->dimen[1]->map->count; i2++) {
|
||||||
e = newItem_Set(t->relevant);
|
e = newItem_Set(t->relevant);
|
||||||
assert(e);
|
assert(e);
|
||||||
e->kids[0] = ts->representative;
|
e->kids[0] = ts->representative;
|
||||||
e->kids[1] = t->dimen[1]->map->set[i2]->representative;
|
e->kids[1] = t->dimen[1]->map->set[i2]->representative;
|
||||||
for (pl = t->rules; pl; pl = pl->next) {
|
for (pl = t->rules; pl; pl = pl->next) {
|
||||||
register Rule p = (Rule) pl->x;
|
register Rule p = (Rule) pl->x;
|
||||||
|
|
||||||
if (t->op == p->pat->op
|
if (t->op == p->pat->op
|
||||||
&& ts->virgin[p->pat->children[0]->num].rule
|
&& ts->virgin[p->pat->children[0]->num].rule
|
||||||
&& t->dimen[1]->map->set[i2]->virgin[p->pat->children[1]->num].rule){
|
&& t->dimen[1]->map->set[i2]->virgin[p->pat->children[1]->num].rule){
|
||||||
DeltaCost dc;
|
DeltaCost dc;
|
||||||
ASSIGNCOST(dc, p->delta);
|
ASSIGNCOST(dc, p->delta);
|
||||||
ADDCOST(dc, ts->virgin[p->pat->children[0]->num].delta);
|
ADDCOST(dc, ts->virgin[p->pat->children[0]->num].delta);
|
||||||
ADDCOST(dc, t->dimen[1]->map->set[i2]->virgin[p->pat->children[1]->num].delta);
|
ADDCOST(dc, t->dimen[1]->map->set[i2]->virgin[p->pat->children[1]->num].delta);
|
||||||
|
|
||||||
if (!e->virgin[p->lhs->num].rule || LESSCOST(dc, e->virgin[p->lhs->num].delta)) {
|
if (!e->virgin[p->lhs->num].rule || LESSCOST(dc, e->virgin[p->lhs->num].delta)) {
|
||||||
e->virgin[p->lhs->num].rule = p;
|
e->virgin[p->lhs->num].rule = p;
|
||||||
ASSIGNCOST(e->virgin[p->lhs->num].delta, dc);
|
ASSIGNCOST(e->virgin[p->lhs->num].delta, dc);
|
||||||
e->op = t->op;
|
e->op = t->op;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
trim(e);
|
trim(e);
|
||||||
zero(e);
|
zero(e);
|
||||||
tmp = encode(globalMap, e, &new);
|
tmp = encode(globalMap, e, &new);
|
||||||
assert(ts->num < t->dimen[0]->map->max_size);
|
assert(ts->num < t->dimen[0]->map->max_size);
|
||||||
t->transition[ts->num * t->dimen[1]->max_size + i2] = tmp;
|
t->transition[ts->num * t->dimen[1]->max_size + i2] = tmp;
|
||||||
if (new) {
|
if (new) {
|
||||||
closure(e);
|
closure(e);
|
||||||
addQ(globalQ, tmp);
|
addQ(globalQ, tmp);
|
||||||
} else {
|
} else {
|
||||||
freeItem_Set(e);
|
freeItem_Set(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
addHP_2_1(t, ts) Table t; Item_Set ts;
|
addHP_2_1(t, ts) Table t; Item_Set ts;
|
||||||
{
|
{
|
||||||
List pl;
|
List pl;
|
||||||
register Item_Set e;
|
register Item_Set e;
|
||||||
Item_Set tmp;
|
Item_Set tmp;
|
||||||
int new;
|
int new;
|
||||||
int i1;
|
int i1;
|
||||||
|
|
||||||
assert(t->dimen[0]->map->count <= t->dimen[0]->map->max_size);
|
assert(t->dimen[0]->map->count <= t->dimen[0]->map->max_size);
|
||||||
for (i1 = 0; i1 < t->dimen[0]->map->count; i1++) {
|
for (i1 = 0; i1 < t->dimen[0]->map->count; i1++) {
|
||||||
e = newItem_Set(t->relevant);
|
e = newItem_Set(t->relevant);
|
||||||
assert(e);
|
assert(e);
|
||||||
e->kids[0] = t->dimen[0]->map->set[i1]->representative;
|
e->kids[0] = t->dimen[0]->map->set[i1]->representative;
|
||||||
e->kids[1] = ts->representative;
|
e->kids[1] = ts->representative;
|
||||||
for (pl = t->rules; pl; pl = pl->next) {
|
for (pl = t->rules; pl; pl = pl->next) {
|
||||||
register Rule p = (Rule) pl->x;
|
register Rule p = (Rule) pl->x;
|
||||||
|
|
||||||
if (t->op == p->pat->op
|
if (t->op == p->pat->op
|
||||||
&& ts->virgin[p->pat->children[1]->num].rule
|
&& ts->virgin[p->pat->children[1]->num].rule
|
||||||
&& t->dimen[0]->map->set[i1]->virgin[p->pat->children[0]->num].rule){
|
&& t->dimen[0]->map->set[i1]->virgin[p->pat->children[0]->num].rule){
|
||||||
DeltaCost dc;
|
DeltaCost dc;
|
||||||
ASSIGNCOST(dc, p->delta );
|
ASSIGNCOST(dc, p->delta );
|
||||||
ADDCOST(dc, ts->virgin[p->pat->children[1]->num].delta);
|
ADDCOST(dc, ts->virgin[p->pat->children[1]->num].delta);
|
||||||
ADDCOST(dc, t->dimen[0]->map->set[i1]->virgin[p->pat->children[0]->num].delta);
|
ADDCOST(dc, t->dimen[0]->map->set[i1]->virgin[p->pat->children[0]->num].delta);
|
||||||
if (!e->virgin[p->lhs->num].rule || LESSCOST(dc, e->virgin[p->lhs->num].delta)) {
|
if (!e->virgin[p->lhs->num].rule || LESSCOST(dc, e->virgin[p->lhs->num].delta)) {
|
||||||
e->virgin[p->lhs->num].rule = p;
|
e->virgin[p->lhs->num].rule = p;
|
||||||
ASSIGNCOST(e->virgin[p->lhs->num].delta, dc);
|
ASSIGNCOST(e->virgin[p->lhs->num].delta, dc);
|
||||||
e->op = t->op;
|
e->op = t->op;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
trim(e);
|
trim(e);
|
||||||
zero(e);
|
zero(e);
|
||||||
tmp = encode(globalMap, e, &new);
|
tmp = encode(globalMap, e, &new);
|
||||||
assert(ts->num < t->dimen[1]->map->max_size);
|
assert(ts->num < t->dimen[1]->map->max_size);
|
||||||
t->transition[i1 * t->dimen[1]->max_size + ts->num] = tmp;
|
t->transition[i1 * t->dimen[1]->max_size + ts->num] = tmp;
|
||||||
if (new) {
|
if (new) {
|
||||||
closure(e);
|
closure(e);
|
||||||
addQ(globalQ, tmp);
|
addQ(globalQ, tmp);
|
||||||
} else {
|
} else {
|
||||||
freeItem_Set(e);
|
freeItem_Set(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
addHyperPlane(t, i, ts) Table t; ArityNum i; Item_Set ts;
|
addHyperPlane(t, i, ts) Table t; ArityNum i; Item_Set ts;
|
||||||
{
|
{
|
||||||
switch (t->op->arity) {
|
switch (t->op->arity) {
|
||||||
default:
|
default:
|
||||||
assert(0);
|
assert(0);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
addHP_1(t, ts);
|
addHP_1(t, ts);
|
||||||
return;
|
return;
|
||||||
case 2:
|
case 2:
|
||||||
switch (i) {
|
switch (i) {
|
||||||
default:
|
default:
|
||||||
assert(0);
|
assert(0);
|
||||||
break;
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
addHP_2_0(t, ts);
|
addHP_2_0(t, ts);
|
||||||
return;
|
return;
|
||||||
case 1:
|
case 1:
|
||||||
addHP_2_1(t, ts);
|
addHP_2_1(t, ts);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
addToTable(t, ts) Table t; Item_Set ts;
|
addToTable(t, ts) Table t; Item_Set ts;
|
||||||
{
|
{
|
||||||
ArityNum i;
|
ArityNum i;
|
||||||
|
|
||||||
assert(t);
|
assert(t);
|
||||||
assert(ts);
|
assert(ts);
|
||||||
assert(t->op);
|
assert(t->op);
|
||||||
|
|
||||||
for (i = 0; i < t->op->arity; i++) {
|
for (i = 0; i < t->op->arity; i++) {
|
||||||
Item_Set r;
|
Item_Set r;
|
||||||
Item_Set tmp;
|
Item_Set tmp;
|
||||||
int new;
|
int new;
|
||||||
|
|
||||||
r = restrict(t->dimen[i], ts);
|
r = restrict(t->dimen[i], ts);
|
||||||
tmp = encode(t->dimen[i]->map, r, &new);
|
tmp = encode(t->dimen[i]->map, r, &new);
|
||||||
if (t->dimen[i]->index_map.max_size <= ts->num) {
|
if (t->dimen[i]->index_map.max_size <= ts->num) {
|
||||||
growIndex_Map(&t->dimen[i]->index_map);
|
growIndex_Map(&t->dimen[i]->index_map);
|
||||||
}
|
}
|
||||||
assert(ts->num < t->dimen[i]->index_map.max_size);
|
assert(ts->num < t->dimen[i]->index_map.max_size);
|
||||||
t->dimen[i]->index_map.class[ts->num] = tmp;
|
t->dimen[i]->index_map.class[ts->num] = tmp;
|
||||||
if (new) {
|
if (new) {
|
||||||
if (t->dimen[i]->max_size <= r->num) {
|
if (t->dimen[i]->max_size <= r->num) {
|
||||||
growTransition(t, i);
|
growTransition(t, i);
|
||||||
}
|
}
|
||||||
addHyperPlane(t, i, r);
|
addHyperPlane(t, i, r);
|
||||||
} else {
|
} else {
|
||||||
freeItem_Set(r);
|
freeItem_Set(r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Item_Set *
|
Item_Set *
|
||||||
transLval(t, row, col) Table t; int row; int col;
|
transLval(t, row, col) Table t; int row; int col;
|
||||||
{
|
{
|
||||||
switch (t->op->arity) {
|
switch (t->op->arity) {
|
||||||
case 0:
|
case 0:
|
||||||
assert(row == 0);
|
assert(row == 0);
|
||||||
assert(col == 0);
|
assert(col == 0);
|
||||||
return t->transition;
|
return t->transition;
|
||||||
case 1:
|
case 1:
|
||||||
assert(col == 0);
|
assert(col == 0);
|
||||||
return t->transition + row;
|
return t->transition + row;
|
||||||
case 2:
|
case 2:
|
||||||
return t->transition + row * t->dimen[1]->max_size + col;
|
return t->transition + row * t->dimen[1]->max_size + col;
|
||||||
default:
|
default:
|
||||||
assert(0);
|
assert(0);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dumpRelevant(r) Relevant r;
|
dumpRelevant(r) Relevant r;
|
||||||
{
|
{
|
||||||
for (; *r; r++) {
|
for (; *r; r++) {
|
||||||
printf("%4d", *r);
|
printf("%4d", *r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dumpIndex_Map(r) Index_Map *r;
|
dumpIndex_Map(r) Index_Map *r;
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
printf("BEGIN Index_Map: MaxSize (%d)\n", r->max_size);
|
printf("BEGIN Index_Map: MaxSize (%d)\n", r->max_size);
|
||||||
for (i = 0; i < globalMap->count; i++) {
|
for (i = 0; i < globalMap->count; i++) {
|
||||||
printf("\t#%d: -> %d\n", i, r->class[i]->num);
|
printf("\t#%d: -> %d\n", i, r->class[i]->num);
|
||||||
}
|
}
|
||||||
printf("END Index_Map:\n");
|
printf("END Index_Map:\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dumpDimension(d) Dimension d;
|
dumpDimension(d) Dimension d;
|
||||||
{
|
{
|
||||||
printf("BEGIN Dimension:\n");
|
printf("BEGIN Dimension:\n");
|
||||||
printf("Relevant: ");
|
printf("Relevant: ");
|
||||||
dumpRelevant(d->relevant);
|
dumpRelevant(d->relevant);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
dumpIndex_Map(&d->index_map);
|
dumpIndex_Map(&d->index_map);
|
||||||
dumpMapping(d->map);
|
dumpMapping(d->map);
|
||||||
printf("MaxSize of dimension = %d\n", d->max_size);
|
printf("MaxSize of dimension = %d\n", d->max_size);
|
||||||
printf("END Dimension\n");
|
printf("END Dimension\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dumpTable(t, full) Table t; int full;
|
dumpTable(t, full) Table t; int full;
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (!t) {
|
if (!t) {
|
||||||
printf("NO Table yet.\n");
|
printf("NO Table yet.\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
printf("BEGIN Table:\n");
|
printf("BEGIN Table:\n");
|
||||||
if (full) {
|
if (full) {
|
||||||
dumpOperator(t->op, 0);
|
dumpOperator(t->op, 0);
|
||||||
}
|
}
|
||||||
for (i = 0; i < t->op->arity; i++) {
|
for (i = 0; i < t->op->arity; i++) {
|
||||||
printf("BEGIN dimension(%d)\n", i);
|
printf("BEGIN dimension(%d)\n", i);
|
||||||
dumpDimension(t->dimen[i]);
|
dumpDimension(t->dimen[i]);
|
||||||
printf("END dimension(%d)\n", i);
|
printf("END dimension(%d)\n", i);
|
||||||
}
|
}
|
||||||
dumpTransition(t);
|
dumpTransition(t);
|
||||||
printf("END Table:\n");
|
printf("END Table:\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dumpTransition(t) Table t;
|
dumpTransition(t) Table t;
|
||||||
{
|
{
|
||||||
int i,j;
|
int i,j;
|
||||||
|
|
||||||
switch (t->op->arity) {
|
switch (t->op->arity) {
|
||||||
case 0:
|
case 0:
|
||||||
printf("{ %d }", t->transition[0]->num);
|
printf("{ %d }", t->transition[0]->num);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
printf("{");
|
printf("{");
|
||||||
for (i = 0; i < t->dimen[0]->map->count; i++) {
|
for (i = 0; i < t->dimen[0]->map->count; i++) {
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
printf(",");
|
printf(",");
|
||||||
}
|
}
|
||||||
printf("%5d", t->transition[i]->num);
|
printf("%5d", t->transition[i]->num);
|
||||||
}
|
}
|
||||||
printf("}");
|
printf("}");
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
printf("{");
|
printf("{");
|
||||||
for (i = 0; i < t->dimen[0]->map->count; i++) {
|
for (i = 0; i < t->dimen[0]->map->count; i++) {
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
printf(",");
|
printf(",");
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf("{");
|
printf("{");
|
||||||
for (j = 0; j < t->dimen[1]->map->count; j++) {
|
for (j = 0; j < t->dimen[1]->map->count; j++) {
|
||||||
Item_Set *ts = transLval(t, i, j);
|
Item_Set *ts = transLval(t, i, j);
|
||||||
if (j > 0) {
|
if (j > 0) {
|
||||||
printf(",");
|
printf(",");
|
||||||
}
|
}
|
||||||
printf("%5d", (*ts)->num);
|
printf("%5d", (*ts)->num);
|
||||||
}
|
}
|
||||||
printf("}");
|
printf("}");
|
||||||
}
|
}
|
||||||
printf("\n}\n");
|
printf("\n}\n");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
assert(0);
|
assert(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,397 +16,397 @@ static Relation *newAllPairs ARGS((void));
|
|||||||
static void
|
static void
|
||||||
siblings(i, j) int i; int j;
|
siblings(i, j) int i; int j;
|
||||||
{
|
{
|
||||||
int k;
|
int k;
|
||||||
List pl;
|
List pl;
|
||||||
DeltaCost Max;
|
DeltaCost Max;
|
||||||
int foundmax;
|
int foundmax;
|
||||||
|
|
||||||
allpairs[i][j].sibComputed = 1;
|
allpairs[i][j].sibComputed = 1;
|
||||||
|
|
||||||
if (i == 1) {
|
if (i == 1) {
|
||||||
return; /* never trim start symbol */
|
return; /* never trim start symbol */
|
||||||
}
|
}
|
||||||
if (i==j) {
|
if (i==j) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ZEROCOST(Max);
|
ZEROCOST(Max);
|
||||||
foundmax = 0;
|
foundmax = 0;
|
||||||
|
|
||||||
for (k = 1; k < max_nonterminal; k++) {
|
for (k = 1; k < max_nonterminal; k++) {
|
||||||
DeltaCost tmp;
|
DeltaCost tmp;
|
||||||
|
|
||||||
if (k==i || k==j) {
|
if (k==i || k==j) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!allpairs[k][i].rule) {
|
if (!allpairs[k][i].rule) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!allpairs[k][j].rule) {
|
if (!allpairs[k][j].rule) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ASSIGNCOST(tmp, allpairs[k][j].chain);
|
ASSIGNCOST(tmp, allpairs[k][j].chain);
|
||||||
MINUSCOST(tmp, allpairs[k][i].chain);
|
MINUSCOST(tmp, allpairs[k][i].chain);
|
||||||
if (foundmax) {
|
if (foundmax) {
|
||||||
if (LESSCOST(Max, tmp)) {
|
if (LESSCOST(Max, tmp)) {
|
||||||
ASSIGNCOST(Max, tmp);
|
ASSIGNCOST(Max, tmp);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
foundmax = 1;
|
foundmax = 1;
|
||||||
ASSIGNCOST(Max, tmp);
|
ASSIGNCOST(Max, tmp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (pl = rules; pl; pl = pl->next) {
|
for (pl = rules; pl; pl = pl->next) {
|
||||||
Rule p = (Rule) pl->x;
|
Rule p = (Rule) pl->x;
|
||||||
Operator op = p->pat->op;
|
Operator op = p->pat->op;
|
||||||
List oprule;
|
List oprule;
|
||||||
DeltaCost Min;
|
DeltaCost Min;
|
||||||
int foundmin;
|
int foundmin;
|
||||||
|
|
||||||
if (!op) {
|
if (!op) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
switch (op->arity) {
|
switch (op->arity) {
|
||||||
case 0:
|
case 0:
|
||||||
continue;
|
continue;
|
||||||
case 1:
|
case 1:
|
||||||
if (!allpairs[p->pat->children[0]->num ][ i].rule) {
|
if (!allpairs[p->pat->children[0]->num ][ i].rule) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
foundmin = 0;
|
foundmin = 0;
|
||||||
for (oprule = op->table->rules; oprule; oprule = oprule->next) {
|
for (oprule = op->table->rules; oprule; oprule = oprule->next) {
|
||||||
Rule s = (Rule) oprule->x;
|
Rule s = (Rule) oprule->x;
|
||||||
DeltaPtr Cx;
|
DeltaPtr Cx;
|
||||||
DeltaPtr Csj;
|
DeltaPtr Csj;
|
||||||
DeltaPtr Cpi;
|
DeltaPtr Cpi;
|
||||||
DeltaCost tmp;
|
DeltaCost tmp;
|
||||||
|
|
||||||
if (!allpairs[p->lhs->num ][ s->lhs->num].rule
|
if (!allpairs[p->lhs->num ][ s->lhs->num].rule
|
||||||
|| !allpairs[s->pat->children[0]->num ][ j].rule) {
|
|| !allpairs[s->pat->children[0]->num ][ j].rule) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Cx = allpairs[p->lhs->num ][ s->lhs->num].chain;
|
Cx = allpairs[p->lhs->num ][ s->lhs->num].chain;
|
||||||
Csj= allpairs[s->pat->children[0]->num ][ j].chain;
|
Csj= allpairs[s->pat->children[0]->num ][ j].chain;
|
||||||
Cpi= allpairs[p->pat->children[0]->num ][ i].chain;
|
Cpi= allpairs[p->pat->children[0]->num ][ i].chain;
|
||||||
ASSIGNCOST(tmp, Cx);
|
ASSIGNCOST(tmp, Cx);
|
||||||
ADDCOST(tmp, s->delta);
|
ADDCOST(tmp, s->delta);
|
||||||
ADDCOST(tmp, Csj);
|
ADDCOST(tmp, Csj);
|
||||||
MINUSCOST(tmp, Cpi);
|
MINUSCOST(tmp, Cpi);
|
||||||
MINUSCOST(tmp, p->delta);
|
MINUSCOST(tmp, p->delta);
|
||||||
if (foundmin) {
|
if (foundmin) {
|
||||||
if (LESSCOST(tmp, Min)) {
|
if (LESSCOST(tmp, Min)) {
|
||||||
ASSIGNCOST(Min, tmp);
|
ASSIGNCOST(Min, tmp);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
foundmin = 1;
|
foundmin = 1;
|
||||||
ASSIGNCOST(Min, tmp);
|
ASSIGNCOST(Min, tmp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!foundmin) {
|
if (!foundmin) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (foundmax) {
|
if (foundmax) {
|
||||||
if (LESSCOST(Max, Min)) {
|
if (LESSCOST(Max, Min)) {
|
||||||
ASSIGNCOST(Max, Min);
|
ASSIGNCOST(Max, Min);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
foundmax = 1;
|
foundmax = 1;
|
||||||
ASSIGNCOST(Max, Min);
|
ASSIGNCOST(Max, Min);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
/* do first dimension */
|
/* do first dimension */
|
||||||
if (allpairs[p->pat->children[0]->num ][ i].rule) {
|
if (allpairs[p->pat->children[0]->num ][ i].rule) {
|
||||||
foundmin = 0;
|
foundmin = 0;
|
||||||
for (oprule = op->table->rules; oprule; oprule = oprule->next) {
|
for (oprule = op->table->rules; oprule; oprule = oprule->next) {
|
||||||
Rule s = (Rule) oprule->x;
|
Rule s = (Rule) oprule->x;
|
||||||
DeltaPtr Cx;
|
DeltaPtr Cx;
|
||||||
DeltaPtr Cb;
|
DeltaPtr Cb;
|
||||||
DeltaPtr Csj;
|
DeltaPtr Csj;
|
||||||
DeltaPtr Cpi;
|
DeltaPtr Cpi;
|
||||||
DeltaCost tmp;
|
DeltaCost tmp;
|
||||||
|
|
||||||
if (allpairs[p->lhs->num ][ s->lhs->num].rule
|
if (allpairs[p->lhs->num ][ s->lhs->num].rule
|
||||||
&& allpairs[s->pat->children[0]->num ][ j].rule
|
&& allpairs[s->pat->children[0]->num ][ j].rule
|
||||||
&& allpairs[s->pat->children[1]->num ][ p->pat->children[1]->num].rule) {
|
&& allpairs[s->pat->children[1]->num ][ p->pat->children[1]->num].rule) {
|
||||||
Cx = allpairs[p->lhs->num ][ s->lhs->num].chain;
|
Cx = allpairs[p->lhs->num ][ s->lhs->num].chain;
|
||||||
Csj= allpairs[s->pat->children[0]->num ][ j].chain;
|
Csj= allpairs[s->pat->children[0]->num ][ j].chain;
|
||||||
Cpi= allpairs[p->pat->children[0]->num ][ i].chain;
|
Cpi= allpairs[p->pat->children[0]->num ][ i].chain;
|
||||||
Cb = allpairs[s->pat->children[1]->num ][ p->pat->children[1]->num].chain;
|
Cb = allpairs[s->pat->children[1]->num ][ p->pat->children[1]->num].chain;
|
||||||
ASSIGNCOST(tmp, Cx);
|
ASSIGNCOST(tmp, Cx);
|
||||||
ADDCOST(tmp, s->delta);
|
ADDCOST(tmp, s->delta);
|
||||||
ADDCOST(tmp, Csj);
|
ADDCOST(tmp, Csj);
|
||||||
ADDCOST(tmp, Cb);
|
ADDCOST(tmp, Cb);
|
||||||
MINUSCOST(tmp, Cpi);
|
MINUSCOST(tmp, Cpi);
|
||||||
MINUSCOST(tmp, p->delta);
|
MINUSCOST(tmp, p->delta);
|
||||||
if (foundmin) {
|
if (foundmin) {
|
||||||
if (LESSCOST(tmp, Min)) {
|
if (LESSCOST(tmp, Min)) {
|
||||||
ASSIGNCOST(Min, tmp);
|
ASSIGNCOST(Min, tmp);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
foundmin = 1;
|
foundmin = 1;
|
||||||
ASSIGNCOST(Min, tmp);
|
ASSIGNCOST(Min, tmp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!foundmin) {
|
if (!foundmin) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (foundmax) {
|
if (foundmax) {
|
||||||
if (LESSCOST(Max, Min)) {
|
if (LESSCOST(Max, Min)) {
|
||||||
ASSIGNCOST(Max, Min);
|
ASSIGNCOST(Max, Min);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
foundmax = 1;
|
foundmax = 1;
|
||||||
ASSIGNCOST(Max, Min);
|
ASSIGNCOST(Max, Min);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* do second dimension */
|
/* do second dimension */
|
||||||
if (allpairs[p->pat->children[1]->num ][ i].rule) {
|
if (allpairs[p->pat->children[1]->num ][ i].rule) {
|
||||||
foundmin = 0;
|
foundmin = 0;
|
||||||
for (oprule = op->table->rules; oprule; oprule = oprule->next) {
|
for (oprule = op->table->rules; oprule; oprule = oprule->next) {
|
||||||
Rule s = (Rule) oprule->x;
|
Rule s = (Rule) oprule->x;
|
||||||
DeltaPtr Cx;
|
DeltaPtr Cx;
|
||||||
DeltaPtr Cb;
|
DeltaPtr Cb;
|
||||||
DeltaPtr Csj;
|
DeltaPtr Csj;
|
||||||
DeltaPtr Cpi;
|
DeltaPtr Cpi;
|
||||||
DeltaCost tmp;
|
DeltaCost tmp;
|
||||||
|
|
||||||
if (allpairs[p->lhs->num ][ s->lhs->num].rule
|
if (allpairs[p->lhs->num ][ s->lhs->num].rule
|
||||||
&& allpairs[s->pat->children[1]->num ][ j].rule
|
&& allpairs[s->pat->children[1]->num ][ j].rule
|
||||||
&& allpairs[s->pat->children[0]->num ][ p->pat->children[0]->num].rule) {
|
&& allpairs[s->pat->children[0]->num ][ p->pat->children[0]->num].rule) {
|
||||||
Cx = allpairs[p->lhs->num ][ s->lhs->num].chain;
|
Cx = allpairs[p->lhs->num ][ s->lhs->num].chain;
|
||||||
Csj= allpairs[s->pat->children[1]->num ][ j].chain;
|
Csj= allpairs[s->pat->children[1]->num ][ j].chain;
|
||||||
Cpi= allpairs[p->pat->children[1]->num ][ i].chain;
|
Cpi= allpairs[p->pat->children[1]->num ][ i].chain;
|
||||||
Cb = allpairs[s->pat->children[0]->num ][ p->pat->children[0]->num].chain;
|
Cb = allpairs[s->pat->children[0]->num ][ p->pat->children[0]->num].chain;
|
||||||
ASSIGNCOST(tmp, Cx);
|
ASSIGNCOST(tmp, Cx);
|
||||||
ADDCOST(tmp, s->delta);
|
ADDCOST(tmp, s->delta);
|
||||||
ADDCOST(tmp, Csj);
|
ADDCOST(tmp, Csj);
|
||||||
ADDCOST(tmp, Cb);
|
ADDCOST(tmp, Cb);
|
||||||
MINUSCOST(tmp, Cpi);
|
MINUSCOST(tmp, Cpi);
|
||||||
MINUSCOST(tmp, p->delta);
|
MINUSCOST(tmp, p->delta);
|
||||||
if (foundmin) {
|
if (foundmin) {
|
||||||
if (LESSCOST(tmp, Min)) {
|
if (LESSCOST(tmp, Min)) {
|
||||||
ASSIGNCOST(Min, tmp);
|
ASSIGNCOST(Min, tmp);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
foundmin = 1;
|
foundmin = 1;
|
||||||
ASSIGNCOST(Min, tmp);
|
ASSIGNCOST(Min, tmp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!foundmin) {
|
if (!foundmin) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (foundmax) {
|
if (foundmax) {
|
||||||
if (LESSCOST(Max, Min)) {
|
if (LESSCOST(Max, Min)) {
|
||||||
ASSIGNCOST(Max, Min);
|
ASSIGNCOST(Max, Min);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
foundmax = 1;
|
foundmax = 1;
|
||||||
ASSIGNCOST(Max, Min);
|
ASSIGNCOST(Max, Min);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
assert(0);
|
assert(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
allpairs[i ][ j].sibFlag = foundmax;
|
allpairs[i ][ j].sibFlag = foundmax;
|
||||||
ASSIGNCOST(allpairs[i ][ j].sibling, Max);
|
ASSIGNCOST(allpairs[i ][ j].sibling, Max);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
findAllNexts()
|
findAllNexts()
|
||||||
{
|
{
|
||||||
int i,j;
|
int i,j;
|
||||||
int last;
|
int last;
|
||||||
|
|
||||||
for (i = 1; i < max_nonterminal; i++) {
|
for (i = 1; i < max_nonterminal; i++) {
|
||||||
last = 0;
|
last = 0;
|
||||||
for (j = 1; j < max_nonterminal; j++) {
|
for (j = 1; j < max_nonterminal; j++) {
|
||||||
if (allpairs[i ][j].rule) {
|
if (allpairs[i ][j].rule) {
|
||||||
allpairs[i ][ last].nextchain = j;
|
allpairs[i ][ last].nextchain = j;
|
||||||
last = j;
|
last = j;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
for (i = 1; i < max_nonterminal; i++) {
|
for (i = 1; i < max_nonterminal; i++) {
|
||||||
last = 0;
|
last = 0;
|
||||||
for (j = 1; j < max_nonterminal; j++) {
|
for (j = 1; j < max_nonterminal; j++) {
|
||||||
if (allpairs[i ][j].sibFlag) {
|
if (allpairs[i ][j].sibFlag) {
|
||||||
allpairs[i ][ last].nextsibling = j;
|
allpairs[i ][ last].nextsibling = j;
|
||||||
last = j;
|
last = j;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
static Relation *
|
static Relation *
|
||||||
newAllPairs()
|
newAllPairs()
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
Relation *rv;
|
Relation *rv;
|
||||||
|
|
||||||
rv = (Relation*) zalloc(max_nonterminal * sizeof(Relation));
|
rv = (Relation*) zalloc(max_nonterminal * sizeof(Relation));
|
||||||
for (i = 0; i < max_nonterminal; i++) {
|
for (i = 0; i < max_nonterminal; i++) {
|
||||||
rv[i] = (Relation) zalloc(max_nonterminal * sizeof(struct relation));
|
rv[i] = (Relation) zalloc(max_nonterminal * sizeof(struct relation));
|
||||||
}
|
}
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
findAllPairs()
|
findAllPairs()
|
||||||
{
|
{
|
||||||
List pl;
|
List pl;
|
||||||
int changes;
|
int changes;
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
allpairs = newAllPairs();
|
allpairs = newAllPairs();
|
||||||
for (pl = chainrules; pl; pl = pl->next) {
|
for (pl = chainrules; pl; pl = pl->next) {
|
||||||
Rule p = (Rule) pl->x;
|
Rule p = (Rule) pl->x;
|
||||||
NonTerminalNum rhs = p->pat->children[0]->num;
|
NonTerminalNum rhs = p->pat->children[0]->num;
|
||||||
NonTerminalNum lhs = p->lhs->num;
|
NonTerminalNum lhs = p->lhs->num;
|
||||||
Relation r = &allpairs[lhs ][ rhs];
|
Relation r = &allpairs[lhs ][ rhs];
|
||||||
|
|
||||||
if (LESSCOST(p->delta, r->chain)) {
|
if (LESSCOST(p->delta, r->chain)) {
|
||||||
ASSIGNCOST(r->chain, p->delta);
|
ASSIGNCOST(r->chain, p->delta);
|
||||||
r->rule = p;
|
r->rule = p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (j = 1; j < max_nonterminal; j++) {
|
for (j = 1; j < max_nonterminal; j++) {
|
||||||
Relation r = &allpairs[j ][ j];
|
Relation r = &allpairs[j ][ j];
|
||||||
ZEROCOST(r->chain);
|
ZEROCOST(r->chain);
|
||||||
r->rule = &stub_rule;
|
r->rule = &stub_rule;
|
||||||
}
|
}
|
||||||
changes = 1;
|
changes = 1;
|
||||||
while (changes) {
|
while (changes) {
|
||||||
changes = 0;
|
changes = 0;
|
||||||
for (pl = chainrules; pl; pl = pl->next) {
|
for (pl = chainrules; pl; pl = pl->next) {
|
||||||
Rule p = (Rule) pl->x;
|
Rule p = (Rule) pl->x;
|
||||||
NonTerminalNum rhs = p->pat->children[0]->num;
|
NonTerminalNum rhs = p->pat->children[0]->num;
|
||||||
NonTerminalNum lhs = p->lhs->num;
|
NonTerminalNum lhs = p->lhs->num;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 1; i < max_nonterminal; i++) {
|
for (i = 1; i < max_nonterminal; i++) {
|
||||||
Relation r = &allpairs[rhs ][ i];
|
Relation r = &allpairs[rhs ][ i];
|
||||||
Relation s = &allpairs[lhs ][ i];
|
Relation s = &allpairs[lhs ][ i];
|
||||||
DeltaCost dc;
|
DeltaCost dc;
|
||||||
if (!r->rule) {
|
if (!r->rule) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ASSIGNCOST(dc, p->delta);
|
ASSIGNCOST(dc, p->delta);
|
||||||
ADDCOST(dc, r->chain);
|
ADDCOST(dc, r->chain);
|
||||||
if (!s->rule || LESSCOST(dc, s->chain)) {
|
if (!s->rule || LESSCOST(dc, s->chain)) {
|
||||||
s->rule = p;
|
s->rule = p;
|
||||||
ASSIGNCOST(s->chain, dc);
|
ASSIGNCOST(s->chain, dc);
|
||||||
changes = 1;
|
changes = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
findAllNexts();
|
findAllNexts();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
trim(t) Item_Set t;
|
trim(t) Item_Set t;
|
||||||
{
|
{
|
||||||
int m,n;
|
int m,n;
|
||||||
static short *vec = 0;
|
static short *vec = 0;
|
||||||
int last;
|
int last;
|
||||||
|
|
||||||
assert(!t->closed);
|
assert(!t->closed);
|
||||||
debug(debugTrim, printf("Begin Trim\n"));
|
debug(debugTrim, printf("Begin Trim\n"));
|
||||||
debug(debugTrim, dumpItem_Set(t));
|
debug(debugTrim, dumpItem_Set(t));
|
||||||
|
|
||||||
last = 0;
|
last = 0;
|
||||||
if (!vec) {
|
if (!vec) {
|
||||||
vec = (short*) zalloc(max_nonterminal * sizeof(*vec));
|
vec = (short*) zalloc(max_nonterminal * sizeof(*vec));
|
||||||
}
|
}
|
||||||
for (m = 1; m < max_nonterminal; m++) {
|
for (m = 1; m < max_nonterminal; m++) {
|
||||||
if (t->virgin[m].rule) {
|
if (t->virgin[m].rule) {
|
||||||
vec[last++] = m;
|
vec[last++] = m;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (m = 0; m < last; m++) {
|
for (m = 0; m < last; m++) {
|
||||||
DeltaCost tmp;
|
DeltaCost tmp;
|
||||||
int j;
|
int j;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
i = vec[m];
|
i = vec[m];
|
||||||
|
|
||||||
for (j = allpairs[i ][ 0].nextchain; j; j = allpairs[i ][ j].nextchain) {
|
for (j = allpairs[i ][ 0].nextchain; j; j = allpairs[i ][ j].nextchain) {
|
||||||
|
|
||||||
if (i == j) {
|
if (i == j) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!t->virgin[j].rule) {
|
if (!t->virgin[j].rule) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ASSIGNCOST(tmp, t->virgin[j].delta);
|
ASSIGNCOST(tmp, t->virgin[j].delta);
|
||||||
ADDCOST(tmp, allpairs[i ][ j].chain);
|
ADDCOST(tmp, allpairs[i ][ j].chain);
|
||||||
if (!LESSCOST(t->virgin[i].delta, tmp)) {
|
if (!LESSCOST(t->virgin[i].delta, tmp)) {
|
||||||
t->virgin[i].rule = 0;
|
t->virgin[i].rule = 0;
|
||||||
ZEROCOST(t->virgin[i].delta);
|
ZEROCOST(t->virgin[i].delta);
|
||||||
debug(debugTrim, printf("Trimmed Chain (%d,%d)\n", i,j));
|
debug(debugTrim, printf("Trimmed Chain (%d,%d)\n", i,j));
|
||||||
goto outer;
|
goto outer;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if (!trimflag) {
|
if (!trimflag) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (n = 0; n < last; n++) {
|
for (n = 0; n < last; n++) {
|
||||||
j = vec[n];
|
j = vec[n];
|
||||||
if (i == j) {
|
if (i == j) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!t->virgin[j].rule) {
|
if (!t->virgin[j].rule) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!allpairs[i][j].sibComputed) {
|
if (!allpairs[i][j].sibComputed) {
|
||||||
siblings(i,j);
|
siblings(i,j);
|
||||||
}
|
}
|
||||||
if (!allpairs[i][j].sibFlag) {
|
if (!allpairs[i][j].sibFlag) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ASSIGNCOST(tmp, t->virgin[j].delta);
|
ASSIGNCOST(tmp, t->virgin[j].delta);
|
||||||
ADDCOST(tmp, allpairs[i ][ j].sibling);
|
ADDCOST(tmp, allpairs[i ][ j].sibling);
|
||||||
if (!LESSCOST(t->virgin[i].delta, tmp)) {
|
if (!LESSCOST(t->virgin[i].delta, tmp)) {
|
||||||
t->virgin[i].rule = 0;
|
t->virgin[i].rule = 0;
|
||||||
ZEROCOST(t->virgin[i].delta);
|
ZEROCOST(t->virgin[i].delta);
|
||||||
goto outer;
|
goto outer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
outer: ;
|
outer: ;
|
||||||
}
|
}
|
||||||
|
|
||||||
debug(debugTrim, dumpItem_Set(t));
|
debug(debugTrim, dumpItem_Set(t));
|
||||||
debug(debugTrim, printf("End Trim\n"));
|
debug(debugTrim, printf("End Trim\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dumpRelation(r) Relation r;
|
dumpRelation(r) Relation r;
|
||||||
{
|
{
|
||||||
printf("{ %d %ld %d %ld }", r->rule->erulenum, (long) r->chain, r->sibFlag, (long) r->sibling);
|
printf("{ %d %ld %d %ld }", r->rule->erulenum, (long) r->chain, r->sibFlag, (long) r->sibling);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dumpAllPairs()
|
dumpAllPairs()
|
||||||
{
|
{
|
||||||
int i,j;
|
int i,j;
|
||||||
|
|
||||||
printf("Dumping AllPairs\n");
|
printf("Dumping AllPairs\n");
|
||||||
for (i = 1; i < max_nonterminal; i++) {
|
for (i = 1; i < max_nonterminal; i++) {
|
||||||
for (j = 1; j < max_nonterminal; j++) {
|
for (j = 1; j < max_nonterminal; j++) {
|
||||||
dumpRelation(&allpairs[i ][j]);
|
dumpRelation(&allpairs[i ][j]);
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,25 +8,25 @@ char rcsid_zalloc[] = "$Id$";
|
|||||||
int
|
int
|
||||||
fatal(const char *name, int line)
|
fatal(const char *name, int line)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "assertion failed: file %s, line %d\n", name, line);
|
fprintf(stderr, "assertion failed: file %s, line %d\n", name, line);
|
||||||
exit(1);
|
exit(1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *
|
void *
|
||||||
zalloc(size) unsigned int size;
|
zalloc(size) unsigned int size;
|
||||||
{
|
{
|
||||||
void *t = (void *) malloc(size);
|
void *t = (void *) malloc(size);
|
||||||
if (!t) {
|
if (!t) {
|
||||||
fprintf(stderr, "Malloc failed---PROGRAM ABORTED\n");
|
fprintf(stderr, "Malloc failed---PROGRAM ABORTED\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
memset(t, 0, size);
|
memset(t, 0, size);
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
zfree(p) void *p;
|
zfree(p) void *p;
|
||||||
{
|
{
|
||||||
free(p);
|
free(p);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ Init *BitsRecTy::convertValue(TypedInit *VI) {
|
|||||||
if (BRT->Size == Size) {
|
if (BRT->Size == Size) {
|
||||||
BitsInit *Ret = new BitsInit(Size);
|
BitsInit *Ret = new BitsInit(Size);
|
||||||
for (unsigned i = 0; i != Size; ++i)
|
for (unsigned i = 0; i != Size; ++i)
|
||||||
Ret->setBit(i, new VarBitInit(VI, i));
|
Ret->setBit(i, new VarBitInit(VI, i));
|
||||||
return Ret;
|
return Ret;
|
||||||
}
|
}
|
||||||
if (Size == 1 && dynamic_cast<BitRecTy*>(VI->getType())) {
|
if (Size == 1 && dynamic_cast<BitRecTy*>(VI->getType())) {
|
||||||
@@ -768,13 +768,13 @@ std::ostream &llvm::operator<<(std::ostream &OS, const RecordKeeper &RK) {
|
|||||||
OS << "------------- Classes -----------------\n";
|
OS << "------------- Classes -----------------\n";
|
||||||
const std::map<std::string, Record*> &Classes = RK.getClasses();
|
const std::map<std::string, Record*> &Classes = RK.getClasses();
|
||||||
for (std::map<std::string, Record*>::const_iterator I = Classes.begin(),
|
for (std::map<std::string, Record*>::const_iterator I = Classes.begin(),
|
||||||
E = Classes.end(); I != E; ++I)
|
E = Classes.end(); I != E; ++I)
|
||||||
OS << "class " << *I->second;
|
OS << "class " << *I->second;
|
||||||
|
|
||||||
OS << "------------- Defs -----------------\n";
|
OS << "------------- Defs -----------------\n";
|
||||||
const std::map<std::string, Record*> &Defs = RK.getDefs();
|
const std::map<std::string, Record*> &Defs = RK.getDefs();
|
||||||
for (std::map<std::string, Record*>::const_iterator I = Defs.begin(),
|
for (std::map<std::string, Record*>::const_iterator I = Defs.begin(),
|
||||||
E = Defs.end(); I != E; ++I)
|
E = Defs.end(); I != E; ++I)
|
||||||
OS << "def " << *I->second;
|
OS << "def " << *I->second;
|
||||||
return OS;
|
return OS;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -944,7 +944,7 @@ public:
|
|||||||
bool isSubClassOf(Record *R) const {
|
bool isSubClassOf(Record *R) const {
|
||||||
for (unsigned i = 0, e = SuperClasses.size(); i != e; ++i)
|
for (unsigned i = 0, e = SuperClasses.size(); i != e; ++i)
|
||||||
if (SuperClasses[i] == R)
|
if (SuperClasses[i] == R)
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1031,10 +1031,10 @@ class RecordKeeper {
|
|||||||
public:
|
public:
|
||||||
~RecordKeeper() {
|
~RecordKeeper() {
|
||||||
for (std::map<std::string, Record*>::iterator I = Classes.begin(),
|
for (std::map<std::string, Record*>::iterator I = Classes.begin(),
|
||||||
E = Classes.end(); I != E; ++I)
|
E = Classes.end(); I != E; ++I)
|
||||||
delete I->second;
|
delete I->second;
|
||||||
for (std::map<std::string, Record*>::iterator I = Defs.begin(),
|
for (std::map<std::string, Record*>::iterator I = Defs.begin(),
|
||||||
E = Defs.end(); I != E; ++I)
|
E = Defs.end(); I != E; ++I)
|
||||||
delete I->second;
|
delete I->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -93,10 +93,10 @@ static Init *getBit(Record *R, unsigned BitNo) {
|
|||||||
for (unsigned i = 0, e = V.size(); i != e; ++i)
|
for (unsigned i = 0, e = V.size(); i != e; ++i)
|
||||||
if (V[i].getPrefix()) {
|
if (V[i].getPrefix()) {
|
||||||
assert(dynamic_cast<BitsInit*>(V[i].getValue()) &&
|
assert(dynamic_cast<BitsInit*>(V[i].getValue()) &&
|
||||||
"Can only handle fields of bits<> type!");
|
"Can only handle fields of bits<> type!");
|
||||||
BitsInit *I = (BitsInit*)V[i].getValue();
|
BitsInit *I = (BitsInit*)V[i].getValue();
|
||||||
if (BitNo < I->getNumBits())
|
if (BitNo < I->getNumBits())
|
||||||
return I->getBit(BitNo);
|
return I->getBit(BitNo);
|
||||||
BitNo -= I->getNumBits();
|
BitNo -= I->getNumBits();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,7 +111,7 @@ static unsigned getNumBits(Record *R) {
|
|||||||
for (unsigned i = 0, e = V.size(); i != e; ++i)
|
for (unsigned i = 0, e = V.size(); i != e; ++i)
|
||||||
if (V[i].getPrefix()) {
|
if (V[i].getPrefix()) {
|
||||||
assert(dynamic_cast<BitsInit*>(V[i].getValue()) &&
|
assert(dynamic_cast<BitsInit*>(V[i].getValue()) &&
|
||||||
"Can only handle fields of bits<> type!");
|
"Can only handle fields of bits<> type!");
|
||||||
Num += ((BitsInit*)V[i].getValue())->getNumBits();
|
Num += ((BitsInit*)V[i].getValue())->getNumBits();
|
||||||
}
|
}
|
||||||
return Num;
|
return Num;
|
||||||
@@ -130,7 +130,7 @@ static bool BitsAreEqual(Record *I1, Record *I2, unsigned BitNo) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool BitRangesEqual(Record *I1, Record *I2,
|
static bool BitRangesEqual(Record *I1, Record *I2,
|
||||||
unsigned Start, unsigned End) {
|
unsigned Start, unsigned End) {
|
||||||
for (unsigned i = Start; i != End; ++i)
|
for (unsigned i = Start; i != End; ++i)
|
||||||
if (!BitsAreEqual(I1, I2, i))
|
if (!BitsAreEqual(I1, I2, i))
|
||||||
return false;
|
return false;
|
||||||
@@ -145,9 +145,9 @@ static unsigned getFirstFixedBit(Record *R, unsigned FirstFixedBit) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void FindInstDifferences(Record *I1, Record *I2,
|
static void FindInstDifferences(Record *I1, Record *I2,
|
||||||
unsigned FirstFixedBit, unsigned MaxBits,
|
unsigned FirstFixedBit, unsigned MaxBits,
|
||||||
unsigned &FirstVaryingBitOverall,
|
unsigned &FirstVaryingBitOverall,
|
||||||
unsigned &LastFixedBitOverall) {
|
unsigned &LastFixedBitOverall) {
|
||||||
// Compare the first instruction to the rest of the instructions, looking for
|
// Compare the first instruction to the rest of the instructions, looking for
|
||||||
// fields that differ.
|
// fields that differ.
|
||||||
//
|
//
|
||||||
@@ -179,16 +179,16 @@ struct BitComparator {
|
|||||||
for (unsigned i = BitBegin; i != BitEnd; ++i) {
|
for (unsigned i = BitBegin; i != BitEnd; ++i) {
|
||||||
bool V1 = getBitValue(R1, i), V2 = getBitValue(R2, i);
|
bool V1 = getBitValue(R1, i), V2 = getBitValue(R2, i);
|
||||||
if (V1 < V2)
|
if (V1 < V2)
|
||||||
return true;
|
return true;
|
||||||
else if (V2 < V1)
|
else if (V2 < V1)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static void PrintRange(std::vector<Record*>::iterator I,
|
static void PrintRange(std::vector<Record*>::iterator I,
|
||||||
std::vector<Record*>::iterator E) {
|
std::vector<Record*>::iterator E) {
|
||||||
while (I != E) std::cerr << **I++;
|
while (I != E) std::cerr << **I++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,8 +197,8 @@ static bool getMemoryBit(unsigned char *M, unsigned i) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static unsigned getFirstFixedBitInSequence(std::vector<Record*>::iterator IB,
|
static unsigned getFirstFixedBitInSequence(std::vector<Record*>::iterator IB,
|
||||||
std::vector<Record*>::iterator IE,
|
std::vector<Record*>::iterator IE,
|
||||||
unsigned StartBit) {
|
unsigned StartBit) {
|
||||||
unsigned FirstFixedBit = 0;
|
unsigned FirstFixedBit = 0;
|
||||||
for (std::vector<Record*>::iterator I = IB; I != IE; ++I)
|
for (std::vector<Record*>::iterator I = IB; I != IE; ++I)
|
||||||
FirstFixedBit = std::max(FirstFixedBit, getFirstFixedBit(*I, StartBit));
|
FirstFixedBit = std::max(FirstFixedBit, getFirstFixedBit(*I, StartBit));
|
||||||
@@ -211,16 +211,16 @@ static unsigned getFirstFixedBitInSequence(std::vector<Record*>::iterator IB,
|
|||||||
// down to zero or one instruction, in which case we have a match or failure.
|
// down to zero or one instruction, in which case we have a match or failure.
|
||||||
//
|
//
|
||||||
static Record *ParseMachineCode(std::vector<Record*>::iterator InstsB,
|
static Record *ParseMachineCode(std::vector<Record*>::iterator InstsB,
|
||||||
std::vector<Record*>::iterator InstsE,
|
std::vector<Record*>::iterator InstsE,
|
||||||
unsigned char *M) {
|
unsigned char *M) {
|
||||||
assert(InstsB != InstsE && "Empty range?");
|
assert(InstsB != InstsE && "Empty range?");
|
||||||
if (InstsB+1 == InstsE) {
|
if (InstsB+1 == InstsE) {
|
||||||
// Only a single instruction, see if we match it...
|
// Only a single instruction, see if we match it...
|
||||||
Record *Inst = *InstsB;
|
Record *Inst = *InstsB;
|
||||||
for (unsigned i = 0, e = getNumBits(Inst); i != e; ++i)
|
for (unsigned i = 0, e = getNumBits(Inst); i != e; ++i)
|
||||||
if (BitInit *BI = dynamic_cast<BitInit*>(getBit(Inst, i)))
|
if (BitInit *BI = dynamic_cast<BitInit*>(getBit(Inst, i)))
|
||||||
if (getMemoryBit(M, i) != BI->getValue())
|
if (getMemoryBit(M, i) != BI->getValue())
|
||||||
throw std::string("Parse failed!\n");
|
throw std::string("Parse failed!\n");
|
||||||
return Inst;
|
return Inst;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,16 +235,16 @@ static Record *ParseMachineCode(std::vector<Record*>::iterator InstsB,
|
|||||||
LastFixedBit = ~0;
|
LastFixedBit = ~0;
|
||||||
for (std::vector<Record*>::iterator I = InstsB+1; I != InstsE; ++I)
|
for (std::vector<Record*>::iterator I = InstsB+1; I != InstsE; ++I)
|
||||||
FindInstDifferences(*InstsB, *I, FirstFixedBit, MaxBits,
|
FindInstDifferences(*InstsB, *I, FirstFixedBit, MaxBits,
|
||||||
FirstVaryingBit, LastFixedBit);
|
FirstVaryingBit, LastFixedBit);
|
||||||
if (FirstVaryingBit == MaxBits) {
|
if (FirstVaryingBit == MaxBits) {
|
||||||
std::cerr << "ERROR: Could not find bit to distinguish between "
|
std::cerr << "ERROR: Could not find bit to distinguish between "
|
||||||
<< "the following entries!\n";
|
<< "the following entries!\n";
|
||||||
PrintRange(InstsB, InstsE);
|
PrintRange(InstsB, InstsE);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
std::cerr << "FVB: " << FirstVaryingBit << " - " << LastFixedBit
|
std::cerr << "FVB: " << FirstVaryingBit << " - " << LastFixedBit
|
||||||
<< ": " << InstsE-InstsB << "\n";
|
<< ": " << InstsE-InstsB << "\n";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
FirstFixedBit = getFirstFixedBitInSequence(InstsB, InstsE, FirstVaryingBit);
|
FirstFixedBit = getFirstFixedBitInSequence(InstsB, InstsE, FirstVaryingBit);
|
||||||
@@ -282,7 +282,7 @@ static Record *ParseMachineCode(std::vector<Record*>::iterator InstsB,
|
|||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
std::cerr << "FVB: " << FirstVaryingBit << " - " << LastFixedBit
|
std::cerr << "FVB: " << FirstVaryingBit << " - " << LastFixedBit
|
||||||
<< ": [" << RangeEnd-RangeBegin << "] - ";
|
<< ": [" << RangeEnd-RangeBegin << "] - ";
|
||||||
for (int i = LastFixedBit-1; i >= (int)FirstVaryingBit; --i)
|
for (int i = LastFixedBit-1; i >= (int)FirstVaryingBit; --i)
|
||||||
std::cerr << (int)((BitInit*)getBit(*RangeBegin, i))->getValue() << " ";
|
std::cerr << (int)((BitInit*)getBit(*RangeBegin, i))->getValue() << " ";
|
||||||
std::cerr << "\n";
|
std::cerr << "\n";
|
||||||
@@ -290,8 +290,8 @@ static Record *ParseMachineCode(std::vector<Record*>::iterator InstsB,
|
|||||||
|
|
||||||
if (Record *R = ParseMachineCode(RangeBegin, RangeEnd, M)) {
|
if (Record *R = ParseMachineCode(RangeBegin, RangeEnd, M)) {
|
||||||
if (Match) {
|
if (Match) {
|
||||||
std::cerr << "Error: Multiple matches found:\n";
|
std::cerr << "Error: Multiple matches found:\n";
|
||||||
PrintRange(InstsB, InstsE);
|
PrintRange(InstsB, InstsE);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(Match == 0 && "Multiple matches??");
|
assert(Match == 0 && "Multiple matches??");
|
||||||
@@ -305,7 +305,7 @@ static Record *ParseMachineCode(std::vector<Record*>::iterator InstsB,
|
|||||||
|
|
||||||
static void PrintValue(Record *I, unsigned char *Ptr, const RecordVal &Val) {
|
static void PrintValue(Record *I, unsigned char *Ptr, const RecordVal &Val) {
|
||||||
assert(dynamic_cast<BitsInit*>(Val.getValue()) &&
|
assert(dynamic_cast<BitsInit*>(Val.getValue()) &&
|
||||||
"Can only handle undefined bits<> types!");
|
"Can only handle undefined bits<> types!");
|
||||||
BitsInit *BI = (BitsInit*)Val.getValue();
|
BitsInit *BI = (BitsInit*)Val.getValue();
|
||||||
assert(BI->getNumBits() <= 32 && "Can only handle fields up to 32 bits!");
|
assert(BI->getNumBits() <= 32 && "Can only handle fields up to 32 bits!");
|
||||||
|
|
||||||
@@ -325,17 +325,17 @@ static void PrintValue(Record *I, unsigned char *Ptr, const RecordVal &Val) {
|
|||||||
if (Vals[f].getPrefix()) {
|
if (Vals[f].getPrefix()) {
|
||||||
BitsInit *FieldInitializer = (BitsInit*)Vals[f].getValue();
|
BitsInit *FieldInitializer = (BitsInit*)Vals[f].getValue();
|
||||||
if (&Vals[f] == &Val) {
|
if (&Vals[f] == &Val) {
|
||||||
// Read the bits directly now...
|
// Read the bits directly now...
|
||||||
for (unsigned i = 0, e = BI->getNumBits(); i != e; ++i)
|
for (unsigned i = 0, e = BI->getNumBits(); i != e; ++i)
|
||||||
Value |= getMemoryBit(Ptr, Offset+i) << i;
|
Value |= getMemoryBit(Ptr, Offset+i) << i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scan through the field looking for bit initializers of the current
|
// Scan through the field looking for bit initializers of the current
|
||||||
// variable...
|
// variable...
|
||||||
for (unsigned i = 0, e = FieldInitializer->getNumBits(); i != e; ++i)
|
for (unsigned i = 0, e = FieldInitializer->getNumBits(); i != e; ++i)
|
||||||
if (VarBitInit *VBI =
|
if (VarBitInit *VBI =
|
||||||
dynamic_cast<VarBitInit*>(FieldInitializer->getBit(i))) {
|
dynamic_cast<VarBitInit*>(FieldInitializer->getBit(i))) {
|
||||||
TypedInit *TI = VBI->getVariable();
|
TypedInit *TI = VBI->getVariable();
|
||||||
if (VarInit *VI = dynamic_cast<VarInit*>(TI)) {
|
if (VarInit *VI = dynamic_cast<VarInit*>(TI)) {
|
||||||
if (VI->getName() == Val.getName())
|
if (VI->getName() == Val.getName())
|
||||||
@@ -344,7 +344,7 @@ static void PrintValue(Record *I, unsigned char *Ptr, const RecordVal &Val) {
|
|||||||
// FIXME: implement this!
|
// FIXME: implement this!
|
||||||
std::cerr << "FIELD INIT not implemented yet!\n";
|
std::cerr << "FIELD INIT not implemented yet!\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Offset += FieldInitializer->getNumBits();
|
Offset += FieldInitializer->getNumBits();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -353,8 +353,8 @@ static void PrintValue(Record *I, unsigned char *Ptr, const RecordVal &Val) {
|
|||||||
|
|
||||||
static void PrintInstruction(Record *I, unsigned char *Ptr) {
|
static void PrintInstruction(Record *I, unsigned char *Ptr) {
|
||||||
std::cout << "Inst " << getNumBits(I)/8 << " bytes: "
|
std::cout << "Inst " << getNumBits(I)/8 << " bytes: "
|
||||||
<< "\t" << I->getName() << "\t" << *I->getValue("Name")->getValue()
|
<< "\t" << I->getName() << "\t" << *I->getValue("Name")->getValue()
|
||||||
<< "\t";
|
<< "\t";
|
||||||
|
|
||||||
const std::vector<RecordVal> &Vals = I->getValues();
|
const std::vector<RecordVal> &Vals = I->getValues();
|
||||||
for (unsigned i = 0, e = Vals.size(); i != e; ++i)
|
for (unsigned i = 0, e = Vals.size(); i != e; ++i)
|
||||||
@@ -371,21 +371,21 @@ static void ParseMachineCode() {
|
|||||||
// X86 code
|
// X86 code
|
||||||
unsigned char Buffer[] = {
|
unsigned char Buffer[] = {
|
||||||
0x55, // push EBP
|
0x55, // push EBP
|
||||||
0x89, 0xE5, // mov EBP, ESP
|
0x89, 0xE5, // mov EBP, ESP
|
||||||
//0x83, 0xEC, 0x08, // sub ESP, 0x8
|
//0x83, 0xEC, 0x08, // sub ESP, 0x8
|
||||||
0xE8, 1, 2, 3, 4, // call +0x04030201
|
0xE8, 1, 2, 3, 4, // call +0x04030201
|
||||||
0x89, 0xEC, // mov ESP, EBP
|
0x89, 0xEC, // mov ESP, EBP
|
||||||
0x5D, // pop EBP
|
0x5D, // pop EBP
|
||||||
0xC3, // ret
|
0xC3, // ret
|
||||||
0x90, // nop
|
0x90, // nop
|
||||||
0xC9, // leave
|
0xC9, // leave
|
||||||
0x89, 0xF6, // mov ESI, ESI
|
0x89, 0xF6, // mov ESI, ESI
|
||||||
0x68, 1, 2, 3, 4, // push 0x04030201
|
0x68, 1, 2, 3, 4, // push 0x04030201
|
||||||
0x5e, // pop ESI
|
0x5e, // pop ESI
|
||||||
0xFF, 0xD0, // call EAX
|
0xFF, 0xD0, // call EAX
|
||||||
0xB8, 1, 2, 3, 4, // mov EAX, 0x04030201
|
0xB8, 1, 2, 3, 4, // mov EAX, 0x04030201
|
||||||
0x85, 0xC0, // test EAX, EAX
|
0x85, 0xC0, // test EAX, EAX
|
||||||
0xF4, // hlt
|
0xF4, // hlt
|
||||||
};
|
};
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
|||||||
Reference in New Issue
Block a user