MIR Parser: Add support for quoted named global value operands.

This commit extends the machine instruction lexer and implements support for
the quoted global value tokens. With this change the syntax for the global value
identifier tokens becomes identical to the syntax for the global identifier
tokens from the LLVM's assembly language.

Reviewers: Duncan P. N. Exon Smith


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@242702 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Alex Lorenz
2015-07-20 20:31:01 +00:00
parent 1c12cc02fd
commit 40fefe0084
5 changed files with 145 additions and 7 deletions

View File

@@ -31,6 +31,22 @@ using namespace llvm;
namespace {
struct StringValueUtility {
StringRef String;
std::string UnescapedString;
StringValueUtility(const MIToken &Token) {
if (Token.isStringValueQuoted()) {
Token.unescapeQuotedStringValue(UnescapedString);
String = UnescapedString;
return;
}
String = Token.stringValue();
}
operator StringRef() const { return String; }
};
/// A wrapper struct around the 'MachineOperand' struct that includes a source
/// range.
struct MachineOperandWithLocation {
@@ -485,14 +501,16 @@ bool MIParser::parseFixedStackObjectOperand(MachineOperand &Dest) {
bool MIParser::parseGlobalAddressOperand(MachineOperand &Dest) {
switch (Token.kind()) {
case MIToken::NamedGlobalValue: {
auto Name = Token.stringValue();
case MIToken::NamedGlobalValue:
case MIToken::QuotedNamedGlobalValue: {
StringValueUtility Name(Token);
const Module *M = MF.getFunction()->getParent();
if (const auto *GV = M->getNamedValue(Name)) {
Dest = MachineOperand::CreateGA(GV, /*Offset=*/0);
break;
}
return error(Twine("use of undefined global value '@") + Name + "'");
return error(Twine("use of undefined global value '@") +
Token.rawStringValue() + "'");
}
case MIToken::GlobalValue: {
unsigned GVIdx;
@@ -548,6 +566,7 @@ bool MIParser::parseMachineOperand(MachineOperand &Dest) {
return parseFixedStackObjectOperand(Dest);
case MIToken::GlobalValue:
case MIToken::NamedGlobalValue:
case MIToken::QuotedNamedGlobalValue:
return parseGlobalAddressOperand(Dest);
case MIToken::JumpTableIndex:
return parseJumpTableIndexOperand(Dest);