diff options
author | Chris Lattner <sabre@nondot.org> | 2004-10-03 20:19:02 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2004-10-03 20:19:02 +0000 |
commit | 953c6fe11277c2511744440f5d8d90aca1354e18 (patch) | |
tree | eed6d50ebb92a1134ea68f0713ee49dc23383f07 /utils | |
parent | 560a79f1ea4d1a04bd1da7fd0ca57cfe80620c5a (diff) | |
download | external_llvm-953c6fe11277c2511744440f5d8d90aca1354e18.zip external_llvm-953c6fe11277c2511744440f5d8d90aca1354e18.tar.gz external_llvm-953c6fe11277c2511744440f5d8d90aca1354e18.tar.bz2 |
Correctly parse variant notation
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16637 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils')
-rw-r--r-- | utils/TableGen/AsmWriterEmitter.cpp | 48 |
1 files changed, 42 insertions, 6 deletions
diff --git a/utils/TableGen/AsmWriterEmitter.cpp b/utils/TableGen/AsmWriterEmitter.cpp index 64debe2..a2cc21d 100644 --- a/utils/TableGen/AsmWriterEmitter.cpp +++ b/utils/TableGen/AsmWriterEmitter.cpp @@ -30,24 +30,24 @@ void AsmWriterEmitter::run(std::ostream &O) { O << "namespace llvm {\n\n"; CodeGenTarget Target; - Record *AsmWriter = Target.getAsmWriter(); - - std::string AsmWriterClassName = - AsmWriter->getValueAsString("AsmWriterClassName"); + std::string ClassName = AsmWriter->getValueAsString("AsmWriterClassName"); + unsigned Variant = AsmWriter->getValueAsInt("Variant"); O << "/// printInstruction - This method is automatically generated by tablegen\n" "/// from the instruction set description. This method returns true if the\n" "/// machine instruction was sufficiently described to print it, otherwise\n" "/// it returns false.\n" - "bool " << Target.getName() << AsmWriterClassName + "bool " << Target.getName() << ClassName << "::printInstruction(const MachineInstr *MI) {\n"; O << " switch (MI->getOpcode()) {\n" " default: return false;\n"; std::string Namespace = Target.inst_begin()->second.Namespace; + bool inVariant = false; // True if we are inside a {.|.|.} region. + for (CodeGenTarget::inst_iterator I = Target.inst_begin(), E = Target.inst_end(); I != E; ++I) if (!I->second.AsmString.empty()) { @@ -56,7 +56,8 @@ void AsmWriterEmitter::run(std::ostream &O) { std::string::size_type LastEmitted = 0; while (LastEmitted != AsmString.size()) { - std::string::size_type DollarPos = AsmString.find('$', LastEmitted); + std::string::size_type DollarPos = + AsmString.find_first_of("${|}", LastEmitted); if (DollarPos == std::string::npos) DollarPos = AsmString.size(); // Emit a constant string fragment. @@ -65,6 +66,41 @@ void AsmWriterEmitter::run(std::ostream &O) { O << " << \"" << std::string(AsmString.begin()+LastEmitted, AsmString.begin()+DollarPos) << "\""; LastEmitted = DollarPos; + } else if (AsmString[DollarPos] == '{') { + if (inVariant) + throw "Nested variants found for instruction '" + I->first + "'!"; + LastEmitted = DollarPos+1; + inVariant = true; // We are now inside of the variant! + for (unsigned i = 0; i != Variant; ++i) { + // Skip over all of the text for an irrelevant variant here. The + // next variant starts at |, or there may not be text for this + // variant if we see a }. + std::string::size_type NP = + AsmString.find_first_of("|}", LastEmitted); + if (NP == std::string::npos) + throw "Incomplete variant for instruction '" + I->first + "'!"; + LastEmitted = NP+1; + if (AsmString[NP] == '}') { + inVariant = false; // No text for this variant. + break; + } + } + } else if (AsmString[DollarPos] == '|') { + if (!inVariant) + throw "'|' character found outside of a variant in instruction '" + + I->first + "'!"; + // Move to the end of variant list. + std::string::size_type NP = AsmString.find('}', LastEmitted); + if (NP == std::string::npos) + throw "Incomplete variant for instruction '" + I->first + "'!"; + LastEmitted = NP+1; + inVariant = false; + } else if (AsmString[DollarPos] == '}') { + if (!inVariant) + throw "'}' character found outside of a variant in instruction '" + + I->first + "'!"; + LastEmitted = DollarPos+1; + inVariant = false; } else if (DollarPos+1 != AsmString.size() && AsmString[DollarPos+1] == '$') { O << " << '$'"; // "$$" -> $ |