]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.h
Merge ^/head r321307 through r321350.
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / Target / Mips / MCTargetDesc / MipsELFStreamer.h
1 //===- MipsELFStreamer.h - ELF Object Output --------------------*- C++ -*-===//
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
15 #ifndef LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSELFSTREAMER_H
16 #define LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSELFSTREAMER_H
17
18 #include "MipsOptionRecord.h"
19 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/MC/MCELFStreamer.h"
21 #include <memory>
22
23 namespace llvm {
24
25 class MCAsmBackend;
26 class MCCodeEmitter;
27 class MCContext;
28 class MCSubtargetInfo;
29
30 class MipsELFStreamer : public MCELFStreamer {
31   SmallVector<std::unique_ptr<MipsOptionRecord>, 8> MipsOptionRecords;
32   MipsRegInfoRecord *RegInfoRecord;
33   SmallVector<MCSymbol*, 4> Labels;
34
35 public:
36   MipsELFStreamer(MCContext &Context, MCAsmBackend &MAB, raw_pwrite_stream &OS,
37                   MCCodeEmitter *Emitter)
38       : MCELFStreamer(Context, MAB, OS, Emitter) {
39     RegInfoRecord = new MipsRegInfoRecord(this, Context);
40     MipsOptionRecords.push_back(
41         std::unique_ptr<MipsRegInfoRecord>(RegInfoRecord));
42   }
43
44   /// Overriding this function allows us to add arbitrary behaviour before the
45   /// \p Inst is actually emitted. For example, we can inspect the operands and
46   /// gather sufficient information that allows us to reason about the register
47   /// usage for the translation unit.
48   void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI,
49                        bool = false) override;
50
51   /// Overriding this function allows us to record all labels that should be
52   /// marked as microMIPS. Based on this data marking is done in
53   /// EmitInstruction.
54   void EmitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
55
56   /// Overriding this function allows us to dismiss all labels that are
57   /// candidates for marking as microMIPS when .section directive is processed.
58   void SwitchSection(MCSection *Section,
59                      const MCExpr *Subsection = nullptr) override;
60
61   /// Overriding this function allows us to dismiss all labels that are
62   /// candidates for marking as microMIPS when .word directive is emitted.
63   void EmitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc) override;
64
65   /// Emits all the option records stored up until the point it's called.
66   void EmitMipsOptionRecords();
67
68   /// Mark labels as microMIPS, if necessary for the subtarget.
69   void createPendingLabelRelocs();
70 };
71
72 MCELFStreamer *createMipsELFStreamer(MCContext &Context, MCAsmBackend &MAB,
73                                      raw_pwrite_stream &OS,
74                                      MCCodeEmitter *Emitter, bool RelaxAll);
75 } // end namespace llvm
76
77 #endif // LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSELFSTREAMER_H