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" |
Daniel Sanders | 68c3747 | 2014-07-21 13:30:55 +0000 | [diff] [blame] | 12 | #include "llvm/MC/MCInst.h" |
Rafael Espindola | 95fb9b9 | 2015-06-02 20:38:46 +0000 | [diff] [blame] | 13 | #include "llvm/MC/MCSymbolELF.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(); |
| 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 | } |
Zoran Jovanovic | 9c65483 | 2014-11-05 16:35:20 +0000 | [diff] [blame] | 34 | |
Toma Tabacu | 9ca5096 | 2015-04-16 09:53:47 +0000 | [diff] [blame] | 35 | createPendingLabelRelocs(); |
| 36 | } |
| 37 | |
| 38 | void MipsELFStreamer::createPendingLabelRelocs() { |
| 39 | MipsTargetELFStreamer *ELFTargetStreamer = |
| 40 | static_cast<MipsTargetELFStreamer *>(getTargetStreamer()); |
| 41 | |
| 42 | // FIXME: Also mark labels when in MIPS16 mode. |
Zoran Jovanovic | 9c65483 | 2014-11-05 16:35:20 +0000 | [diff] [blame] | 43 | if (ELFTargetStreamer->isMicroMipsEnabled()) { |
Rafael Espindola | 95fb9b9 | 2015-06-02 20:38:46 +0000 | [diff] [blame] | 44 | for (auto *L : Labels) { |
| 45 | auto *Label = cast<MCSymbolELF>(L); |
Rafael Espindola | c73aed1 | 2015-06-03 19:03:11 +0000 | [diff] [blame^] | 46 | getAssembler().registerSymbol(*Label); |
Zoran Jovanovic | 9c65483 | 2014-11-05 16:35:20 +0000 | [diff] [blame] | 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. |
Rafael Espindola | 95fb9b9 | 2015-06-02 20:38:46 +0000 | [diff] [blame] | 50 | Label->setOther(ELF::STO_MIPS_MICROMIPS >> 2); |
Zoran Jovanovic | 9c65483 | 2014-11-05 16:35:20 +0000 | [diff] [blame] | 51 | } |
| 52 | } |
| 53 | |
| 54 | Labels.clear(); |
| 55 | } |
| 56 | |
| 57 | void MipsELFStreamer::EmitLabel(MCSymbol *Symbol) { |
| 58 | MCELFStreamer::EmitLabel(Symbol); |
| 59 | Labels.push_back(Symbol); |
| 60 | } |
| 61 | |
Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 62 | void MipsELFStreamer::SwitchSection(MCSection *Section, |
Zoran Jovanovic | 9c65483 | 2014-11-05 16:35:20 +0000 | [diff] [blame] | 63 | const MCExpr *Subsection) { |
| 64 | MCELFStreamer::SwitchSection(Section, Subsection); |
| 65 | Labels.clear(); |
| 66 | } |
| 67 | |
| 68 | void MipsELFStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size, |
| 69 | const SMLoc &Loc) { |
| 70 | MCELFStreamer::EmitValueImpl(Value, Size, Loc); |
| 71 | Labels.clear(); |
Daniel Sanders | 68c3747 | 2014-07-21 13:30:55 +0000 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | void MipsELFStreamer::EmitMipsOptionRecords() { |
| 75 | for (const auto &I : MipsOptionRecords) |
| 76 | I->EmitMipsOptionRecord(); |
| 77 | } |
Matheus Almeida | dac77fb | 2014-03-27 11:39:03 +0000 | [diff] [blame] | 78 | |
Rafael Espindola | cd584a8 | 2015-03-19 01:50:16 +0000 | [diff] [blame] | 79 | MCELFStreamer *llvm::createMipsELFStreamer(MCContext &Context, |
Rafael Espindola | 5560a4c | 2015-04-14 22:14:34 +0000 | [diff] [blame] | 80 | MCAsmBackend &MAB, |
| 81 | raw_pwrite_stream &OS, |
Rafael Espindola | cd584a8 | 2015-03-19 01:50:16 +0000 | [diff] [blame] | 82 | MCCodeEmitter *Emitter, |
| 83 | bool RelaxAll) { |
| 84 | return new MipsELFStreamer(Context, MAB, OS, Emitter); |
Matheus Almeida | dac77fb | 2014-03-27 11:39:03 +0000 | [diff] [blame] | 85 | } |