summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2010-10-30 18:56:12 +0000
committerChris Lattner <sabre@nondot.org>2010-10-30 18:56:12 +0000
commitcf9b6e31071f13eb5ddbb52339a0b6cefe1121d8 (patch)
treeb481c757c99d6b1cbdca5f96aa75ddaaf80df47f
parent477fba4f54b4fa910364ca4c84c4d6ef37ab44f1 (diff)
downloadbcm5719-llvm-cf9b6e31071f13eb5ddbb52339a0b6cefe1121d8.tar.gz
bcm5719-llvm-cf9b6e31071f13eb5ddbb52339a0b6cefe1121d8.zip
diagnose targets that define two alises with the same 'from' mnemonic
with a useful error message instead of having tblgen explode with an assert. llvm-svn: 117827
-rw-r--r--llvm/utils/TableGen/AsmMatcherEmitter.cpp35
1 files changed, 30 insertions, 5 deletions
diff --git a/llvm/utils/TableGen/AsmMatcherEmitter.cpp b/llvm/utils/TableGen/AsmMatcherEmitter.cpp
index 93d3ac304ea..8cc766e4619 100644
--- a/llvm/utils/TableGen/AsmMatcherEmitter.cpp
+++ b/llvm/utils/TableGen/AsmMatcherEmitter.cpp
@@ -1524,15 +1524,40 @@ static bool EmitMnemonicAliases(raw_ostream &OS) {
Records.getAllDerivedDefinitions("MnemonicAlias");
if (Aliases.empty()) return false;
- std::vector<StringMatcher::StringPair> Cases;
+ // Keep track of all the aliases from a mnemonic. Use an std::map so that the
+ // iteration order of the map is stable.
+ std::map<std::string, std::vector<Record*> > AliasesFromMnemonic;
+
for (unsigned i = 0, e = Aliases.size(); i != e; ++i) {
Record *R = Aliases[i];
- Cases.push_back(std::make_pair(R->getValueAsString("FromMnemonic"),
- "Mnemonic = \"" +
- R->getValueAsString("ToMnemonic") +
- "\"; return;"));
+ AliasesFromMnemonic[R->getValueAsString("FromMnemonic")].push_back(R);
+ }
+
+ // Process each alias a "from" mnemonic at a time, building the code executed
+ // by the string remapper.
+ std::vector<StringMatcher::StringPair> Cases;
+ for (std::map<std::string, std::vector<Record*> >::iterator
+ I = AliasesFromMnemonic.begin(), E = AliasesFromMnemonic.end();
+ I != E; ++I) {
+ const std::string &From = I->first;
+ const std::vector<Record*> &ToVec = I->second;
+
+ // If there is only one destination mnemonic, generate simple code.
+ if (ToVec.size() == 1) {
+ Cases.push_back(std::make_pair(From, "Mnemonic = \"" +
+ ToVec[0]->getValueAsString("ToMnemonic") +
+ "\"; return;"));
+ continue;
+ }
+
+ // Otherwise, diagnose an error, can't have two aliases from the same
+ // mnemonic.
+ PrintError(ToVec[0]->getLoc(), "two MnemonicAliases with the same 'from' mnemonic!");
+ PrintError(ToVec[1]->getLoc(), "this is the other MnemonicAliases.");
+ throw std::string("ERROR: Invalid MnemonicAliases definitions!");
}
+
StringMatcher("Mnemonic", Cases, OS).Emit();
OS << "}\n";
OpenPOWER on IntegriCloud