1 //===-------- MipsELFStreamer.cpp - ELF Object Output ---------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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"
18 void MipsELFStreamer::EmitInstruction(const MCInst &Inst,
19 const MCSubtargetInfo &STI) {
20 MCELFStreamer::EmitInstruction(Inst, STI);
22 MCContext &Context = getContext();
23 const MCRegisterInfo *MCRegInfo = Context.getRegisterInfo();
25 for (unsigned OpIndex = 0; OpIndex < Inst.getNumOperands(); ++OpIndex) {
26 const MCOperand &Op = Inst.getOperand(OpIndex);
31 unsigned Reg = Op.getReg();
32 RegInfoRecord->SetPhysRegUsed(Reg, MCRegInfo);
35 createPendingLabelRelocs();
38 void MipsELFStreamer::createPendingLabelRelocs() {
39 MipsTargetELFStreamer *ELFTargetStreamer =
40 static_cast<MipsTargetELFStreamer *>(getTargetStreamer());
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 getOrCreateSymbolData(Label);
47 // The "other" values are stored in the last 6 bits of the second byte.
48 // The traditional defines for STO values assume the full byte and thus
49 // the shift to pack it.
50 Label->setOther(ELF::STO_MIPS_MICROMIPS >> 2);
57 void MipsELFStreamer::EmitLabel(MCSymbol *Symbol) {
58 MCELFStreamer::EmitLabel(Symbol);
59 Labels.push_back(Symbol);
62 void MipsELFStreamer::SwitchSection(MCSection *Section,
63 const MCExpr *Subsection) {
64 MCELFStreamer::SwitchSection(Section, Subsection);
68 void MipsELFStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size,
70 MCELFStreamer::EmitValueImpl(Value, Size, Loc);
74 void MipsELFStreamer::EmitMipsOptionRecords() {
75 for (const auto &I : MipsOptionRecords)
76 I->EmitMipsOptionRecord();
79 MCELFStreamer *llvm::createMipsELFStreamer(MCContext &Context,
81 raw_pwrite_stream &OS,
82 MCCodeEmitter *Emitter,
84 return new MipsELFStreamer(Context, MAB, OS, Emitter);