Add error checking code to the node type parser. Start the instruction pattern

reader


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7632 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2003-08-06 06:16:35 +00:00
parent faca5ab189
commit 2787d1a34b
4 changed files with 68 additions and 14 deletions

View File

@@ -24,7 +24,6 @@ NodeType::ArgResultTypes NodeType::Translate(Record *R) {
/// ///
void InstrSelectorEmitter::ProcessNodeTypes() { void InstrSelectorEmitter::ProcessNodeTypes() {
std::vector<Record*> Nodes = Records.getAllDerivedDefinitions("DagNode"); std::vector<Record*> Nodes = Records.getAllDerivedDefinitions("DagNode");
for (unsigned i = 0, e = Nodes.size(); i != e; ++i) { for (unsigned i = 0, e = Nodes.size(); i != e; ++i) {
Record *Node = Nodes[i]; Record *Node = Nodes[i];
@@ -36,21 +35,48 @@ void InstrSelectorEmitter::ProcessNodeTypes() {
ListInit *Args = Node->getValueAsListInit("ArgTypes"); ListInit *Args = Node->getValueAsListInit("ArgTypes");
std::vector<NodeType::ArgResultTypes> ArgTypes; std::vector<NodeType::ArgResultTypes> ArgTypes;
for (unsigned a = 0, e = Args->getSize(); a != e; ++a) for (unsigned a = 0, e = Args->getSize(); a != e; ++a) {
if (DefInit *DI = dynamic_cast<DefInit*>(Args->getElement(a))) if (DefInit *DI = dynamic_cast<DefInit*>(Args->getElement(a)))
ArgTypes.push_back(NodeType::Translate(DI->getDef())); ArgTypes.push_back(NodeType::Translate(DI->getDef()));
else else
throw "In node " + Node->getName() + ", argument is not a Def!"; throw "In node " + Node->getName() + ", argument is not a Def!";
if (a == 0 && ArgTypes.back() == NodeType::Arg0)
throw "In node " + Node->getName() + ", arg 0 cannot have type 'arg0'!";
if (ArgTypes.back() == NodeType::Void)
throw "In node " + Node->getName() + ", args cannot be void type!";
}
if (RetTy == NodeType::Arg0 && Args->getSize() == 0)
throw "In node " + Node->getName() +
", invalid return type for nullary node!";
// Add the node type mapping now... // Add the node type mapping now...
NodeTypes[Node] = NodeType(RetTy, ArgTypes); NodeTypes[Node] = NodeType(RetTy, ArgTypes);
} }
} }
/// ProcessInstructionPatterns - Read in all subclasses of Instruction, and
/// process those with a useful Pattern field.
///
void InstrSelectorEmitter::ProcessInstructionPatterns() {
std::vector<Record*> Insts = Records.getAllDerivedDefinitions("Instruction");
for (unsigned i = 0, e = Insts.size(); i != e; ++i) {
Record *Inst = Insts[i];
if (DagInit *PatternInit =
dynamic_cast<DagInit*>(Inst->getValueInit("Pattern"))) {
}
}
}
void InstrSelectorEmitter::run(std::ostream &OS) { void InstrSelectorEmitter::run(std::ostream &OS) {
// Type-check all of the node types to ensure we "understand" them. // Type-check all of the node types to ensure we "understand" them.
ProcessNodeTypes(); ProcessNodeTypes();
// Read all of the instruction patterns in...
ProcessInstructionPatterns();
// Read all of the Expander patterns in...
} }

View File

@@ -17,12 +17,10 @@ struct NodeType {
// Both argument and return types... // Both argument and return types...
Val, // A non-void type Val, // A non-void type
Arg0, // Value matches the type of Arg0 Arg0, // Value matches the type of Arg0
Ptr, // Tree node is the type of the target pointer
// Return types // Return types
Void, // Tree node always returns void Void, // Tree node always returns void
// Argument types
Ptr, // Tree node is the target argument type
}; };
ArgResultTypes ResultType; ArgResultTypes ResultType;
@@ -36,7 +34,6 @@ struct NodeType {
NodeType(const NodeType &N) : ResultType(N.ResultType), ArgTypes(N.ArgTypes){} NodeType(const NodeType &N) : ResultType(N.ResultType), ArgTypes(N.ArgTypes){}
static ArgResultTypes Translate(Record *R); static ArgResultTypes Translate(Record *R);
}; };
class InstrSelectorEmitter : public TableGenBackend { class InstrSelectorEmitter : public TableGenBackend {
@@ -54,6 +51,10 @@ private:
// RecordKeeper, turning them into the more accessible NodeTypes data // RecordKeeper, turning them into the more accessible NodeTypes data
// structure. // structure.
void ProcessNodeTypes(); void ProcessNodeTypes();
// ProcessInstructionPatterns - Read in all subclasses of Instruction, and
// process those with a useful Pattern field.
void ProcessInstructionPatterns();
}; };
#endif #endif

