81 lines · c
1//===- MipsELFStreamer.h - ELF Object Output --------------------*- C++ -*-===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8//9// This is a custom MCELFStreamer which allows us to insert some hooks before10// emitting data into an actual object file.11//12//===----------------------------------------------------------------------===//13 14#ifndef LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSELFSTREAMER_H15#define LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSELFSTREAMER_H16 17#include "MipsOptionRecord.h"18#include "llvm/ADT/SmallVector.h"19#include "llvm/MC/MCELFStreamer.h"20#include <memory>21 22namespace llvm {23 24class MCAsmBackend;25class MCCodeEmitter;26class MCContext;27class MCSubtargetInfo;28struct MCDwarfFrameInfo;29 30class MipsELFStreamer : public MCELFStreamer {31 SmallVector<std::unique_ptr<MipsOptionRecord>, 8> MipsOptionRecords;32 MipsRegInfoRecord *RegInfoRecord;33 SmallVector<MCSymbol*, 4> Labels;34 35public:36 MipsELFStreamer(MCContext &Context, std::unique_ptr<MCAsmBackend> MAB,37 std::unique_ptr<MCObjectWriter> OW,38 std::unique_ptr<MCCodeEmitter> Emitter);39 40 /// Overriding this function allows us to add arbitrary behaviour before the41 /// \p Inst is actually emitted. For example, we can inspect the operands and42 /// gather sufficient information that allows us to reason about the register43 /// usage for the translation unit.44 void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override;45 46 /// Overriding this function allows us to record all labels that should be47 /// marked as microMIPS. Based on this data marking is done in48 /// EmitInstruction.49 void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;50 51 /// Overriding this function allows us to dismiss all labels that are52 /// candidates for marking as microMIPS when .section directive is processed.53 void switchSection(MCSection *Section, uint32_t Subsection = 0) override;54 55 /// Overriding these functions allows us to dismiss all labels that are56 /// candidates for marking as microMIPS when .word/.long/.4byte etc57 /// directives are emitted.58 void emitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc) override;59 void emitIntValue(uint64_t Value, unsigned Size) override;60 61 // Overriding these functions allows us to avoid recording of these labels62 // in EmitLabel and later marking them as microMIPS.63 void emitCFIStartProcImpl(MCDwarfFrameInfo &Frame) override;64 void emitCFIEndProcImpl(MCDwarfFrameInfo &Frame) override;65 MCSymbol *emitCFILabel() override;66 67 /// Emits all the option records stored up until the point it's called.68 void EmitMipsOptionRecords();69 70 /// Mark labels as microMIPS, if necessary for the subtarget.71 void createPendingLabelRelocs();72};73 74MCELFStreamer *createMipsELFStreamer(MCContext &Context,75 std::unique_ptr<MCAsmBackend> MAB,76 std::unique_ptr<MCObjectWriter> OW,77 std::unique_ptr<MCCodeEmitter> Emitter);78} // end namespace llvm79 80#endif // LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSELFSTREAMER_H81