mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-02-01 13:11:39 +01:00
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. llvm-svn: 78504
This commit is contained in:
parent
e5e5b0a1bd
commit
246602757e
@ -46,7 +46,9 @@ private:
|
|||||||
bool MatchInstruction(SmallVectorImpl<X86Operand> &Operands,
|
bool MatchInstruction(SmallVectorImpl<X86Operand> &Operands,
|
||||||
MCInst &Inst);
|
MCInst &Inst);
|
||||||
|
|
||||||
bool MatchRegisterName(const StringRef &Name, unsigned &RegNo);
|
/// MatchRegisterName - Match the given string to a register name, or 0 if
|
||||||
|
/// there is no match.
|
||||||
|
unsigned MatchRegisterName(const StringRef &Name);
|
||||||
|
|
||||||
/// }
|
/// }
|
||||||
|
|
||||||
@ -214,7 +216,9 @@ bool X86ATTAsmParser::ParseRegister(X86Operand &Op) {
|
|||||||
// validation later, so maybe there is no need for this here.
|
// validation later, so maybe there is no need for this here.
|
||||||
unsigned RegNo;
|
unsigned RegNo;
|
||||||
assert(Tok.getString().startswith("%") && "Invalid register name!");
|
assert(Tok.getString().startswith("%") && "Invalid register name!");
|
||||||
if (MatchRegisterName(Tok.getString().substr(1), RegNo))
|
|
||||||
|
RegNo = MatchRegisterName(Tok.getString().substr(1));
|
||||||
|
if (RegNo == 0)
|
||||||
return Error(Tok.getLoc(), "invalid register name");
|
return Error(Tok.getLoc(), "invalid register name");
|
||||||
|
|
||||||
Op = X86Operand::CreateReg(RegNo);
|
Op = X86Operand::CreateReg(RegNo);
|
||||||
|
@ -690,27 +690,6 @@ static void EmitMatchClassEnumeration(CodeGenTarget &Target,
|
|||||||
OS << "}\n\n";
|
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.
|
/// EmitClassifyOperand - Emit the function to classify an operand.
|
||||||
static void EmitClassifyOperand(CodeGenTarget &Target,
|
static void EmitClassifyOperand(CodeGenTarget &Target,
|
||||||
std::vector<ClassInfo*> &Infos,
|
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
|
/// EmitMatchRegisterName - Emit the function to match a string to the target
|
||||||
/// specific register enum.
|
/// specific register enum.
|
||||||
static void EmitMatchRegisterName(CodeGenTarget &Target, Record *AsmParser,
|
static void EmitMatchRegisterName(CodeGenTarget &Target, Record *AsmParser,
|
||||||
raw_ostream &OS) {
|
raw_ostream &OS) {
|
||||||
const std::vector<CodeGenRegister> &Registers = Target.getRegisters();
|
// Construct the match list.
|
||||||
|
|
||||||
OS << "bool " << Target.getName()
|
|
||||||
<< AsmParser->getValueAsString("AsmParserClassName")
|
|
||||||
<< "::MatchRegisterName(const StringRef &Name, unsigned &RegNo) {\n";
|
|
||||||
|
|
||||||
std::vector<StringPair> Matches;
|
std::vector<StringPair> Matches;
|
||||||
|
for (unsigned i = 0, e = Target.getRegisters().size(); i != e; ++i) {
|
||||||
// FIXME: TableGen should have a fast string matcher generator.
|
const CodeGenRegister &Reg = Target.getRegisters()[i];
|
||||||
for (unsigned i = 0, e = Registers.size(); i != e; ++i) {
|
|
||||||
const CodeGenRegister &Reg = Registers[i];
|
|
||||||
if (Reg.TheDef->getValueAsString("AsmName").empty())
|
if (Reg.TheDef->getValueAsString("AsmName").empty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Matches.push_back(StringPair(Reg.TheDef->getValueAsString("AsmName"),
|
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);
|
EmitStringMatcher("Name", Matches, OS);
|
||||||
|
|
||||||
OS << " return true;\n";
|
OS << " return 0;\n";
|
||||||
OS << "}\n\n";
|
OS << "}\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user