diff options
author | Jack Carter <jack.carter@imgtec.com> | 2014-01-06 23:27:31 +0000 |
---|---|---|
committer | Jack Carter <jack.carter@imgtec.com> | 2014-01-06 23:27:31 +0000 |
commit | 0cd3c19f33a7bf73511a1a498ef489d07265ef35 (patch) | |
tree | 0943cbc22b4adc7971ac937533038262fe9ccb1d /llvm/lib | |
parent | b2166d8ef3b8456a50e425a7cf2ed1bd6ad93319 (diff) | |
download | bcm5719-llvm-0cd3c19f33a7bf73511a1a498ef489d07265ef35.tar.gz bcm5719-llvm-0cd3c19f33a7bf73511a1a498ef489d07265ef35.zip |
[Mips] TargetStreamer Support for .abicalls and .set pic0.
This patch adds .abicalls and .set pic0 support which
affects the ELF ABI and its flags. In addition the patch uses
a common interface for both the MipsTargetSteamer and
MipsObjectStreamer that both the integrated and standalone
assemblers will use for the output for these directives.
llvm-svn: 198646
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp | 43 | ||||
-rw-r--r-- | llvm/lib/Target/Mips/MCTargetDesc/MipsMCTargetDesc.cpp | 1 | ||||
-rw-r--r-- | llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp | 24 | ||||
-rw-r--r-- | llvm/lib/Target/Mips/MipsAsmPrinter.cpp | 10 | ||||
-rw-r--r-- | llvm/lib/Target/Mips/MipsTargetStreamer.h | 9 |
5 files changed, 77 insertions, 10 deletions
diff --git a/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp b/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp index cae3999c12b..8bbfcd9c32a 100644 --- a/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp +++ b/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp @@ -196,6 +196,7 @@ class MipsAsmParser : public MCTargetAsmParser { bool parseDirectiveSet(); bool parseDirectiveMipsHackStocg(); bool parseDirectiveMipsHackELFFlags(); + bool parseDirectiveOption(); bool parseSetAtDirective(); bool parseSetNoAtDirective(); @@ -2468,6 +2469,35 @@ bool MipsAsmParser::parseDirectiveGpWord() { return false; } +bool MipsAsmParser::parseDirectiveOption() { + // Get the option token. + AsmToken Tok = Parser.getTok(); + // At the moment only identifiers are supported. + if (Tok.isNot(AsmToken::Identifier)) { + Error(Parser.getTok().getLoc(), "unexpected token in .option directive"); + Parser.eatToEndOfStatement(); + return false; + } + + StringRef Option = Tok.getIdentifier(); + + if (Option == "pic0") { + getTargetStreamer().emitDirectiveOptionPic0(); + Parser.Lex(); + if (Parser.getTok().isNot(AsmToken::EndOfStatement)) { + Error(Parser.getTok().getLoc(), + "unexpected token in .option pic0 directive"); + Parser.eatToEndOfStatement(); + } + return false; + } + + // Unknown option. + Warning(Parser.getTok().getLoc(), "unknown option in .option directive"); + Parser.eatToEndOfStatement(); + return false; +} + bool MipsAsmParser::ParseDirective(AsmToken DirectiveID) { StringRef IDVal = DirectiveID.getString(); @@ -2523,6 +2553,19 @@ bool MipsAsmParser::ParseDirective(AsmToken DirectiveID) { if (IDVal == ".mips_hack_elf_flags") return parseDirectiveMipsHackELFFlags(); + if (IDVal == ".option") + return parseDirectiveOption(); + + if (IDVal == ".abicalls") { + getTargetStreamer().emitDirectiveAbiCalls(); + if (Parser.getTok().isNot(AsmToken::EndOfStatement)) { + Error(Parser.getTok().getLoc(), "unexpected token in directive"); + // Clear line + Parser.eatToEndOfStatement(); + } + return false; + } + return true; } diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsMCTargetDesc.cpp b/llvm/lib/Target/Mips/MCTargetDesc/MipsMCTargetDesc.cpp index 5548aaa9a6d..add6e4b751b 100644 --- a/llvm/lib/Target/Mips/MCTargetDesc/MipsMCTargetDesc.cpp +++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsMCTargetDesc.cpp @@ -16,7 +16,6 @@ #include "MipsMCAsmInfo.h" #include "MipsTargetStreamer.h" #include "llvm/MC/MCCodeGenInfo.h" -#include "llvm/MC/MCELF.h" #include "llvm/MC/MCELFStreamer.h" #include "llvm/MC/MCInstrInfo.h" #include "llvm/MC/MCRegisterInfo.h" diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp b/llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp index 5e90bbc635a..6fe39640d87 100644 --- a/llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp +++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp @@ -17,13 +17,14 @@ #include "llvm/Support/CommandLine.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FormattedStream.h" +#include "llvm/Support/ELF.h" using namespace llvm; static cl::opt<bool> PrintHackDirectives("print-hack-directives", cl::init(false), cl::Hidden); -// pin vtable to this file +// Pin vtable to this file. void MipsTargetStreamer::anchor() {} MipsTargetAsmStreamer::MipsTargetAsmStreamer(formatted_raw_ostream &OS) @@ -47,6 +48,13 @@ void MipsTargetAsmStreamer::emitMipsHackSTOCG(MCSymbol *Sym, unsigned Val) { OS << Val; OS << '\n'; } +void MipsTargetAsmStreamer::emitDirectiveAbiCalls() { OS << "\t.abicalls\n"; } +void MipsTargetAsmStreamer::emitDirectiveOptionPic0() { + OS << "\t.option\tpic0\n"; +} + +// This part is for ELF object output. +MipsTargetELFStreamer::MipsTargetELFStreamer() {} MCELFStreamer &MipsTargetELFStreamer::getStreamer() { return static_cast<MCELFStreamer &>(*Streamer); @@ -57,7 +65,7 @@ void MipsTargetELFStreamer::emitMipsHackELFFlags(unsigned Flags) { MCA.setELFHeaderEFlags(Flags); } -// Set a symbol's STO flags +// Set a symbol's STO flags. void MipsTargetELFStreamer::emitMipsHackSTOCG(MCSymbol *Sym, unsigned Val) { MCSymbolData &Data = getStreamer().getOrCreateSymbolData(Sym); // The "other" values are stored in the last 6 bits of the second byte @@ -65,3 +73,15 @@ void MipsTargetELFStreamer::emitMipsHackSTOCG(MCSymbol *Sym, unsigned Val) { // the shift to pack it. MCELF::setOther(Data, Val >> 2); } +void MipsTargetELFStreamer::emitDirectiveAbiCalls() { + MCAssembler &MCA = getStreamer().getAssembler(); + unsigned Flags = MCA.getELFHeaderEFlags(); + Flags |= ELF::EF_MIPS_CPIC; + MCA.setELFHeaderEFlags(Flags); +} +void MipsTargetELFStreamer::emitDirectiveOptionPic0() { + MCAssembler &MCA = getStreamer().getAssembler(); + unsigned Flags = MCA.getELFHeaderEFlags(); + Flags &= ~ELF::EF_MIPS_PIC; + MCA.setELFHeaderEFlags(Flags); +} diff --git a/llvm/lib/Target/Mips/MipsAsmPrinter.cpp b/llvm/lib/Target/Mips/MipsAsmPrinter.cpp index 284e51c5978..d01aed49f9e 100644 --- a/llvm/lib/Target/Mips/MipsAsmPrinter.cpp +++ b/llvm/lib/Target/Mips/MipsAsmPrinter.cpp @@ -608,12 +608,10 @@ void MipsAsmPrinter::EmitStartOfAsmFile(Module &M) { // TODO: Need to add -mabicalls and -mno-abicalls flags. // Currently we assume that -mabicalls is the default. - if (OutStreamer.hasRawTextSupport()) { - OutStreamer.EmitRawText(StringRef("\t.abicalls")); - Reloc::Model RM = Subtarget->getRelocationModel(); - if (RM == Reloc::Static && !Subtarget->hasMips64()) - OutStreamer.EmitRawText(StringRef("\t.option\tpic0")); - } + getTargetStreamer().emitDirectiveAbiCalls(); + Reloc::Model RM = Subtarget->getRelocationModel(); + if (RM == Reloc::Static && !Subtarget->hasMips64()) + getTargetStreamer().emitDirectiveOptionPic0(); // Tell the assembler which ABI we are using if (OutStreamer.hasRawTextSupport()) diff --git a/llvm/lib/Target/Mips/MipsTargetStreamer.h b/llvm/lib/Target/Mips/MipsTargetStreamer.h index 96966fd7cbc..8c53cb5bc2d 100644 --- a/llvm/lib/Target/Mips/MipsTargetStreamer.h +++ b/llvm/lib/Target/Mips/MipsTargetStreamer.h @@ -20,6 +20,8 @@ class MipsTargetStreamer : public MCTargetStreamer { public: virtual void emitMipsHackELFFlags(unsigned Flags) = 0; virtual void emitMipsHackSTOCG(MCSymbol *Sym, unsigned Val) = 0; + virtual void emitDirectiveAbiCalls() = 0; + virtual void emitDirectiveOptionPic0() = 0; }; // This part is for ascii assembly output @@ -30,15 +32,20 @@ public: MipsTargetAsmStreamer(formatted_raw_ostream &OS); virtual void emitMipsHackELFFlags(unsigned Flags); virtual void emitMipsHackSTOCG(MCSymbol *Sym, unsigned Val); + virtual void emitDirectiveAbiCalls(); + virtual void emitDirectiveOptionPic0(); }; // This part is for ELF object output class MipsTargetELFStreamer : public MipsTargetStreamer { public: MCELFStreamer &getStreamer(); + MipsTargetELFStreamer(); + // FIXME: emitMipsHackELFFlags() will be removed from this class. virtual void emitMipsHackELFFlags(unsigned Flags); virtual void emitMipsHackSTOCG(MCSymbol *Sym, unsigned Val); + virtual void emitDirectiveAbiCalls(); + virtual void emitDirectiveOptionPic0(); }; } - #endif |