Skip to content

Commit

Permalink
[mips] [IAS] Add missing constraints and improve testing for the .mod…
Browse files Browse the repository at this point in the history
…ule 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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@231465 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
Toma Tabacu committed Mar 6, 2015
1 parent 90e6a21 commit 25c2850
Show file tree
Hide file tree
Showing 5 changed files with 303 additions and 13 deletions.
18 changes: 18 additions & 0 deletions lib/Target/Mips/AsmParser/MipsAsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
27 changes: 21 additions & 6 deletions lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }
Expand All @@ -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) {}
Expand All @@ -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)
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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";
Expand Down
3 changes: 2 additions & 1 deletion lib/Target/Mips/MipsTargetStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ class MipsTargetStreamer : public MCTargetStreamer {
}

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
Expand Down
6 changes: 0 additions & 6 deletions test/MC/Mips/mips-abi-bad.s
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,4 @@
.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: ^
262 changes: 262 additions & 0 deletions test/MC/Mips/module-directive-bad.s
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 25c2850

Please sign in to comment.