1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 11:13:28 +01:00

tblgen/AsmMatcher: Emit simple matcher for register names.

llvm-svn: 76212
This commit is contained in:
Daniel Dunbar 2009-07-17 18:51:11 +00:00
parent 1669f312b5
commit d84feb8aa1

View File

@ -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";
}