llvm.org GIT mirror llvm / 3c733ea
Replace .mips_hack_stocg with ".set micromips" and ".set nomicromips". This matches what gnu as does and implementing this is easier than arguing about it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199181 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 6 years ago
8 changed file(s) with 66 addition(s) and 60 deletion(s). Raw diff Collapse all Expand all
7070 public:
7171 virtual ~MCTargetStreamer();
7272 void setStreamer(MCStreamer *S) { Streamer = S; }
73
74 // Allow a target to add behavior to the EmitLabel of MCStreamer.
75 virtual void emitLabel(MCSymbol *Symbol);
7376 };
7477
7578 // FIXME: declared here because it is used from
2323
2424 // Pin the vtables to this file.
2525 MCTargetStreamer::~MCTargetStreamer() {}
26 void MCTargetStreamer::emitLabel(MCSymbol *Symbol) {}
2627 void ARMTargetStreamer::anchor() {}
2728
2829 MCStreamer::MCStreamer(MCContext &Ctx, MCTargetStreamer *TargetStreamer)
213214 assert(getCurrentSection().first && "Cannot emit before setting section!");
214215 AssignSection(Symbol, getCurrentSection().first);
215216 LastSymbol = Symbol;
217
218 MCTargetStreamer *TS = getTargetStreamer();
219 if (TS)
220 TS->emitLabel(Symbol);
216221 }
217222
218223 void MCStreamer::EmitDebugLabel(MCSymbol *Symbol) {
193193
194194 bool isEvaluated(const MCExpr *Expr);
195195 bool parseDirectiveSet();
196 bool parseDirectiveMipsHackStocg();
197196 bool parseDirectiveMipsHackELFFlags();
198197 bool parseDirectiveOption();
199198
23872386 Parser.eatToEndOfStatement();
23882387 return false;
23892388 } else if (Tok.getString() == "nomicromips") {
2390 // Ignore this directive for now.
2389 getTargetStreamer().emitDirectiveSetNoMicroMips();
2390 Parser.eatToEndOfStatement();
2391 return false;
2392 } else if (Tok.getString() == "micromips") {
2393 getTargetStreamer().emitDirectiveSetMicroMips();
23912394 Parser.eatToEndOfStatement();
23922395 return false;
23932396 } else {
23972400 }
23982401
23992402 return true;
2400 }
2401
2402 bool MipsAsmParser::parseDirectiveMipsHackStocg() {
2403 MCAsmParser &Parser = getParser();
2404 StringRef Name;
2405 if (Parser.parseIdentifier(Name))
2406 reportParseError("expected identifier");
2407
2408 MCSymbol *Sym = getContext().GetOrCreateSymbol(Name);
2409 if (getLexer().isNot(AsmToken::Comma)) {
2410 TokError("unexpected token");
2411 return false;
2412 }
2413 Lex();
2414
2415 int64_t Flags = 0;
2416 if (Parser.parseAbsoluteExpression(Flags)) {
2417 TokError("unexpected token");
2418 return false;
2419 }
2420
2421 getTargetStreamer().emitMipsHackSTOCG(Sym, Flags);
2422 return false;
24232403 }
24242404
24252405 bool MipsAsmParser::parseDirectiveMipsHackELFFlags() {
25512531 return false;
25522532 }
25532533
2554 if (IDVal == ".mips_hack_stocg")
2555 return parseDirectiveMipsHackStocg();
2556
25572534 if (IDVal == ".mips_hack_elf_flags")
25582535 return parseDirectiveMipsHackELFFlags();
25592536
3737 OS.write_hex(Flags);
3838 OS << '\n';
3939 }
40 void MipsTargetAsmStreamer::emitMipsHackSTOCG(MCSymbol *Sym, unsigned Val) {
41 if (!PrintHackDirectives)
42 return;
4340
44 OS << "\t.mips_hack_stocg ";
45 OS << Sym->getName();
46 OS << ", ";
47 OS << Val;
48 OS << '\n';
41 void MipsTargetAsmStreamer::emitDirectiveSetMicroMips() {
42 OS << "\t.set\tmicromips\n";
4943 }
44
45 void MipsTargetAsmStreamer::emitDirectiveSetNoMicroMips() {
46 OS << "\t.set\tnomicromips\n";
47 }
48
5049 void MipsTargetAsmStreamer::emitDirectiveAbiCalls() { OS << "\t.abicalls\n"; }
5150 void MipsTargetAsmStreamer::emitDirectiveOptionPic0() {
5251 OS << "\t.option\tpic0\n";
5453
5554 // This part is for ELF object output.
5655 MipsTargetELFStreamer::MipsTargetELFStreamer() {}
56
57 void MipsTargetELFStreamer::emitLabel(MCSymbol *Symbol) {
58 MCSymbolData &Data = getStreamer().getOrCreateSymbolData(Symbol);
59 // The "other" values are stored in the last 6 bits of the second byte
60 // The traditional defines for STO values assume the full byte and thus
61 // the shift to pack it.
62 if (isMicroMipsEnabled())
63 MCELF::setOther(Data, ELF::STO_MIPS_MICROMIPS >> 2);
64 }
5765
5866 MCELFStreamer &MipsTargetELFStreamer::getStreamer() {
5967 return static_cast(*Streamer);
6472 MCA.setELFHeaderEFlags(Flags);
6573 }
6674
67 // Set a symbol's STO flags.
68 void MipsTargetELFStreamer::emitMipsHackSTOCG(MCSymbol *Sym, unsigned Val) {
69 MCSymbolData &Data = getStreamer().getOrCreateSymbolData(Sym);
70 // The "other" values are stored in the last 6 bits of the second byte
71 // The traditional defines for STO values assume the full byte and thus
72 // the shift to pack it.
73 MCELF::setOther(Data, Val >> 2);
75 void MipsTargetELFStreamer::emitDirectiveSetMicroMips() {
76 MicroMipsEnabled = true;
7477 }
78
79 void MipsTargetELFStreamer::emitDirectiveSetNoMicroMips() {
80 MicroMipsEnabled = false;
81 }
82
7583 void MipsTargetELFStreamer::emitDirectiveAbiCalls() {
7684 MCAssembler &MCA = getStreamer().getAssembler();
7785 unsigned Flags = MCA.getELFHeaderEFlags();
264264 }
265265
266266 void MipsAsmPrinter::EmitFunctionEntryLabel() {
267 if (Subtarget->inMicroMipsMode())
268 getTargetStreamer().emitDirectiveSetMicroMips();
269
267270 if (OutStreamer.hasRawTextSupport()) {
268271 if (Subtarget->inMips16Mode())
269272 OutStreamer.EmitRawText(StringRef("\t.set\tmips16"));
274277 OutStreamer.EmitRawText("\t.ent\t" + Twine(CurrentFnSym->getName()));
275278 }
276279
277 if (Subtarget->inMicroMipsMode())
278 getTargetStreamer().emitMipsHackSTOCG(CurrentFnSym,
279 (unsigned)ELF::STO_MIPS_MICROMIPS);
280280 OutStreamer.EmitLabel(CurrentFnSym);
281281 }
282282
1818
1919 public:
2020 virtual void emitMipsHackELFFlags(unsigned Flags) = 0;
21 virtual void emitMipsHackSTOCG(MCSymbol *Sym, unsigned Val) = 0;
21 virtual void emitDirectiveSetMicroMips() = 0;
22 virtual void emitDirectiveSetNoMicroMips() = 0;
2223 virtual void emitDirectiveAbiCalls() = 0;
2324 virtual void emitDirectiveOptionPic0() = 0;
2425 };
3031 public:
3132 MipsTargetAsmStreamer(formatted_raw_ostream &OS);
3233 virtual void emitMipsHackELFFlags(unsigned Flags);
33 virtual void emitMipsHackSTOCG(MCSymbol *Sym, unsigned Val);
34 virtual void emitDirectiveSetMicroMips();
35 virtual void emitDirectiveSetNoMicroMips();
3436 virtual void emitDirectiveAbiCalls();
3537 virtual void emitDirectiveOptionPic0();
3638 };
3739
3840 // This part is for ELF object output
3941 class MipsTargetELFStreamer : public MipsTargetStreamer {
42 bool MicroMipsEnabled;
4043 public:
44 bool isMicroMipsEnabled() const { return MicroMipsEnabled; }
4145 MCELFStreamer &getStreamer();
4246 MipsTargetELFStreamer();
47
48 virtual void emitLabel(MCSymbol *Symbol) LLVM_OVERRIDE;
49
4350 // FIXME: emitMipsHackELFFlags() will be removed from this class.
4451 virtual void emitMipsHackELFFlags(unsigned Flags);
45 virtual void emitMipsHackSTOCG(MCSymbol *Sym, unsigned Val);
52 virtual void emitDirectiveSetMicroMips();
53 virtual void emitDirectiveSetNoMicroMips();
4654 virtual void emitDirectiveAbiCalls();
4755 virtual void emitDirectiveOptionPic0();
4856 };
77 ret i32 0
88 }
99
10 ; CHECK: .mips_hack_stocg main, 128
10 ; CHECK: .set micromips
11 ; CHECK: main:
0 // RUN: llvm-mc -filetype=obj -triple mipsel-unknown-linux %s -o -| llvm-readobj -t | FileCheck %s
11
2 .text
3 .globl main
4 .align 2
5 .type main,@function
6 .set nomips16 # @main
7 .ent main
8 .mips_hack_stocg main, 128
9 main:
102
11 // CHECK: Name: main
12 // CHECK: Other: 128
3 .globl f1
4 .set micromips
5 f1:
6 nop
7
8 .globl f2
9 .set nomicromips
10 f2:
11 nop
12
13 // CHECK-LABEL: Name: f1
14 // CHECK: Other: 128
15 // CHECK-LABEL: Name: f2
16 // CHECK: Other: 0