[MC][AsmParser] Hook for post assembly file processing

This patch handles LLVM standalone assembler (llvm-mc) ELF flag setting based on input file
directive processing.

Mips assembly requires processing inline directives that directly and
indirectly affect the output ELF header flags. This patch handles one
".abicalls".

To process these directives we are following the model the code generator
uses by storing state in a container as we go through processing and when
we detect the end of input file processing, AsmParser is notified and we
update the ELF header flags through a MipsELFStreamer method with a call from
MCTargetAsmParser::emitEndOfAsmFile(MCStreamer &OutStreamer).

This patch will allow other targets the same functionality.

Jack


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191982 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Jack Carter
2013-10-04 21:26:15 +00:00
parent 36ea408903
commit 8e48edcf3d
8 changed files with 111 additions and 7 deletions

View File

@@ -7,6 +7,8 @@
//
//===----------------------------------------------------------------------===//
#include "AsmParser/MipsAsmFlags.h"
#include "MCTargetDesc/MipsELFStreamer.h"
#include "MCTargetDesc/MipsMCTargetDesc.h"
#include "MipsRegisterInfo.h"
#include "llvm/ADT/StringSwitch.h"
@@ -59,6 +61,7 @@ class MipsAsmParser : public MCTargetAsmParser {
MCSubtargetInfo &STI;
MCAsmParser &Parser;
MipsAssemblerOptions Options;
MipsMCAsmFlags Flags;
bool hasConsumedDollar;
#define GET_ASSEMBLER_HEADER
@@ -228,6 +231,8 @@ class MipsAsmParser : public MCTargetAsmParser {
bool processInstruction(MCInst &Inst, SMLoc IDLoc,
SmallVectorImpl<MCInst> &Instructions);
void emitEndOfAsmFile(MCStreamer &Out);
public:
MipsAsmParser(MCSubtargetInfo &sti, MCAsmParser &parser,
const MCInstrInfo &MII)
@@ -2172,9 +2177,23 @@ bool MipsAsmParser::ParseDirective(AsmToken DirectiveID) {
return false;
}
if (IDVal == ".abicalls") {
Flags.setRelocationModel(MipsMCAsmFlags::MAF_RM_CPIC);
if (Parser.getTok().isNot(AsmToken::EndOfStatement))
return Error(Parser.getTok().getLoc(), "unexpected token in directive");
return false;
}
return true;
}
/// End of assembly processing such as updating ELF header flags.
void MipsAsmParser::emitEndOfAsmFile(MCStreamer &OutStreamer) {
if (MipsELFStreamer *MES = dyn_cast<MipsELFStreamer>(&OutStreamer))
MES->emitELFHeaderFlagsAsm(Flags);
MCTargetAsmParser::emitEndOfAsmFile(OutStreamer);
}
extern "C" void LLVMInitializeMipsAsmParser() {
RegisterMCAsmParser<MipsAsmParser> X(TheMipsTarget);
RegisterMCAsmParser<MipsAsmParser> Y(TheMipselTarget);