View File

@@ -24,7 +24,6 @@ NodeType::ArgResultTypes NodeType::Translate(Record *R) {
/// ///
void InstrSelectorEmitter::ProcessNodeTypes() { void InstrSelectorEmitter::ProcessNodeTypes() {
std::vector<Record*> Nodes = Records.getAllDerivedDefinitions("DagNode"); std::vector<Record*> Nodes = Records.getAllDerivedDefinitions("DagNode");
for (unsigned i = 0, e = Nodes.size(); i != e; ++i) { for (unsigned i = 0, e = Nodes.size(); i != e; ++i) {
Record *Node = Nodes[i]; Record *Node = Nodes[i];
@@ -36,21 +35,48 @@ void InstrSelectorEmitter::ProcessNodeTypes() {
ListInit *Args = Node->getValueAsListInit("ArgTypes"); ListInit *Args = Node->getValueAsListInit("ArgTypes");
std::vector<NodeType::ArgResultTypes> ArgTypes; std::vector<NodeType::ArgResultTypes> ArgTypes;
for (unsigned a = 0, e = Args->getSize(); a != e; ++a) for (unsigned a = 0, e = Args->getSize(); a != e; ++a) {
if (DefInit *DI = dynamic_cast<DefInit*>(Args->getElement(a))) if (DefInit *DI = dynamic_cast<DefInit*>(Args->getElement(a)))
ArgTypes.push_back(NodeType::Translate(DI->getDef())); ArgTypes.push_back(NodeType::Translate(DI->getDef()));
else else
throw "In node " + Node->getName() + ", argument is not a Def!"; throw "In node " + Node->getName() + ", argument is not a Def!";
if (a == 0 && ArgTypes.back() == NodeType::Arg0)
throw "In node " + Node->getName() + ", arg 0 cannot have type 'arg0'!";
if (ArgTypes.back() == NodeType::Void)
throw "In node " + Node->getName() + ", args cannot be void type!";
}
if (RetTy == NodeType::Arg0 && Args->getSize() == 0)
throw "In node " + Node->getName() +
", invalid return type for nullary node!";
// Add the node type mapping now... // Add the node type mapping now...
NodeTypes[Node] = NodeType(RetTy, ArgTypes); NodeTypes[Node] = NodeType(RetTy, ArgTypes);
} }
} }
/// ProcessInstructionPatterns - Read in all subclasses of Instruction, and
/// process those with a useful Pattern field.
///
void InstrSelectorEmitter::ProcessInstructionPatterns() {
std::vector<Record*> Insts = Records.getAllDerivedDefinitions("Instruction");
for (unsigned i = 0, e = Insts.size(); i != e; ++i) {
Record *Inst = Insts[i];
if (DagInit *PatternInit =
dynamic_cast<DagInit*>(Inst->getValueInit("Pattern"))) {
}
}
}
void InstrSelectorEmitter::run(std::ostream &OS) { void InstrSelectorEmitter::run(std::ostream &OS) {
// Type-check all of the node types to ensure we "understand" them. // Type-check all of the node types to ensure we "understand" them.
ProcessNodeTypes(); ProcessNodeTypes();
// Read all of the instruction patterns in...
ProcessInstructionPatterns();
// Read all of the Expander patterns in...
} }

View File

@@ -17,12 +17,10 @@ struct NodeType {
// Both argument and return types... // Both argument and return types...
Val, // A non-void type Val, // A non-void type
Arg0, // Value matches the type of Arg0 Arg0, // Value matches the type of Arg0
Ptr, // Tree node is the type of the target pointer
// Return types // Return types
Void, // Tree node always returns void Void, // Tree node always returns void
// Argument types
Ptr, // Tree node is the target argument type
}; };
ArgResultTypes ResultType; ArgResultTypes ResultType;
@@ -36,7 +34,6 @@ struct NodeType {
NodeType(const NodeType &N) : ResultType(N.ResultType), ArgTypes(N.ArgTypes){} NodeType(const NodeType &N) : ResultType(N.ResultType), ArgTypes(N.ArgTypes){}
static ArgResultTypes Translate(Record *R); static ArgResultTypes Translate(Record *R);
}; };
class InstrSelectorEmitter : public TableGenBackend { class InstrSelectorEmitter : public TableGenBackend {
@@ -54,6 +51,10 @@ private:
// RecordKeeper, turning them into the more accessible NodeTypes data // RecordKeeper, turning them into the more accessible NodeTypes data
// structure. // structure.
void ProcessNodeTypes(); void ProcessNodeTypes();
// ProcessInstructionPatterns - Read in all subclasses of Instruction, and
// process those with a useful Pattern field.
void ProcessInstructionPatterns();
}; };
#endif #endif