[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
diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp b/llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp
index 5e90bbc..6fe3964 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 @@
   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 @@
   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 @@
   // 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);
+}