diff options
Diffstat (limited to 'llvm/utils/TableGen/PredicateExpander.cpp')
-rw-r--r-- | llvm/utils/TableGen/PredicateExpander.cpp | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/llvm/utils/TableGen/PredicateExpander.cpp b/llvm/utils/TableGen/PredicateExpander.cpp index 68eb32794a0..6f611737a43 100644 --- a/llvm/utils/TableGen/PredicateExpander.cpp +++ b/llvm/utils/TableGen/PredicateExpander.cpp @@ -176,6 +176,72 @@ void PredicateExpander::expandCheckNonPortable(formatted_raw_ostream &OS, OS << '(' << Code << ')'; } +void PredicateExpander::expandReturnStatement(formatted_raw_ostream &OS, + const Record *Rec) { + OS << "return "; + expandPredicate(OS, Rec); + OS << ";"; +} + +void PredicateExpander::expandOpcodeSwitchCase(formatted_raw_ostream &OS, + const Record *Rec) { + const RecVec &Opcodes = Rec->getValueAsListOfDefs("Opcodes"); + for (const Record *Opcode : Opcodes) { + OS.PadToColumn(getIndentLevel() * 2); + OS << "case " << Opcode->getValueAsString("Namespace") + << "::" << Opcode->getName() << " :\n"; + } + + increaseIndentLevel(); + expandStatement(OS, Rec->getValueAsDef("CaseStmt")); + decreaseIndentLevel(); +} + +void PredicateExpander::expandOpcodeSwitchStatement(formatted_raw_ostream &OS, + const RecVec &Cases, + const Record *Default) { + OS << "switch(MI" << (isByRef() ? "." : "->") << "getOpcode()) {\n"; + + for (const Record *Rec : Cases) { + expandOpcodeSwitchCase(OS, Rec); + OS << '\n'; + } + + unsigned ColNum = getIndentLevel() * 2; + OS.PadToColumn(ColNum); + + // Expand the default case. + OS << "default :\n"; + increaseIndentLevel(); + expandStatement(OS, Default); + decreaseIndentLevel(); + OS << '\n'; + + OS.PadToColumn(ColNum); + OS << "} // end of switch-stmt"; +} + +void PredicateExpander::expandStatement(formatted_raw_ostream &OS, + const Record *Rec) { + OS.flush(); + unsigned ColNum = getIndentLevel() * 2; + if (OS.getColumn() < ColNum) + OS.PadToColumn(ColNum); + + if (Rec->isSubClassOf("MCOpcodeSwitchStatement")) { + expandOpcodeSwitchStatement(OS, Rec->getValueAsListOfDefs("Cases"), + Rec->getValueAsDef("DefaultCase")); + return; + } + + if (Rec->isSubClassOf("MCReturnStatement")) { + expandReturnStatement(OS, Rec->getValueAsDef("Pred")); + return; + } + + llvm_unreachable("No known rules to expand this MCStatement"); +} + void PredicateExpander::expandPredicate(formatted_raw_ostream &OS, const Record *Rec) { OS.flush(); |