• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/MCInst.h"
13 #include "llvm/MC/MCSymbolELF.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 
25   for (unsigned OpIndex = 0; OpIndex < Inst.getNumOperands(); ++OpIndex) {
26     const MCOperand &Op = Inst.getOperand(OpIndex);
27 
28     if (!Op.isReg())
29       continue;
30 
31     unsigned Reg = Op.getReg();
32     RegInfoRecord->SetPhysRegUsed(Reg, MCRegInfo);
33   }
34 
35   createPendingLabelRelocs();
36 }
37 
createPendingLabelRelocs()38 void MipsELFStreamer::createPendingLabelRelocs() {
39   MipsTargetELFStreamer *ELFTargetStreamer =
40       static_cast<MipsTargetELFStreamer *>(getTargetStreamer());
41 
42   // FIXME: Also mark labels when in MIPS16 mode.
43   if (ELFTargetStreamer->isMicroMipsEnabled()) {
44     for (auto *L : Labels) {
45       auto *Label = cast<MCSymbolELF>(L);
46       getAssembler().registerSymbol(*Label);
47       Label->setOther(ELF::STO_MIPS_MICROMIPS);
48     }
49   }
50 
51   Labels.clear();
52 }
53 
EmitLabel(MCSymbol * Symbol)54 void MipsELFStreamer::EmitLabel(MCSymbol *Symbol) {
55   MCELFStreamer::EmitLabel(Symbol);
56   Labels.push_back(Symbol);
57 }
58 
SwitchSection(MCSection * Section,const MCExpr * Subsection)59 void MipsELFStreamer::SwitchSection(MCSection *Section,
60                                     const MCExpr *Subsection) {
61   MCELFStreamer::SwitchSection(Section, Subsection);
62   Labels.clear();
63 }
64 
EmitValueImpl(const MCExpr * Value,unsigned Size,SMLoc Loc)65 void MipsELFStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size,
66                                     SMLoc Loc) {
67   MCELFStreamer::EmitValueImpl(Value, Size, Loc);
68   Labels.clear();
69 }
70 
EmitMipsOptionRecords()71 void MipsELFStreamer::EmitMipsOptionRecords() {
72   for (const auto &I : MipsOptionRecords)
73     I->EmitMipsOptionRecord();
74 }
75 
createMipsELFStreamer(MCContext & Context,MCAsmBackend & MAB,raw_pwrite_stream & OS,MCCodeEmitter * Emitter,bool RelaxAll)76 MCELFStreamer *llvm::createMipsELFStreamer(MCContext &Context,
77                                            MCAsmBackend &MAB,
78                                            raw_pwrite_stream &OS,
79                                            MCCodeEmitter *Emitter,
80                                            bool RelaxAll) {
81   return new MipsELFStreamer(Context, MAB, OS, Emitter);
82 }
83