1 //===-------- MipsELFStreamer.cpp - ELF Object Output ---------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "MipsELFStreamer.h"
11 #include "MipsTargetStreamer.h"
12 #include "llvm/MC/MCELF.h"
13 #include "llvm/MC/MCInst.h"
14 #include "llvm/Support/ELF.h"
15
16 using namespace llvm;
17
EmitInstruction(const MCInst & Inst,const MCSubtargetInfo & STI)18 void MipsELFStreamer::EmitInstruction(const MCInst &Inst,
19 const MCSubtargetInfo &STI) {
20 MCELFStreamer::EmitInstruction(Inst, STI);
21
22 MCContext &Context = getContext();
23 const MCRegisterInfo *MCRegInfo = Context.getRegisterInfo();
24 MipsTargetELFStreamer *ELFTargetStreamer =
25 static_cast<MipsTargetELFStreamer *>(getTargetStreamer());
26
27 for (unsigned OpIndex = 0; OpIndex < Inst.getNumOperands(); ++OpIndex) {
28 const MCOperand &Op = Inst.getOperand(OpIndex);
29
30 if (!Op.isReg())
31 continue;
32
33 unsigned Reg = Op.getReg();
34 RegInfoRecord->SetPhysRegUsed(Reg, MCRegInfo);
35 }
36
37 if (ELFTargetStreamer->isMicroMipsEnabled()) {
38 for (auto Label : Labels) {
39 MCSymbolData &Data = getOrCreateSymbolData(Label);
40 // The "other" values are stored in the last 6 bits of the second byte.
41 // The traditional defines for STO values assume the full byte and thus
42 // the shift to pack it.
43 MCELF::setOther(Data, ELF::STO_MIPS_MICROMIPS >> 2);
44 }
45 }
46
47 Labels.clear();
48 }
49
EmitLabel(MCSymbol * Symbol)50 void MipsELFStreamer::EmitLabel(MCSymbol *Symbol) {
51 MCELFStreamer::EmitLabel(Symbol);
52 Labels.push_back(Symbol);
53 }
54
SwitchSection(const MCSection * Section,const MCExpr * Subsection)55 void MipsELFStreamer::SwitchSection(const MCSection * Section,
56 const MCExpr *Subsection) {
57 MCELFStreamer::SwitchSection(Section, Subsection);
58 Labels.clear();
59 }
60
EmitValueImpl(const MCExpr * Value,unsigned Size,const SMLoc & Loc)61 void MipsELFStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size,
62 const SMLoc &Loc) {
63 MCELFStreamer::EmitValueImpl(Value, Size, Loc);
64 Labels.clear();
65 }
66
EmitMipsOptionRecords()67 void MipsELFStreamer::EmitMipsOptionRecords() {
68 for (const auto &I : MipsOptionRecords)
69 I->EmitMipsOptionRecord();
70 }
71
72 namespace llvm {
createMipsELFStreamer(MCContext & Context,MCAsmBackend & MAB,raw_ostream & OS,MCCodeEmitter * Emitter,const MCSubtargetInfo & STI,bool RelaxAll)73 MCELFStreamer *createMipsELFStreamer(MCContext &Context, MCAsmBackend &MAB,
74 raw_ostream &OS, MCCodeEmitter *Emitter,
75 const MCSubtargetInfo &STI,
76 bool RelaxAll) {
77 return new MipsELFStreamer(Context, MAB, OS, Emitter, STI);
78 }
79 }
80