aboutsummaryrefslogtreecommitdiffstats
path: root/utils/TableGen/AsmMatcherEmitter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'utils/TableGen/AsmMatcherEmitter.cpp')
-rw-r--r--utils/TableGen/AsmMatcherEmitter.cpp33
1 files changed, 30 insertions, 3 deletions
diff --git a/utils/TableGen/AsmMatcherEmitter.cpp b/utils/TableGen/AsmMatcherEmitter.cpp
index e0ee944..1d4ad09 100644
--- a/utils/TableGen/AsmMatcherEmitter.cpp
+++ b/utils/TableGen/AsmMatcherEmitter.cpp
@@ -17,8 +17,35 @@
#include "Record.h"
using namespace llvm;
-void AsmMatcherEmitter::run(raw_ostream &O) {
- EmitSourceFileHeader("Assembly Matcher Source Fragment", O);
-
+void AsmMatcherEmitter::run(raw_ostream &OS) {
CodeGenTarget Target;
+ const std::vector<CodeGenRegister> &Registers = Target.getRegisters();
+
+ std::string Namespace = Registers[0].TheDef->getValueAsString("Namespace");
+
+ EmitSourceFileHeader("Assembly Matcher Source Fragment", OS);
+ OS << "namespace llvm {\n\n";
+
+ // Emit the function to match a register name to number.
+
+ if (!Namespace.empty())
+ OS << "namespace " << Namespace << " {\n";
+ OS << "bool MatchRegisterName(const std::string &Name, unsigned &RegNo) {\n";
+
+ // FIXME: TableGen should have a fast string matcher generator.
+ for (unsigned i = 0, e = Registers.size(); i != e; ++i) {
+ const CodeGenRegister &Reg = Registers[i];
+ if (Reg.TheDef->getValueAsString("AsmName").empty())
+ continue;
+
+ OS << " if (Name == \""
+ << Reg.TheDef->getValueAsString("AsmName") << "\")\n"
+ << " return RegNo=" << i + 1 << ", false;\n";
+ }
+ OS << " return true;\n";
+ OS << "}\n";
+
+ if (!Namespace.empty())
+ OS << "}\n";
+ OS << "} // End llvm namespace \n";
}