[mips] [IAS] Add missing constraints and improve testing for the .module directive.
authorToma Tabacu <toma.tabacu@imgtec.com>
Fri, 6 Mar 2015 12:15:12 +0000 (12:15 +0000)
committerToma Tabacu <toma.tabacu@imgtec.com>
Fri, 6 Mar 2015 12:15:12 +0000 (12:15 +0000)
Summary:
None of the .set directives can be used before the .module directives. The .set mips0/pop/push were not triggering this constraint.
Also added testing for all the other implemented directives which are supposed to trigger this constraint.

Reviewers: dsanders

Reviewed By: dsanders

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D7140

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@231465 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/mips-abi-bad.s
test/MC/Mips/module-directive-bad.s [new file with mode: 0644]

index f58ed56562725068be891c6c5ebcc8323c6bee42..51de707d949aa7ccecaef3b568a64d1bc499d5c3 100644 (file)
@@ -236,6 +236,8 @@ class MipsAsmParser : public MCTargetAsmParser {
   bool parseFpABIValue(MipsABIFlagsSection::FpABIKind &FpABI,
                        StringRef Directive);
 
+  bool parseInternalDirectiveReallowModule();
+
   MCSymbolRefExpr::VariantKind getVariantKind(StringRef Symbol);
 
   bool eatComma(StringRef ErrorStr);
@@ -4429,9 +4431,25 @@ bool MipsAsmParser::ParseDirective(AsmToken DirectiveID) {
   if (IDVal == ".module")
     return parseDirectiveModule();
 
+  if (IDVal == ".llvm_internal_mips_reallow_module_directive")
+    return parseInternalDirectiveReallowModule();
+
   return true;
 }
 
+bool MipsAsmParser::parseInternalDirectiveReallowModule() {
+  // If this is not the end of the statement, report an error.
+  if (getLexer().isNot(AsmToken::EndOfStatement)) {
+    reportParseError("unexpected token, expected end of statement");
+    return false;
+  }
+
+  getTargetStreamer().reallowModuleDirective();
+
+  getParser().Lex(); // Eat EndOfStatement token.
+  return false;
+}
+
 extern "C" void LLVMInitializeMipsAsmParser() {
   RegisterMCAsmParser<MipsAsmParser> X(TheMipsTarget);
   RegisterMCAsmParser<MipsAsmParser> Y(TheMipselTarget);
index 64d7cab4d7c2cc6cb1836276451a05be474a49d9..babb2a8425745c8d91a67a681f22faca442e0415 100644 (file)
@@ -62,7 +62,7 @@ void MipsTargetStreamer::emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff) {
 void MipsTargetStreamer::emitDirectiveSetArch(StringRef Arch) {
   forbidModuleDirective();
 }
-void MipsTargetStreamer::emitDirectiveSetMips0() {}
+void MipsTargetStreamer::emitDirectiveSetMips0() { forbidModuleDirective(); }
 void MipsTargetStreamer::emitDirectiveSetMips1() { forbidModuleDirective(); }
 void MipsTargetStreamer::emitDirectiveSetMips2() { forbidModuleDirective(); }
 void MipsTargetStreamer::emitDirectiveSetMips3() { forbidModuleDirective(); }
@@ -78,8 +78,8 @@ void MipsTargetStreamer::emitDirectiveSetMips64R2() { forbidModuleDirective(); }
 void MipsTargetStreamer::emitDirectiveSetMips64R3() { forbidModuleDirective(); }
 void MipsTargetStreamer::emitDirectiveSetMips64R5() { forbidModuleDirective(); }
 void MipsTargetStreamer::emitDirectiveSetMips64R6() { forbidModuleDirective(); }
-void MipsTargetStreamer::emitDirectiveSetPop() {}
-void MipsTargetStreamer::emitDirectiveSetPush() {}
+void MipsTargetStreamer::emitDirectiveSetPop() { forbidModuleDirective(); }
+void MipsTargetStreamer::emitDirectiveSetPush() { forbidModuleDirective(); }
 void MipsTargetStreamer::emitDirectiveSetDsp() { forbidModuleDirective(); }
 void MipsTargetStreamer::emitDirectiveSetNoDsp() { forbidModuleDirective(); }
 void MipsTargetStreamer::emitDirectiveCpLoad(unsigned RegNo) {}
@@ -91,6 +91,10 @@ void MipsTargetStreamer::emitDirectiveModuleOddSPReg(bool Enabled,
   if (!Enabled && !IsO32ABI)
     report_fatal_error("+nooddspreg is only valid for O32");
 }
+void MipsTargetStreamer::emitDirectiveSetFp(
+    MipsABIFlagsSection::FpABIKind Value) {
+  forbidModuleDirective();
+}
 
 MipsTargetAsmStreamer::MipsTargetAsmStreamer(MCStreamer &S,
                                              formatted_raw_ostream &OS)
@@ -198,7 +202,10 @@ void MipsTargetAsmStreamer::emitDirectiveSetArch(StringRef Arch) {
   MipsTargetStreamer::emitDirectiveSetArch(Arch);
 }
 
-void MipsTargetAsmStreamer::emitDirectiveSetMips0() { OS << "\t.set\tmips0\n"; }
+void MipsTargetAsmStreamer::emitDirectiveSetMips0() {
+  OS << "\t.set\tmips0\n";
+  MipsTargetStreamer::emitDirectiveSetMips0();
+}
 
 void MipsTargetAsmStreamer::emitDirectiveSetMips1() {
   OS << "\t.set\tmips1\n";
@@ -285,9 +292,15 @@ void MipsTargetAsmStreamer::emitDirectiveSetNoDsp() {
   MipsTargetStreamer::emitDirectiveSetNoDsp();
 }
 
-void MipsTargetAsmStreamer::emitDirectiveSetPop() { OS << "\t.set\tpop\n"; }
+void MipsTargetAsmStreamer::emitDirectiveSetPop() {
+  OS << "\t.set\tpop\n";
+  MipsTargetStreamer::emitDirectiveSetPop();
+}
 
-void MipsTargetAsmStreamer::emitDirectiveSetPush() { OS << "\t.set\tpush\n"; }
+void MipsTargetAsmStreamer::emitDirectiveSetPush() {
+ OS << "\t.set\tpush\n";
+ MipsTargetStreamer::emitDirectiveSetPush();
+}
 
 // Print a 32 bit hex number with all numbers.
 static void printHex32(unsigned Value, raw_ostream &OS) {
@@ -346,6 +359,8 @@ void MipsTargetAsmStreamer::emitDirectiveModuleFP(
 
 void MipsTargetAsmStreamer::emitDirectiveSetFp(
     MipsABIFlagsSection::FpABIKind Value) {
+  MipsTargetStreamer::emitDirectiveSetFp(Value);
+
   StringRef ModuleValue;
   OS << "\t.set\tfp=";
   OS << ABIFlagsSection.getFpABIString(Value) << "\n";
index b3b829623fafdd0f45f5e0aa6760e8564252dc98..88aca1ad893d80efb95d74cd50e1d84f5e12c453 100644 (file)
@@ -92,9 +92,10 @@ public:
   }
 
   virtual void emitDirectiveModuleOddSPReg(bool Enabled, bool IsO32ABI);
-  virtual void emitDirectiveSetFp(MipsABIFlagsSection::FpABIKind Value){};
+  virtual void emitDirectiveSetFp(MipsABIFlagsSection::FpABIKind Value);
   virtual void emitMipsAbiFlags(){};
   void forbidModuleDirective() { ModuleDirectiveAllowed = false; }
+  void reallowModuleDirective() { ModuleDirectiveAllowed = true; }
   bool isModuleDirectiveAllowed() { return ModuleDirectiveAllowed; }
 
   // This method enables template classes to set internal abi flags
index ba6564fb7e1b226bd0b4f56efa9136601474610b..0e065bfba7080a1bf0b8e5804bfd7c1dbe3001c3 100644 (file)
     .module 34
 # CHECK: :[[@LINE-1]]:13: error: expected .module option identifier
 # CHECK-NEXT: .module 34
-# CHECK-NEXT:         ^
-
-    .set mips16
-    .module fp=32
-# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
-# CHECK-NEXT: .module fp=32
 # CHECK-NEXT:         ^
diff --git a/test/MC/Mips/module-directive-bad.s b/test/MC/Mips/module-directive-bad.s
new file mode 100644 (file)
index 0000000..963d651
--- /dev/null
@@ -0,0 +1,262 @@
+# RUN: not llvm-mc -triple mips-unknown-unknown %s 2>%t1
+# RUN: FileCheck %s < %t1
+
+    .set mips0
+    .module fp=64
+# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .llvm_internal_mips_reallow_module_directive
+    .module fp=32
+# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .set mips1
+    .module fp=64
+# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .llvm_internal_mips_reallow_module_directive
+    .module fp=32
+# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .set mips2
+    .module fp=64
+# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .llvm_internal_mips_reallow_module_directive
+    .module fp=32
+# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .set mips3
+    .module fp=64
+# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .llvm_internal_mips_reallow_module_directive
+    .module fp=32
+# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .set mips4
+    .module fp=64
+# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .llvm_internal_mips_reallow_module_directive
+    .module fp=32
+# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .set mips5
+    .module fp=64
+# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .llvm_internal_mips_reallow_module_directive
+    .module fp=32
+# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .set mips32
+    .module fp=64
+# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .llvm_internal_mips_reallow_module_directive
+    .module fp=32
+# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .set mips32r2
+    .module fp=64
+# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .llvm_internal_mips_reallow_module_directive
+    .module fp=32
+# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .set mips32r6
+    .module fp=64
+# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .llvm_internal_mips_reallow_module_directive
+    .module fp=32
+# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .set mips64
+    .module fp=64
+# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .llvm_internal_mips_reallow_module_directive
+    .module fp=32
+# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .set mips64r2
+    .module fp=64
+# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .llvm_internal_mips_reallow_module_directive
+    .module fp=32
+# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .set mips64r6
+    .module fp=64
+# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .llvm_internal_mips_reallow_module_directive
+    .module fp=32
+# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .set arch=mips32
+    .module fp=64
+# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .llvm_internal_mips_reallow_module_directive
+    .module fp=32
+# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .set mips16
+    .module fp=64
+# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .llvm_internal_mips_reallow_module_directive
+    .module fp=32
+# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .set nomips16
+    .module fp=64
+# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .llvm_internal_mips_reallow_module_directive
+    .module fp=32
+# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .set micromips
+    .module fp=64
+# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .llvm_internal_mips_reallow_module_directive
+    .module fp=32
+# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .set nomicromips
+    .module fp=64
+# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .llvm_internal_mips_reallow_module_directive
+    .module fp=32
+# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .set msa
+    .module fp=64
+# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .llvm_internal_mips_reallow_module_directive
+    .module fp=32
+# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .set nomsa
+    .module fp=64
+# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .llvm_internal_mips_reallow_module_directive
+    .module fp=32
+# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .set dsp
+    .module fp=64
+# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .llvm_internal_mips_reallow_module_directive
+    .module fp=32
+# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .set nodsp
+    .module fp=64
+# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .llvm_internal_mips_reallow_module_directive
+    .module fp=32
+# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .set push
+    .module fp=64
+# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .llvm_internal_mips_reallow_module_directive
+    .module fp=32
+# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .set pop
+    .module fp=64
+# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .llvm_internal_mips_reallow_module_directive
+    .module fp=32
+# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .set reorder
+    .module fp=64
+# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .llvm_internal_mips_reallow_module_directive
+    .module fp=32
+# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .set noreorder
+    .module fp=64
+# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .llvm_internal_mips_reallow_module_directive
+    .module fp=32
+# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .set macro
+    .module fp=64
+# FIXME: emitDirectiveSetMacro should call forbidModuleDirective().
+
+    .llvm_internal_mips_reallow_module_directive
+    .module fp=32
+# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .set nomacro
+    .module fp=64
+# FIXME: emitDirectiveSetNoMacro should call forbidModuleDirective().
+
+    .llvm_internal_mips_reallow_module_directive
+    .module fp=32
+# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .set at
+    .module fp=64
+# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .llvm_internal_mips_reallow_module_directive
+    .module fp=32
+# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .set at=$3
+    .module fp=64
+# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .llvm_internal_mips_reallow_module_directive
+    .module fp=32
+# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .set noat
+    .module fp=64
+# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .llvm_internal_mips_reallow_module_directive
+    .module fp=32
+# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .set fp=32
+    .module fp=64
+# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .llvm_internal_mips_reallow_module_directive
+    .module fp=32
+# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .cpload $25
+    .module fp=64
+# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .llvm_internal_mips_reallow_module_directive
+    .module fp=32
+# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
+
+    .cpsetup $25, 8, __cerror
+    .module fp=64
+# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code