[Mips] TargetStreamer Support for .set mips16.
authorJack Carter <jack.carter@imgtec.com>
Wed, 22 Jan 2014 23:08:42 +0000 (23:08 +0000)
committerJack Carter <jack.carter@imgtec.com>
Wed, 22 Jan 2014 23:08:42 +0000 (23:08 +0000)
This patch updates .set mips16 support which
affects the ELF ABI and its flags. In addition the patch uses
a common interface for both the MipsTargetSteamer and
MipsObjectStreamer that the assembler uses for
both ELF and ASCII output for these directives.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199851 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/Mips/AsmParser/MipsAsmParser.cpp
lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp
lib/Target/Mips/MipsTargetStreamer.h
test/MC/Mips/elf_eflags.s

index 31ece464bba9b96453568870450b034cd97aadf2..d63f88f3ed88ca65d733a01a36614c9688d7a7d9 100644 (file)
@@ -203,6 +203,8 @@ class MipsAsmParser : public MCTargetAsmParser {
   bool parseSetNoMacroDirective();
   bool parseSetReorderDirective();
   bool parseSetNoReorderDirective();
+  bool parseSetMips16Directive();
+  bool parseSetNoMips16Directive();
 
   bool parseSetAssignment();
 
@@ -2341,6 +2343,30 @@ bool MipsAsmParser::parseSetNoMacroDirective() {
   return false;
 }
 
+bool MipsAsmParser::parseSetMips16Directive() {
+  Parser.Lex();
+  // If this is not the end of the statement, report an error.
+  if (getLexer().isNot(AsmToken::EndOfStatement)) {
+    reportParseError("unexpected token in statement");
+    return false;
+  }
+  getTargetStreamer().emitDirectiveSetMips16(true);
+  Parser.Lex(); // Consume the EndOfStatement.
+  return false;
+}
+
+bool MipsAsmParser::parseSetNoMips16Directive() {
+  Parser.Lex();
+  // If this is not the end of the statement, report an error.
+  if (getLexer().isNot(AsmToken::EndOfStatement)) {
+    reportParseError("unexpected token in statement");
+    return false;
+  }
+  // For now do nothing.
+  Parser.Lex(); // Consume the EndOfStatement.
+  return false;
+}
+
 bool MipsAsmParser::parseSetAssignment() {
   StringRef Name;
   const MCExpr *Value;
@@ -2382,10 +2408,10 @@ bool MipsAsmParser::parseDirectiveSet() {
     return parseSetMacroDirective();
   } else if (Tok.getString() == "nomacro") {
     return parseSetNoMacroDirective();
+  } else if (Tok.getString() == "mips16") {
+    return parseSetMips16Directive();
   } else if (Tok.getString() == "nomips16") {
-    // Ignore this directive for now.
-    Parser.eatToEndOfStatement();
-    return false;
+    return parseSetNoMips16Directive();
   } else if (Tok.getString() == "nomicromips") {
     getTargetStreamer().emitDirectiveSetNoMicroMips();
     Parser.eatToEndOfStatement();
index 909f9dc1596d160a2cae822056cecac874b1e506..786edf5d35f9e87a98a40c40938c1644654167d0 100644 (file)
@@ -63,6 +63,12 @@ void MipsTargetAsmStreamer::emitDirectiveAbiCalls() { OS << "\t.abicalls\n"; }
 void MipsTargetAsmStreamer::emitDirectiveOptionPic0() {
   OS << "\t.option\tpic0\n";
 }
+void MipsTargetAsmStreamer::emitDirectiveSetMips16(bool IsMips16) {
+  if (IsMips16)
+    OS << "\t.set\tmips16\n";
+  else
+    OS << "\t.set\tnomips16\n";
+}
 
 // This part is for ELF object output.
 MipsTargetELFStreamer::MipsTargetELFStreamer() : MicroMipsEnabled(false) {}
@@ -122,3 +128,13 @@ void MipsTargetELFStreamer::emitDirectiveOptionPic0() {
   Flags &= ~ELF::EF_MIPS_PIC;
   MCA.setELFHeaderEFlags(Flags);
 }
+void MipsTargetELFStreamer::emitDirectiveSetMips16(bool IsMips16) {
+  // Don't do anything for .set nomips16
+  if (!IsMips16)
+    return;
+
+  MCAssembler &MCA = getStreamer().getAssembler();
+  unsigned Flags = MCA.getELFHeaderEFlags();
+  Flags |= ELF::EF_MIPS_ARCH_ASE_M16;
+  MCA.setELFHeaderEFlags(Flags);
+}
index 4c0446fc3ced01e520b329b1440e1c1450bf8e0b..5b7591c80e708a3c1c1d91cb041f02fcb58b46e5 100644 (file)
@@ -26,6 +26,7 @@ public:
   virtual void emitDirectiveEnt(const MCSymbol &Symbol) = 0;
   virtual void emitDirectiveAbiCalls() = 0;
   virtual void emitDirectiveOptionPic0() = 0;
+  virtual void emitDirectiveSetMips16(bool IsMips16) = 0;
 };
 
 // This part is for ascii assembly output
@@ -42,11 +43,13 @@ public:
   virtual void emitDirectiveEnt(const MCSymbol &Symbol);
   virtual void emitDirectiveAbiCalls();
   virtual void emitDirectiveOptionPic0();
+  virtual void emitDirectiveSetMips16(bool IsMips16);
 };
 
 // This part is for ELF object output
 class MipsTargetELFStreamer : public MipsTargetStreamer {
   bool MicroMipsEnabled;
+
 public:
   bool isMicroMipsEnabled() const { return MicroMipsEnabled; }
   MCELFStreamer &getStreamer();
@@ -63,6 +66,7 @@ public:
   virtual void emitDirectiveEnt(const MCSymbol &Symbol);
   virtual void emitDirectiveAbiCalls();
   virtual void emitDirectiveOptionPic0();
+  virtual void emitDirectiveSetMips16(bool IsMips16);
 };
 }
 #endif
index c05772970a710e479f6e7783aef7d85c43e0db99..f459689bb92bc8bea1f35552d76291b1c04db524 100644 (file)
@@ -5,8 +5,11 @@
 
         .mips_hack_elf_flags 0x50001003
 
-// CHECK: Flags [ (0x50001005)
+// CHECK: Flags [ (0x54001005)
 
         .abicalls
 
         .option pic0
+ // Set EF_MIPS_ARCH_ASE_M16 (0x04000000)
+        .set mips16