blob: 9b748ce92c3c34374ce42fb7b7f4cfa7ec93136e [file] [log] [blame]
Eugene Zelenkocd8ea022017-02-03 23:39:33 +00001//===- MipsELFStreamer.h - ELF Object Output --------------------*- C++ -*-===//
Matheus Almeidadac77fb2014-03-27 11:39:03 +00002//
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 {
Eugene Zelenkocd8ea022017-02-03 23:39:33 +000024
Matheus Almeidadac77fb2014-03-27 11:39:03 +000025class MCAsmBackend;
26class MCCodeEmitter;
27class MCContext;
28class MCSubtargetInfo;
29
30class MipsELFStreamer : public MCELFStreamer {
Daniel Sanders68c37472014-07-21 13:30:55 +000031 SmallVector<std::unique_ptr<MipsOptionRecord>, 8> MipsOptionRecords;
32 MipsRegInfoRecord *RegInfoRecord;
Zoran Jovanovic9c654832014-11-05 16:35:20 +000033 SmallVector<MCSymbol*, 4> Labels;
34
Matheus Almeidadac77fb2014-03-27 11:39:03 +000035public:
Rafael Espindola5560a4c2015-04-14 22:14:34 +000036 MipsELFStreamer(MCContext &Context, MCAsmBackend &MAB, raw_pwrite_stream &OS,
Rafael Espindolacd584a82015-03-19 01:50:16 +000037 MCCodeEmitter *Emitter)
Daniel Sanders68c37472014-07-21 13:30:55 +000038 : MCELFStreamer(Context, MAB, OS, Emitter) {
Eric Christophera5762812015-01-26 17:33:46 +000039 RegInfoRecord = new MipsRegInfoRecord(this, Context);
Daniel Sanders68c37472014-07-21 13:30:55 +000040 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) override;
49
Zoran Jovanovic9c654832014-11-05 16:35:20 +000050 /// Overriding this function allows us to record all labels that should be
51 /// marked as microMIPS. Based on this data marking is done in
52 /// EmitInstruction.
53 void EmitLabel(MCSymbol *Symbol) override;
54
55 /// Overriding this function allows us to dismiss all labels that are
56 /// candidates for marking as microMIPS when .section directive is processed.
Rafael Espindola0709a7b2015-05-21 19:20:38 +000057 void SwitchSection(MCSection *Section,
Zoran Jovanovic9c654832014-11-05 16:35:20 +000058 const MCExpr *Subsection = nullptr) override;
59
60 /// Overriding this function allows us to dismiss all labels that are
61 /// candidates for marking as microMIPS when .word directive is emitted.
Craig Topper3c76c522015-09-20 23:35:59 +000062 void EmitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc) override;
Zoran Jovanovic9c654832014-11-05 16:35:20 +000063
Daniel Sanders68c37472014-07-21 13:30:55 +000064 /// Emits all the option records stored up until the point it's called.
65 void EmitMipsOptionRecords();
Toma Tabacu9ca50962015-04-16 09:53:47 +000066
67 /// Mark labels as microMIPS, if necessary for the subtarget.
68 void createPendingLabelRelocs();
Matheus Almeidadac77fb2014-03-27 11:39:03 +000069};
70
71MCELFStreamer *createMipsELFStreamer(MCContext &Context, MCAsmBackend &MAB,
Rafael Espindola5560a4c2015-04-14 22:14:34 +000072 raw_pwrite_stream &OS,
73 MCCodeEmitter *Emitter, bool RelaxAll);
Eugene Zelenkocd8ea022017-02-03 23:39:33 +000074} // end namespace llvm
75
76#endif // LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSELFSTREAMER_H