93f60dfb083e1598d33143d9c6c19d24e40ffff1
[oota-llvm.git] / lib / Target / Mips / MCTargetDesc / MipsELFStreamer.cpp
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
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
50 void MipsELFStreamer::EmitLabel(MCSymbol *Symbol) {
51   MCELFStreamer::EmitLabel(Symbol);
52   Labels.push_back(Symbol);
53 }
54
55 void MipsELFStreamer::SwitchSection(const MCSection * Section,
56                                     const MCExpr *Subsection) {
57   MCELFStreamer::SwitchSection(Section, Subsection);
58   Labels.clear();
59 }
60
61 void MipsELFStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size,
62                                     const SMLoc &Loc) {
63   MCELFStreamer::EmitValueImpl(Value, Size, Loc);
64   Labels.clear();
65 }
66
67 void MipsELFStreamer::EmitMipsOptionRecords() {
68   for (const auto &I : MipsOptionRecords)
69     I->EmitMipsOptionRecord();
70 }
71
72 MCELFStreamer *llvm::createMipsELFStreamer(MCContext &Context,
73                                            MCAsmBackend &MAB, raw_ostream &OS,
74                                            MCCodeEmitter *Emitter,
75                                            bool RelaxAll) {
76   return new MipsELFStreamer(Context, MAB, OS, Emitter);
77 }