forked from OSchip/llvm-project
MIR Parser: Extract the method 'parseGlobalValue'. NFC.
This commit extracts the code that parses a global value from the method 'parseGlobalAddressOperand' into a new method 'parseGlobalValue', so that this code can be reused by the method which will parse the block address machine operands. llvm-svn: 243450
This commit is contained in:
parent
82a1cfdca2
commit
41df7d3d10
|
@ -113,6 +113,7 @@ public:
|
||||||
bool parseMBBOperand(MachineOperand &Dest);
|
bool parseMBBOperand(MachineOperand &Dest);
|
||||||
bool parseStackObjectOperand(MachineOperand &Dest);
|
bool parseStackObjectOperand(MachineOperand &Dest);
|
||||||
bool parseFixedStackObjectOperand(MachineOperand &Dest);
|
bool parseFixedStackObjectOperand(MachineOperand &Dest);
|
||||||
|
bool parseGlobalValue(GlobalValue *&GV);
|
||||||
bool parseGlobalAddressOperand(MachineOperand &Dest);
|
bool parseGlobalAddressOperand(MachineOperand &Dest);
|
||||||
bool parseConstantPoolIndexOperand(MachineOperand &Dest);
|
bool parseConstantPoolIndexOperand(MachineOperand &Dest);
|
||||||
bool parseJumpTableIndexOperand(MachineOperand &Dest);
|
bool parseJumpTableIndexOperand(MachineOperand &Dest);
|
||||||
|
@ -576,18 +577,17 @@ bool MIParser::parseFixedStackObjectOperand(MachineOperand &Dest) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MIParser::parseGlobalAddressOperand(MachineOperand &Dest) {
|
bool MIParser::parseGlobalValue(GlobalValue *&GV) {
|
||||||
switch (Token.kind()) {
|
switch (Token.kind()) {
|
||||||
case MIToken::NamedGlobalValue:
|
case MIToken::NamedGlobalValue:
|
||||||
case MIToken::QuotedNamedGlobalValue: {
|
case MIToken::QuotedNamedGlobalValue: {
|
||||||
StringValueUtility Name(Token);
|
StringValueUtility Name(Token);
|
||||||
const Module *M = MF.getFunction()->getParent();
|
const Module *M = MF.getFunction()->getParent();
|
||||||
if (const auto *GV = M->getNamedValue(Name)) {
|
GV = M->getNamedValue(Name);
|
||||||
Dest = MachineOperand::CreateGA(GV, /*Offset=*/0);
|
if (!GV)
|
||||||
break;
|
return error(Twine("use of undefined global value '@") +
|
||||||
}
|
Token.rawStringValue() + "'");
|
||||||
return error(Twine("use of undefined global value '@") +
|
break;
|
||||||
Token.rawStringValue() + "'");
|
|
||||||
}
|
}
|
||||||
case MIToken::GlobalValue: {
|
case MIToken::GlobalValue: {
|
||||||
unsigned GVIdx;
|
unsigned GVIdx;
|
||||||
|
@ -596,13 +596,20 @@ bool MIParser::parseGlobalAddressOperand(MachineOperand &Dest) {
|
||||||
if (GVIdx >= IRSlots.GlobalValues.size())
|
if (GVIdx >= IRSlots.GlobalValues.size())
|
||||||
return error(Twine("use of undefined global value '@") + Twine(GVIdx) +
|
return error(Twine("use of undefined global value '@") + Twine(GVIdx) +
|
||||||
"'");
|
"'");
|
||||||
Dest = MachineOperand::CreateGA(IRSlots.GlobalValues[GVIdx],
|
GV = IRSlots.GlobalValues[GVIdx];
|
||||||
/*Offset=*/0);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
llvm_unreachable("The current token should be a global value");
|
llvm_unreachable("The current token should be a global value");
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MIParser::parseGlobalAddressOperand(MachineOperand &Dest) {
|
||||||
|
GlobalValue *GV = nullptr;
|
||||||
|
if (parseGlobalValue(GV))
|
||||||
|
return true;
|
||||||
|
Dest = MachineOperand::CreateGA(GV, /*Offset=*/0);
|
||||||
// TODO: Parse offset and target flags.
|
// TODO: Parse offset and target flags.
|
||||||
lex();
|
lex();
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in New Issue