1 //===- MipsELFStreamer.h - ELF Object Output --------------------*- C++ -*-===//
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 // This is a custom MCELFStreamer which allows us to insert some hooks before
11 // emitting data into an actual object file.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSELFSTREAMER_H
16 #define LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSELFSTREAMER_H
18 #include "MipsOptionRecord.h"
19 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/MC/MCELFStreamer.h"
28 class MCSubtargetInfo;
29 struct MCDwarfFrameInfo;
31 class MipsELFStreamer : public MCELFStreamer {
32 SmallVector<std::unique_ptr<MipsOptionRecord>, 8> MipsOptionRecords;
33 MipsRegInfoRecord *RegInfoRecord;
34 SmallVector<MCSymbol*, 4> Labels;
37 MipsELFStreamer(MCContext &Context, std::unique_ptr<MCAsmBackend> MAB,
38 std::unique_ptr<MCObjectWriter> OW,
39 std::unique_ptr<MCCodeEmitter> Emitter);
41 /// Overriding this function allows us to add arbitrary behaviour before the
42 /// \p Inst is actually emitted. For example, we can inspect the operands and
43 /// gather sufficient information that allows us to reason about the register
44 /// usage for the translation unit.
45 void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI,
46 bool = false) override;
48 /// Overriding this function allows us to record all labels that should be
49 /// marked as microMIPS. Based on this data marking is done in
51 void EmitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
53 /// Overriding this function allows us to dismiss all labels that are
54 /// candidates for marking as microMIPS when .section directive is processed.
55 void SwitchSection(MCSection *Section,
56 const MCExpr *Subsection = nullptr) override;
58 /// Overriding these functions allows us to dismiss all labels that are
59 /// candidates for marking as microMIPS when .word/.long/.4byte etc
60 /// directives are emitted.
61 void EmitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc) override;
62 void EmitIntValue(uint64_t Value, unsigned Size) override;
64 // Overriding these functions allows us to avoid recording of these labels
65 // in EmitLabel and later marking them as microMIPS.
66 void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame) override;
67 void EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame) override;
68 MCSymbol *EmitCFILabel() override;
70 /// Emits all the option records stored up until the point it's called.
71 void EmitMipsOptionRecords();
73 /// Mark labels as microMIPS, if necessary for the subtarget.
74 void createPendingLabelRelocs();
77 MCELFStreamer *createMipsELFStreamer(MCContext &Context,
78 std::unique_ptr<MCAsmBackend> MAB,
79 std::unique_ptr<MCObjectWriter> OW,
80 std::unique_ptr<MCCodeEmitter> Emitter,
82 } // end namespace llvm
84 #endif // LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSELFSTREAMER_H