forked from OSchip/llvm-project
Simplify the variant handling code, no functionality change.
llvm-svn: 26023
This commit is contained in:
parent
2bf2c8d7e7
commit
033e32e5d9
|
@ -94,7 +94,7 @@ void AsmWriterOperand::EmitCode(std::ostream &OS) const {
|
||||||
///
|
///
|
||||||
AsmWriterInst::AsmWriterInst(const CodeGenInstruction &CGI, unsigned Variant) {
|
AsmWriterInst::AsmWriterInst(const CodeGenInstruction &CGI, unsigned Variant) {
|
||||||
this->CGI = &CGI;
|
this->CGI = &CGI;
|
||||||
bool inVariant = false; // True if we are inside a {.|.|.} region.
|
unsigned CurVariant = ~0U; // ~0 if we are outside a {.|.|.} region, other #.
|
||||||
|
|
||||||
// NOTE: Any extensions to this code need to be mirrored in the
|
// NOTE: Any extensions to this code need to be mirrored in the
|
||||||
// AsmPrinter::printInlineAsm code that executes as compile time (assuming
|
// AsmPrinter::printInlineAsm code that executes as compile time (assuming
|
||||||
|
@ -109,49 +109,31 @@ AsmWriterInst::AsmWriterInst(const CodeGenInstruction &CGI, unsigned Variant) {
|
||||||
// Emit a constant string fragment.
|
// Emit a constant string fragment.
|
||||||
if (DollarPos != LastEmitted) {
|
if (DollarPos != LastEmitted) {
|
||||||
// TODO: this should eventually handle escaping.
|
// TODO: this should eventually handle escaping.
|
||||||
|
if (CurVariant == Variant || CurVariant == ~0U)
|
||||||
AddLiteralString(std::string(AsmString.begin()+LastEmitted,
|
AddLiteralString(std::string(AsmString.begin()+LastEmitted,
|
||||||
AsmString.begin()+DollarPos));
|
AsmString.begin()+DollarPos));
|
||||||
LastEmitted = DollarPos;
|
LastEmitted = DollarPos;
|
||||||
} else if (AsmString[DollarPos] == '{') {
|
} else if (AsmString[DollarPos] == '{') {
|
||||||
if (inVariant)
|
if (CurVariant != ~0U)
|
||||||
throw "Nested variants found for instruction '" +
|
throw "Nested variants found for instruction '" +
|
||||||
CGI.TheDef->getName() + "'!";
|
CGI.TheDef->getName() + "'!";
|
||||||
LastEmitted = DollarPos+1;
|
LastEmitted = DollarPos+1;
|
||||||
inVariant = true; // We are now inside of the variant!
|
CurVariant = 0; // 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 '" +
|
|
||||||
CGI.TheDef->getName() + "'!";
|
|
||||||
LastEmitted = NP+1;
|
|
||||||
if (AsmString[NP] == '}') {
|
|
||||||
inVariant = false; // No text for this variant.
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (AsmString[DollarPos] == '|') {
|
} else if (AsmString[DollarPos] == '|') {
|
||||||
if (!inVariant)
|
if (CurVariant == ~0U)
|
||||||
throw "'|' character found outside of a variant in instruction '"
|
throw "'|' character found outside of a variant in instruction '"
|
||||||
+ CGI.TheDef->getName() + "'!";
|
+ CGI.TheDef->getName() + "'!";
|
||||||
// Move to the end of variant list.
|
++CurVariant;
|
||||||
std::string::size_type NP = AsmString.find('}', LastEmitted);
|
++LastEmitted;
|
||||||
if (NP == std::string::npos)
|
|
||||||
throw "Incomplete variant for instruction '" +
|
|
||||||
CGI.TheDef->getName() + "'!";
|
|
||||||
LastEmitted = NP+1;
|
|
||||||
inVariant = false;
|
|
||||||
} else if (AsmString[DollarPos] == '}') {
|
} else if (AsmString[DollarPos] == '}') {
|
||||||
if (!inVariant)
|
if (CurVariant == ~0U)
|
||||||
throw "'}' character found outside of a variant in instruction '"
|
throw "'}' character found outside of a variant in instruction '"
|
||||||
+ CGI.TheDef->getName() + "'!";
|
+ CGI.TheDef->getName() + "'!";
|
||||||
LastEmitted = DollarPos+1;
|
++LastEmitted;
|
||||||
inVariant = false;
|
CurVariant = ~0U;
|
||||||
} else if (DollarPos+1 != AsmString.size() &&
|
} else if (DollarPos+1 != AsmString.size() &&
|
||||||
AsmString[DollarPos+1] == '$') {
|
AsmString[DollarPos+1] == '$') {
|
||||||
|
if (CurVariant == Variant || CurVariant == ~0U)
|
||||||
AddLiteralString("$"); // "$$" -> $
|
AddLiteralString("$"); // "$$" -> $
|
||||||
LastEmitted = DollarPos+2;
|
LastEmitted = DollarPos+2;
|
||||||
} else {
|
} else {
|
||||||
|
@ -181,7 +163,7 @@ AsmWriterInst::AsmWriterInst(const CodeGenInstruction &CGI, unsigned Variant) {
|
||||||
throw "Reached end of string before terminating curly brace in '"
|
throw "Reached end of string before terminating curly brace in '"
|
||||||
+ CGI.TheDef->getName() + "'";
|
+ CGI.TheDef->getName() + "'";
|
||||||
if (AsmString[VarEnd] != '}')
|
if (AsmString[VarEnd] != '}')
|
||||||
throw "Variant name beginning with '{' did not end with '}' in '"
|
throw "Variable name beginning with '{' did not end with '}' in '"
|
||||||
+ CGI.TheDef->getName() + "'";
|
+ CGI.TheDef->getName() + "'";
|
||||||
++VarEnd;
|
++VarEnd;
|
||||||
}
|
}
|
||||||
|
@ -202,6 +184,7 @@ AsmWriterInst::AsmWriterInst(const CodeGenInstruction &CGI, unsigned Variant) {
|
||||||
--MIOp;
|
--MIOp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (CurVariant == Variant || CurVariant == ~0U)
|
||||||
Operands.push_back(AsmWriterOperand(OpInfo.PrinterMethodName, MIOp));
|
Operands.push_back(AsmWriterOperand(OpInfo.PrinterMethodName, MIOp));
|
||||||
LastEmitted = VarEnd;
|
LastEmitted = VarEnd;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue