Skip to content

Commit 4e0cf8e

Browse files
author
Toma Tabacu
committedMar 6, 2015
[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
1 parent 98f8ae3 commit 4e0cf8e

File tree

5 files changed

+303
-13
lines changed

5 files changed

+303
-13
lines changed
 

‎llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@ class MipsAsmParser : public MCTargetAsmParser {
236236
bool parseFpABIValue(MipsABIFlagsSection::FpABIKind &FpABI,
237237
StringRef Directive);
238238

239+
bool parseInternalDirectiveReallowModule();
240+
239241
MCSymbolRefExpr::VariantKind getVariantKind(StringRef Symbol);
240242

241243
bool eatComma(StringRef ErrorStr);
@@ -4429,9 +4431,25 @@ bool MipsAsmParser::ParseDirective(AsmToken DirectiveID) {
44294431
if (IDVal == ".module")
44304432
return parseDirectiveModule();
44314433

4434+
if (IDVal == ".llvm_internal_mips_reallow_module_directive")
4435+
return parseInternalDirectiveReallowModule();
4436+
44324437
return true;
44334438
}
44344439

4440+
bool MipsAsmParser::parseInternalDirectiveReallowModule() {
4441+
// If this is not the end of the statement, report an error.
4442+
if (getLexer().isNot(AsmToken::EndOfStatement)) {
4443+
reportParseError("unexpected token, expected end of statement");
4444+
return false;
4445+
}
4446+
4447+
getTargetStreamer().reallowModuleDirective();
4448+
4449+
getParser().Lex(); // Eat EndOfStatement token.
4450+
return false;
4451+
}
4452+
44354453
extern "C" void LLVMInitializeMipsAsmParser() {
44364454
RegisterMCAsmParser<MipsAsmParser> X(TheMipsTarget);
44374455
RegisterMCAsmParser<MipsAsmParser> Y(TheMipselTarget);

‎llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp

+21-6
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void MipsTargetStreamer::emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff) {
6262
void MipsTargetStreamer::emitDirectiveSetArch(StringRef Arch) {
6363
forbidModuleDirective();
6464
}
65-
void MipsTargetStreamer::emitDirectiveSetMips0() {}
65+
void MipsTargetStreamer::emitDirectiveSetMips0() { forbidModuleDirective(); }
6666
void MipsTargetStreamer::emitDirectiveSetMips1() { forbidModuleDirective(); }
6767
void MipsTargetStreamer::emitDirectiveSetMips2() { forbidModuleDirective(); }
6868
void MipsTargetStreamer::emitDirectiveSetMips3() { forbidModuleDirective(); }
@@ -78,8 +78,8 @@ void MipsTargetStreamer::emitDirectiveSetMips64R2() { forbidModuleDirective(); }
7878
void MipsTargetStreamer::emitDirectiveSetMips64R3() { forbidModuleDirective(); }
7979
void MipsTargetStreamer::emitDirectiveSetMips64R5() { forbidModuleDirective(); }
8080
void MipsTargetStreamer::emitDirectiveSetMips64R6() { forbidModuleDirective(); }
81-
void MipsTargetStreamer::emitDirectiveSetPop() {}
82-
void MipsTargetStreamer::emitDirectiveSetPush() {}
81+
void MipsTargetStreamer::emitDirectiveSetPop() { forbidModuleDirective(); }
82+
void MipsTargetStreamer::emitDirectiveSetPush() { forbidModuleDirective(); }
8383
void MipsTargetStreamer::emitDirectiveSetDsp() { forbidModuleDirective(); }
8484
void MipsTargetStreamer::emitDirectiveSetNoDsp() { forbidModuleDirective(); }
8585
void MipsTargetStreamer::emitDirectiveCpLoad(unsigned RegNo) {}
@@ -91,6 +91,10 @@ void MipsTargetStreamer::emitDirectiveModuleOddSPReg(bool Enabled,
9191
if (!Enabled && !IsO32ABI)
9292
report_fatal_error("+nooddspreg is only valid for O32");
9393
}
94+
void MipsTargetStreamer::emitDirectiveSetFp(
95+
MipsABIFlagsSection::FpABIKind Value) {
96+
forbidModuleDirective();
97+
}
9498

9599
MipsTargetAsmStreamer::MipsTargetAsmStreamer(MCStreamer &S,
96100
formatted_raw_ostream &OS)
@@ -198,7 +202,10 @@ void MipsTargetAsmStreamer::emitDirectiveSetArch(StringRef Arch) {
198202
MipsTargetStreamer::emitDirectiveSetArch(Arch);
199203
}
200204

201-
void MipsTargetAsmStreamer::emitDirectiveSetMips0() { OS << "\t.set\tmips0\n"; }
205+
void MipsTargetAsmStreamer::emitDirectiveSetMips0() {
206+
OS << "\t.set\tmips0\n";
207+
MipsTargetStreamer::emitDirectiveSetMips0();
208+
}
202209

203210
void MipsTargetAsmStreamer::emitDirectiveSetMips1() {
204211
OS << "\t.set\tmips1\n";
@@ -285,9 +292,15 @@ void MipsTargetAsmStreamer::emitDirectiveSetNoDsp() {
285292
MipsTargetStreamer::emitDirectiveSetNoDsp();
286293
}
287294

288-
void MipsTargetAsmStreamer::emitDirectiveSetPop() { OS << "\t.set\tpop\n"; }
295+
void MipsTargetAsmStreamer::emitDirectiveSetPop() {
296+
OS << "\t.set\tpop\n";
297+
MipsTargetStreamer::emitDirectiveSetPop();
298+
}
289299

290-
void MipsTargetAsmStreamer::emitDirectiveSetPush() { OS << "\t.set\tpush\n"; }
300+
void MipsTargetAsmStreamer::emitDirectiveSetPush() {
301+
OS << "\t.set\tpush\n";
302+
MipsTargetStreamer::emitDirectiveSetPush();
303+
}
291304

292305
// Print a 32 bit hex number with all numbers.
293306
static void printHex32(unsigned Value, raw_ostream &OS) {
@@ -346,6 +359,8 @@ void MipsTargetAsmStreamer::emitDirectiveModuleFP(
346359

347360
void MipsTargetAsmStreamer::emitDirectiveSetFp(
348361
MipsABIFlagsSection::FpABIKind Value) {
362+
MipsTargetStreamer::emitDirectiveSetFp(Value);
363+
349364
StringRef ModuleValue;
350365
OS << "\t.set\tfp=";
351366
OS << ABIFlagsSection.getFpABIString(Value) << "\n";

‎llvm/lib/Target/Mips/MipsTargetStreamer.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,10 @@ class MipsTargetStreamer : public MCTargetStreamer {
9292
}
9393

9494
virtual void emitDirectiveModuleOddSPReg(bool Enabled, bool IsO32ABI);
95-
virtual void emitDirectiveSetFp(MipsABIFlagsSection::FpABIKind Value){};
95+
virtual void emitDirectiveSetFp(MipsABIFlagsSection::FpABIKind Value);
9696
virtual void emitMipsAbiFlags(){};
9797
void forbidModuleDirective() { ModuleDirectiveAllowed = false; }
98+
void reallowModuleDirective() { ModuleDirectiveAllowed = true; }
9899
bool isModuleDirectiveAllowed() { return ModuleDirectiveAllowed; }
99100

100101
// This method enables template classes to set internal abi flags

‎llvm/test/MC/Mips/mips-abi-bad.s

-6
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,4 @@
2121
.module 34
2222
# CHECK: :[[@LINE-1]]:13: error: expected .module option identifier
2323
# CHECK-NEXT: .module 34
24-
# CHECK-NEXT: ^
25-
26-
.set mips16
27-
.module fp=32
28-
# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
29-
# CHECK-NEXT: .module fp=32
3024
# CHECK-NEXT: ^
+262
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,262 @@
1+
# RUN: not llvm-mc -triple mips-unknown-unknown %s 2>%t1
2+
# RUN: FileCheck %s < %t1
3+
4+
.set mips0
5+
.module fp=64
6+
# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
7+
8+
.llvm_internal_mips_reallow_module_directive
9+
.module fp=32
10+
# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
11+
12+
.set mips1
13+
.module fp=64
14+
# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
15+
16+
.llvm_internal_mips_reallow_module_directive
17+
.module fp=32
18+
# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
19+
20+
.set mips2
21+
.module fp=64
22+
# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
23+
24+
.llvm_internal_mips_reallow_module_directive
25+
.module fp=32
26+
# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
27+
28+
.set mips3
29+
.module fp=64
30+
# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
31+
32+
.llvm_internal_mips_reallow_module_directive
33+
.module fp=32
34+
# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
35+
36+
.set mips4
37+
.module fp=64
38+
# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
39+
40+
.llvm_internal_mips_reallow_module_directive
41+
.module fp=32
42+
# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
43+
44+
.set mips5
45+
.module fp=64
46+
# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
47+
48+
.llvm_internal_mips_reallow_module_directive
49+
.module fp=32
50+
# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
51+
52+
.set mips32
53+
.module fp=64
54+
# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
55+
56+
.llvm_internal_mips_reallow_module_directive
57+
.module fp=32
58+
# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
59+
60+
.set mips32r2
61+
.module fp=64
62+
# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
63+
64+
.llvm_internal_mips_reallow_module_directive
65+
.module fp=32
66+
# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
67+
68+
.set mips32r6
69+
.module fp=64
70+
# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
71+
72+
.llvm_internal_mips_reallow_module_directive
73+
.module fp=32
74+
# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
75+
76+
.set mips64
77+
.module fp=64
78+
# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
79+
80+
.llvm_internal_mips_reallow_module_directive
81+
.module fp=32
82+
# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
83+
84+
.set mips64r2
85+
.module fp=64
86+
# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
87+
88+
.llvm_internal_mips_reallow_module_directive
89+
.module fp=32
90+
# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
91+
92+
.set mips64r6
93+
.module fp=64
94+
# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
95+
96+
.llvm_internal_mips_reallow_module_directive
97+
.module fp=32
98+
# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
99+
100+
.set arch=mips32
101+
.module fp=64
102+
# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
103+
104+
.llvm_internal_mips_reallow_module_directive
105+
.module fp=32
106+
# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
107+
108+
.set mips16
109+
.module fp=64
110+
# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
111+
112+
.llvm_internal_mips_reallow_module_directive
113+
.module fp=32
114+
# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
115+
116+
.set nomips16
117+
.module fp=64
118+
# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
119+
120+
.llvm_internal_mips_reallow_module_directive
121+
.module fp=32
122+
# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
123+
124+
.set micromips
125+
.module fp=64
126+
# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
127+
128+
.llvm_internal_mips_reallow_module_directive
129+
.module fp=32
130+
# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
131+
132+
.set nomicromips
133+
.module fp=64
134+
# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
135+
136+
.llvm_internal_mips_reallow_module_directive
137+
.module fp=32
138+
# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
139+
140+
.set msa
141+
.module fp=64
142+
# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
143+
144+
.llvm_internal_mips_reallow_module_directive
145+
.module fp=32
146+
# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
147+
148+
.set nomsa
149+
.module fp=64
150+
# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
151+
152+
.llvm_internal_mips_reallow_module_directive
153+
.module fp=32
154+
# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
155+
156+
.set dsp
157+
.module fp=64
158+
# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
159+
160+
.llvm_internal_mips_reallow_module_directive
161+
.module fp=32
162+
# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
163+
164+
.set nodsp
165+
.module fp=64
166+
# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
167+
168+
.llvm_internal_mips_reallow_module_directive
169+
.module fp=32
170+
# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
171+
172+
.set push
173+
.module fp=64
174+
# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
175+
176+
.llvm_internal_mips_reallow_module_directive
177+
.module fp=32
178+
# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
179+
180+
.set pop
181+
.module fp=64
182+
# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
183+
184+
.llvm_internal_mips_reallow_module_directive
185+
.module fp=32
186+
# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
187+
188+
.set reorder
189+
.module fp=64
190+
# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
191+
192+
.llvm_internal_mips_reallow_module_directive
193+
.module fp=32
194+
# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
195+
196+
.set noreorder
197+
.module fp=64
198+
# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
199+
200+
.llvm_internal_mips_reallow_module_directive
201+
.module fp=32
202+
# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
203+
204+
.set macro
205+
.module fp=64
206+
# FIXME: emitDirectiveSetMacro should call forbidModuleDirective().
207+
208+
.llvm_internal_mips_reallow_module_directive
209+
.module fp=32
210+
# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
211+
212+
.set nomacro
213+
.module fp=64
214+
# FIXME: emitDirectiveSetNoMacro should call forbidModuleDirective().
215+
216+
.llvm_internal_mips_reallow_module_directive
217+
.module fp=32
218+
# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
219+
220+
.set at
221+
.module fp=64
222+
# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
223+
224+
.llvm_internal_mips_reallow_module_directive
225+
.module fp=32
226+
# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
227+
228+
.set at=$3
229+
.module fp=64
230+
# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
231+
232+
.llvm_internal_mips_reallow_module_directive
233+
.module fp=32
234+
# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
235+
236+
.set noat
237+
.module fp=64
238+
# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
239+
240+
.llvm_internal_mips_reallow_module_directive
241+
.module fp=32
242+
# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
243+
244+
.set fp=32
245+
.module fp=64
246+
# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
247+
248+
.llvm_internal_mips_reallow_module_directive
249+
.module fp=32
250+
# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
251+
252+
.cpload $25
253+
.module fp=64
254+
# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code
255+
256+
.llvm_internal_mips_reallow_module_directive
257+
.module fp=32
258+
# CHECK-NOT: :[[@LINE-1]]:13: error: .module directive must appear before any code
259+
260+
.cpsetup $25, 8, __cerror
261+
.module fp=64
262+
# CHECK: :[[@LINE-1]]:13: error: .module directive must appear before any code

0 commit comments

Comments
 (0)
Please sign in to comment.