blob: bc76d8a852139f33e0c25ba6162327bc9a89a69f [file] [log] [blame]
Matheus Almeidadac77fb2014-03-27 11:39:03 +00001//===-------- MipsELFStreamer.h - 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// 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 Kramera7c40ef2014-08-13 16:26:38 +000015#ifndef LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSELFSTREAMER_H
16#define LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSELFSTREAMER_H
Matheus Almeidadac77fb2014-03-27 11:39:03 +000017
Daniel Sanders68c37472014-07-21 13:30:55 +000018#include "MipsOptionRecord.h"
19#include "llvm/ADT/SmallVector.h"
Matheus Almeidadac77fb2014-03-27 11:39:03 +000020#include "llvm/MC/MCELFStreamer.h"
Daniel Sanders68c37472014-07-21 13:30:55 +000021#include <memory>
Matheus Almeidadac77fb2014-03-27 11:39:03 +000022
23namespace llvm {
24class MCAsmBackend;
25class MCCodeEmitter;
26class MCContext;
27class MCSubtargetInfo;
28
29class MipsELFStreamer : public MCELFStreamer {
Daniel Sanders68c37472014-07-21 13:30:55 +000030 SmallVector<std::unique_ptr<MipsOptionRecord>, 8> MipsOptionRecords;
31 MipsRegInfoRecord *RegInfoRecord;
Zoran Jovanovic9c654832014-11-05 16:35:20 +000032 SmallVector<MCSymbol*, 4> Labels;
33
Matheus Almeidadac77fb2014-03-27 11:39:03 +000034
35public:
36 MipsELFStreamer(MCContext &Context, MCAsmBackend &MAB, raw_ostream &OS,
37 MCCodeEmitter *Emitter, const MCSubtargetInfo &STI)
Daniel Sanders68c37472014-07-21 13:30:55 +000038 : MCELFStreamer(Context, MAB, OS, Emitter) {
Matheus Almeidadac77fb2014-03-27 11:39:03 +000039
Eric Christophera5762812015-01-26 17:33:46 +000040 RegInfoRecord = new MipsRegInfoRecord(this, Context);
Daniel Sanders68c37472014-07-21 13:30:55 +000041 MipsOptionRecords.push_back(
42 std::unique_ptr<MipsRegInfoRecord>(RegInfoRecord));
43 }
44
45 /// Overriding this function allows us to add arbitrary behaviour before the
46 /// \p Inst is actually emitted. For example, we can inspect the operands and
47 /// gather sufficient information that allows us to reason about the register
48 /// usage for the translation unit.
49 void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override;
50
Zoran Jovanovic9c654832014-11-05 16:35:20 +000051 /// 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) 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(const 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,
64 const SMLoc &Loc) override;
65
Daniel Sanders68c37472014-07-21 13:30:55 +000066 /// Emits all the option records stored up until the point it's called.
67 void EmitMipsOptionRecords();
Matheus Almeidadac77fb2014-03-27 11:39:03 +000068};
69
70MCELFStreamer *createMipsELFStreamer(MCContext &Context, MCAsmBackend &MAB,
71 raw_ostream &OS, MCCodeEmitter *Emitter,
Rafael Espindola7b61ddf2014-10-15 16:12:52 +000072 const MCSubtargetInfo &STI, bool RelaxAll);
Matheus Almeidadac77fb2014-03-27 11:39:03 +000073} // namespace llvm.
74#endif