ARM: prepare prefix parsing for improved AAELF support

AAELF specifies a number of ELF specific relocation types which have custom
prefixes for the symbol reference.  Switch the parser to be more table driven
with an idea of file formats for which they apply.  NFC.

llvm-svn: 225758
This commit is contained in:
Saleem Abdulrasool 2015-01-13 03:22:49 +00:00
parent 7ad6d620b7
commit faa4f074eb
1 changed files with 43 additions and 5 deletions

View File

@ -5254,15 +5254,52 @@ bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
return true;
}
enum {
COFF = (1 << MCObjectFileInfo::IsCOFF),
ELF = (1 << MCObjectFileInfo::IsELF),
MACHO = (1 << MCObjectFileInfo::IsMachO)
};
static const struct PrefixEntry {
const char *Spelling;
ARMMCExpr::VariantKind VariantKind;
uint8_t SupportedFormats;
} PrefixEntries[] = {
{ "lower16", ARMMCExpr::VK_ARM_LO16, COFF | ELF | MACHO },
{ "upper16", ARMMCExpr::VK_ARM_HI16, COFF | ELF | MACHO },
};
StringRef IDVal = Parser.getTok().getIdentifier();
if (IDVal == "lower16") {
RefKind = ARMMCExpr::VK_ARM_LO16;
} else if (IDVal == "upper16") {
RefKind = ARMMCExpr::VK_ARM_HI16;
} else {
const auto &Prefix =
std::find_if(std::begin(PrefixEntries), std::end(PrefixEntries),
[&IDVal](const PrefixEntry &PE) {
return PE.Spelling == IDVal;
});
if (Prefix == std::end(PrefixEntries)) {
Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
return true;
}
uint8_t CurrentFormat;
switch (getContext().getObjectFileInfo()->getObjectFileType()) {
case MCObjectFileInfo::IsMachO:
CurrentFormat = MACHO;
break;
case MCObjectFileInfo::IsELF:
CurrentFormat = ELF;
break;
case MCObjectFileInfo::IsCOFF:
CurrentFormat = COFF;
break;
}
if (~Prefix->SupportedFormats & CurrentFormat) {
Error(Parser.getTok().getLoc(),
"cannot represent relocation in the current file format");
return true;
}
RefKind = Prefix->VariantKind;
Parser.Lex();
if (getLexer().isNot(AsmToken::Colon)) {
@ -5270,6 +5307,7 @@ bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
return true;
}
Parser.Lex(); // Eat the last ':'
return false;
}