[llvm-commits] [llvm] r76212 - /llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp
Daniel Dunbar
daniel at zuster.org
Fri Jul 17 11:51:12 PDT 2009
Author: ddunbar
Date: Fri Jul 17 13:51:11 2009
New Revision: 76212
URL: http://llvm.org/viewvc/llvm-project?rev=76212&view=rev
Log:
tblgen/AsmMatcher: Emit simple matcher for register names.
Modified:
llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp
Modified: llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp?rev=76212&r1=76211&r2=76212&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp Fri Jul 17 13:51:11 2009
@@ -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";
}
More information about the llvm-commits
mailing list