From e2eec05e60c784065322da89f701e281675f2aaf Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Fri, 17 Jul 2009 18:51:11 +0000 Subject: [PATCH] tblgen/AsmMatcher: Emit simple matcher for register names. llvm-svn: 76212 --- llvm/utils/TableGen/AsmMatcherEmitter.cpp | 33 ++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/llvm/utils/TableGen/AsmMatcherEmitter.cpp b/llvm/utils/TableGen/AsmMatcherEmitter.cpp index e0ee9443b96a..1d4ad0947aee 100644 --- a/llvm/utils/TableGen/AsmMatcherEmitter.cpp +++ b/llvm/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 &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"; }