blob: 18c4a206059da0e36a29d7dce93e134b0e057ba4 [file] [log] [blame]
Matheus Almeidadac77fb2014-03-27 11:39:03 +00001//===-------- 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"
Zoran Jovanovic9c654832014-11-05 16:35:20 +000011#include "MipsTargetStreamer.h"
12#include "llvm/MC/MCELF.h"
Daniel Sanders68c37472014-07-21 13:30:55 +000013#include "llvm/MC/MCInst.h"
Zoran Jovanovic9c654832014-11-05 16:35:20 +000014#include "llvm/Support/ELF.h"
15
Benjamin Kramer89854eb2014-09-03 21:04:12 +000016using namespace llvm;
Daniel Sanders68c37472014-07-21 13:30:55 +000017
18void 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();
Zoran Jovanovic9c654832014-11-05 16:35:20 +000024 MipsTargetELFStreamer *ELFTargetStreamer =
25 static_cast<MipsTargetELFStreamer *>(getTargetStreamer());
Daniel Sanders68c37472014-07-21 13:30:55 +000026
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 }
Zoran Jovanovic9c654832014-11-05 16:35:20 +000036
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
50void MipsELFStreamer::EmitLabel(MCSymbol *Symbol) {
51 MCELFStreamer::EmitLabel(Symbol);
52 Labels.push_back(Symbol);
53}
54
55void MipsELFStreamer::SwitchSection(const MCSection * Section,
56 const MCExpr *Subsection) {
57 MCELFStreamer::SwitchSection(Section, Subsection);
58 Labels.clear();
59}
60
61void MipsELFStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size,
62 const SMLoc &Loc) {
63 MCELFStreamer::EmitValueImpl(Value, Size, Loc);
64 Labels.clear();
Daniel Sanders68c37472014-07-21 13:30:55 +000065}
66
67void MipsELFStreamer::EmitMipsOptionRecords() {
68 for (const auto &I : MipsOptionRecords)
69 I->EmitMipsOptionRecord();
70}
Matheus Almeidadac77fb2014-03-27 11:39:03 +000071
72namespace llvm {
73MCELFStreamer *createMipsELFStreamer(MCContext &Context, MCAsmBackend &MAB,
74 raw_ostream &OS, MCCodeEmitter *Emitter,
Rafael Espindola7b61ddf2014-10-15 16:12:52 +000075 const MCSubtargetInfo &STI,
76 bool RelaxAll) {
Matheus Almeidadac77fb2014-03-27 11:39:03 +000077 return new MipsELFStreamer(Context, MAB, OS, Emitter, STI);
78}
79}