Eugene Zelenko | cd8ea02 | 2017-02-03 23:39:33 +0000 | [diff] [blame] | 1 | //===- MipsELFStreamer.h - ELF Object Output --------------------*- C++ -*-===// |
Matheus Almeida | dac77fb | 2014-03-27 11:39:03 +0000 | [diff] [blame] | 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 | // This is a custom MCELFStreamer which allows us to insert some hooks before |
| 11 | // emitting data into an actual object file. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Benjamin Kramer | a7c40ef | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 15 | #ifndef LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSELFSTREAMER_H |
| 16 | #define LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSELFSTREAMER_H |
Matheus Almeida | dac77fb | 2014-03-27 11:39:03 +0000 | [diff] [blame] | 17 | |
Daniel Sanders | 68c3747 | 2014-07-21 13:30:55 +0000 | [diff] [blame] | 18 | #include "MipsOptionRecord.h" |
| 19 | #include "llvm/ADT/SmallVector.h" |
Matheus Almeida | dac77fb | 2014-03-27 11:39:03 +0000 | [diff] [blame] | 20 | #include "llvm/MC/MCELFStreamer.h" |
Daniel Sanders | 68c3747 | 2014-07-21 13:30:55 +0000 | [diff] [blame] | 21 | #include <memory> |
Matheus Almeida | dac77fb | 2014-03-27 11:39:03 +0000 | [diff] [blame] | 22 | |
| 23 | namespace llvm { |
Eugene Zelenko | cd8ea02 | 2017-02-03 23:39:33 +0000 | [diff] [blame] | 24 | |
Matheus Almeida | dac77fb | 2014-03-27 11:39:03 +0000 | [diff] [blame] | 25 | class MCAsmBackend; |
| 26 | class MCCodeEmitter; |
| 27 | class MCContext; |
| 28 | class MCSubtargetInfo; |
| 29 | |
| 30 | class MipsELFStreamer : public MCELFStreamer { |
Daniel Sanders | 68c3747 | 2014-07-21 13:30:55 +0000 | [diff] [blame] | 31 | SmallVector<std::unique_ptr<MipsOptionRecord>, 8> MipsOptionRecords; |
| 32 | MipsRegInfoRecord *RegInfoRecord; |
Zoran Jovanovic | 9c65483 | 2014-11-05 16:35:20 +0000 | [diff] [blame] | 33 | SmallVector<MCSymbol*, 4> Labels; |
| 34 | |
Matheus Almeida | dac77fb | 2014-03-27 11:39:03 +0000 | [diff] [blame] | 35 | public: |
Lang Hames | 02d3305 | 2017-10-11 01:57:21 +0000 | [diff] [blame] | 36 | MipsELFStreamer(MCContext &Context, std::unique_ptr<MCAsmBackend> MAB, |
Lang Hames | 2241ffa | 2017-10-11 23:34:47 +0000 | [diff] [blame^] | 37 | raw_pwrite_stream &OS, |
| 38 | std::unique_ptr<MCCodeEmitter> Emitter); |
Daniel Sanders | 68c3747 | 2014-07-21 13:30:55 +0000 | [diff] [blame] | 39 | |
| 40 | /// Overriding this function allows us to add arbitrary behaviour before the |
| 41 | /// \p Inst is actually emitted. For example, we can inspect the operands and |
| 42 | /// gather sufficient information that allows us to reason about the register |
| 43 | /// usage for the translation unit. |
Andrew V. Tischenko | 75745d0 | 2017-04-14 07:44:23 +0000 | [diff] [blame] | 44 | void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI, |
| 45 | bool = false) override; |
Daniel Sanders | 68c3747 | 2014-07-21 13:30:55 +0000 | [diff] [blame] | 46 | |
Zoran Jovanovic | 9c65483 | 2014-11-05 16:35:20 +0000 | [diff] [blame] | 47 | /// Overriding this function allows us to record all labels that should be |
| 48 | /// marked as microMIPS. Based on this data marking is done in |
| 49 | /// EmitInstruction. |
Rafael Espindola | be99157 | 2017-02-10 15:13:12 +0000 | [diff] [blame] | 50 | void EmitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override; |
Zoran Jovanovic | 9c65483 | 2014-11-05 16:35:20 +0000 | [diff] [blame] | 51 | |
| 52 | /// Overriding this function allows us to dismiss all labels that are |
| 53 | /// candidates for marking as microMIPS when .section directive is processed. |
Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 54 | void SwitchSection(MCSection *Section, |
Zoran Jovanovic | 9c65483 | 2014-11-05 16:35:20 +0000 | [diff] [blame] | 55 | const MCExpr *Subsection = nullptr) override; |
| 56 | |
| 57 | /// Overriding this function allows us to dismiss all labels that are |
| 58 | /// candidates for marking as microMIPS when .word directive is emitted. |
Craig Topper | 3c76c52 | 2015-09-20 23:35:59 +0000 | [diff] [blame] | 59 | void EmitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc) override; |
Zoran Jovanovic | 9c65483 | 2014-11-05 16:35:20 +0000 | [diff] [blame] | 60 | |
Daniel Sanders | 68c3747 | 2014-07-21 13:30:55 +0000 | [diff] [blame] | 61 | /// Emits all the option records stored up until the point it's called. |
| 62 | void EmitMipsOptionRecords(); |
Toma Tabacu | 9ca5096 | 2015-04-16 09:53:47 +0000 | [diff] [blame] | 63 | |
| 64 | /// Mark labels as microMIPS, if necessary for the subtarget. |
| 65 | void createPendingLabelRelocs(); |
Matheus Almeida | dac77fb | 2014-03-27 11:39:03 +0000 | [diff] [blame] | 66 | }; |
| 67 | |
Lang Hames | 02d3305 | 2017-10-11 01:57:21 +0000 | [diff] [blame] | 68 | MCELFStreamer *createMipsELFStreamer(MCContext &Context, |
| 69 | std::unique_ptr<MCAsmBackend> MAB, |
Rafael Espindola | 5560a4c | 2015-04-14 22:14:34 +0000 | [diff] [blame] | 70 | raw_pwrite_stream &OS, |
Lang Hames | 2241ffa | 2017-10-11 23:34:47 +0000 | [diff] [blame^] | 71 | std::unique_ptr<MCCodeEmitter> Emitter, |
| 72 | bool RelaxAll); |
Eugene Zelenko | cd8ea02 | 2017-02-03 23:39:33 +0000 | [diff] [blame] | 73 | } // end namespace llvm |
| 74 | |
| 75 | #endif // LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSELFSTREAMER_H |