summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-08-08 21:22:41 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-08-08 21:22:41 +0000
commit245f05843f7f17406f394696e7330950e6d88e6d (patch)
tree272d5762148564424c66005d1cda4d042c0e20c0 /utils
parentfb373909be8d027786556277b2600d34d0086566 (diff)
downloadllvm-245f05843f7f17406f394696e7330950e6d88e6d.tar.gz
llvm-245f05843f7f17406f394696e7330950e6d88e6d.tar.bz2
llvm-245f05843f7f17406f394696e7330950e6d88e6d.tar.xz
llvm-mc/AsmMatcher: Switch token matching to use the new string matcher.
Also, redefined MatchRegisterName to just return the register value or a sentinel, to simplify the generated code. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78504 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils')
-rw-r--r--utils/TableGen/AsmMatcherEmitter.cpp64
1 files changed, 31 insertions, 33 deletions
diff --git a/utils/TableGen/AsmMatcherEmitter.cpp b/utils/TableGen/AsmMatcherEmitter.cpp
index 015a910ee2..5b590e311d 100644
--- a/utils/TableGen/AsmMatcherEmitter.cpp
+++ b/utils/TableGen/AsmMatcherEmitter.cpp
@@ -690,27 +690,6 @@ static void EmitMatchClassEnumeration(CodeGenTarget &Target,
OS << "}\n\n";
}
-/// EmitMatchRegisterName - Emit the function to match a string to appropriate
-/// match class value.
-static void EmitMatchTokenString(CodeGenTarget &Target,
- std::vector<ClassInfo*> &Infos,
- raw_ostream &OS) {
- // FIXME: TableGen should have a fast string matcher generator.
- OS << "static MatchClassKind MatchTokenString(const StringRef &Name) {\n";
- for (std::vector<ClassInfo*>::iterator it = Infos.begin(),
- ie = Infos.end(); it != ie; ++it) {
- ClassInfo &CI = **it;
-
- if (CI.Kind == ClassInfo::Token)
- OS << " if (Name == \"" << CI.ValueName << "\")\n"
- << " return " << CI.Name << ";\n\n";
- }
- OS << " return InvalidMatchClass;\n";
- OS << "}\n\n";
-}
-
-
-
/// EmitClassifyOperand - Emit the function to classify an operand.
static void EmitClassifyOperand(CodeGenTarget &Target,
std::vector<ClassInfo*> &Infos,
@@ -860,32 +839,51 @@ static void EmitStringMatcher(const std::string &StrVariableName,
}
+/// EmitMatchTokenString - Emit the function to match a token string to the
+/// appropriate match class value.
+static void EmitMatchTokenString(CodeGenTarget &Target,
+ std::vector<ClassInfo*> &Infos,
+ raw_ostream &OS) {
+ // Construct the match list.
+ std::vector<StringPair> Matches;
+ for (std::vector<ClassInfo*>::iterator it = Infos.begin(),
+ ie = Infos.end(); it != ie; ++it) {
+ ClassInfo &CI = **it;
+
+ if (CI.Kind == ClassInfo::Token)
+ Matches.push_back(StringPair(CI.ValueName, "return " + CI.Name + ";"));
+ }
+
+ OS << "static MatchClassKind MatchTokenString(const StringRef &Name) {\n";
+
+ EmitStringMatcher("Name", Matches, OS);
+
+ OS << " return InvalidMatchClass;\n";
+ OS << "}\n\n";
+}
/// EmitMatchRegisterName - Emit the function to match a string to the target
/// specific register enum.
static void EmitMatchRegisterName(CodeGenTarget &Target, Record *AsmParser,
raw_ostream &OS) {
- const std::vector<CodeGenRegister> &Registers = Target.getRegisters();
-
- OS << "bool " << Target.getName()
- << AsmParser->getValueAsString("AsmParserClassName")
- << "::MatchRegisterName(const StringRef &Name, unsigned &RegNo) {\n";
-
+ // Construct the match list.
std::vector<StringPair> Matches;
-
- // FIXME: TableGen should have a fast string matcher generator.
- for (unsigned i = 0, e = Registers.size(); i != e; ++i) {
- const CodeGenRegister &Reg = Registers[i];
+ for (unsigned i = 0, e = Target.getRegisters().size(); i != e; ++i) {
+ const CodeGenRegister &Reg = Target.getRegisters()[i];
if (Reg.TheDef->getValueAsString("AsmName").empty())
continue;
Matches.push_back(StringPair(Reg.TheDef->getValueAsString("AsmName"),
- "RegNo=" + utostr(i + 1) + "; return false;"));
+ "return " + utostr(i + 1) + ";"));
}
+ OS << "unsigned " << Target.getName()
+ << AsmParser->getValueAsString("AsmParserClassName")
+ << "::MatchRegisterName(const StringRef &Name) {\n";
+
EmitStringMatcher("Name", Matches, OS);
- OS << " return true;\n";
+ OS << " return 0;\n";
OS << "}\n\n";
}