From: Toma Tabacu Date: Fri, 6 Mar 2015 12:15:12 +0000 (+0000) Subject: [mips] [IAS] Add missing constraints and improve testing for the .module directive. X-Git-Tag: llvmorg-3.7.0-rc1~9975 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4e0cf8e21148ab9cb0dc22d5d00152c40f86af07;p=platform%2Fupstream%2Fllvm.git [mips] [IAS] Add missing constraints and improve testing for the .module directive. 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 llvm-svn: 231465 --- diff --git a/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp b/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp index f58ed56..51de707 100644 --- a/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp +++ b/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp @@ -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 X(TheMipsTarget); RegisterMCAsmParser Y(TheMipselTarget); diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp b/llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp index 64d7cab..babb2a8 100644 --- a/llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp +++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp @@ -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"; diff --git a/llvm/lib/Target/Mips/MipsTargetStreamer.h b/llvm/lib/Target/Mips/MipsTargetStreamer.h index b3b8296..88aca1a 100644 --- a/llvm/lib/Target/Mips/MipsTargetStreamer.h +++ b/llvm/lib/Target/Mips/MipsTargetStreamer.h @@ -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 diff --git a/llvm/test/MC/Mips/mips-abi-bad.s b/llvm/test/MC/Mips/mips-abi-bad.s index ba6564f..0e065bf 100644 --- a/llvm/test/MC/Mips/mips-abi-bad.s +++ b/llvm/test/MC/Mips/mips-abi-bad.s @@ -22,9 +22,3 @@ # 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/llvm/test/MC/Mips/module-directive-bad.s b/llvm/test/MC/Mips/module-directive-bad.s new file mode 100644 index 0000000..963d651 --- /dev/null +++ b/llvm/test/MC/Mips/module-directive-bad.s @@ -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