| Matheus Almeida | dac77fb | 2014-03-27 11:39:03 +0000 | [diff] [blame] | 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" |
| Zoran Jovanovic | 9c65483 | 2014-11-05 16:35:20 +0000 | [diff] [blame] | 11 | #include "MipsTargetStreamer.h" |
| 12 | #include "llvm/MC/MCELF.h" |
| Daniel Sanders | 68c3747 | 2014-07-21 13:30:55 +0000 | [diff] [blame] | 13 | #include "llvm/MC/MCInst.h" |
| Zoran Jovanovic | 9c65483 | 2014-11-05 16:35:20 +0000 | [diff] [blame] | 14 | #include "llvm/Support/ELF.h" |
| 15 | |
| Benjamin Kramer | 89854eb | 2014-09-03 21:04:12 +0000 | [diff] [blame] | 16 | using namespace llvm; |
| Daniel Sanders | 68c3747 | 2014-07-21 13:30:55 +0000 | [diff] [blame] | 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(); |
| Zoran Jovanovic | 9c65483 | 2014-11-05 16:35:20 +0000 | [diff] [blame] | 24 | MipsTargetELFStreamer *ELFTargetStreamer = |
| 25 | static_cast<MipsTargetELFStreamer *>(getTargetStreamer()); |
| Daniel Sanders | 68c3747 | 2014-07-21 13:30:55 +0000 | [diff] [blame] | 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 | } |
| Zoran Jovanovic | 9c65483 | 2014-11-05 16:35:20 +0000 | [diff] [blame] | 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(); |
| Daniel Sanders | 68c3747 | 2014-07-21 13:30:55 +0000 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | void MipsELFStreamer::EmitMipsOptionRecords() { |
| 68 | for (const auto &I : MipsOptionRecords) |
| 69 | I->EmitMipsOptionRecord(); |
| 70 | } |
| Matheus Almeida | dac77fb | 2014-03-27 11:39:03 +0000 | [diff] [blame] | 71 | |
| 72 | namespace llvm { |
| 73 | MCELFStreamer *createMipsELFStreamer(MCContext &Context, MCAsmBackend &MAB, |
| 74 | raw_ostream &OS, MCCodeEmitter *Emitter, |
| Rafael Espindola | 7b61ddf | 2014-10-15 16:12:52 +0000 | [diff] [blame] | 75 | const MCSubtargetInfo &STI, |
| 76 | bool RelaxAll) { |
| Matheus Almeida | dac77fb | 2014-03-27 11:39:03 +0000 | [diff] [blame] | 77 | return new MipsELFStreamer(Context, MAB, OS, Emitter, STI); |
| 78 | } |
| 79 | } |