// SPDX-License-Identifier: GPL-3.0-or-later #ifndef RCC_CODEGEN_ASMPRINTER_H #define RCC_CODEGEN_ASMPRINTER_H #include "rcc/IR/DataLayout.h" #include "rcc/Support/Error.h" #include #include #include namespace rcc { class CompilationUnit; class GlobalInitializer; class MachineFunction; class MachineJumpTableEntry; class MachineMCContext; struct GenericConstantData; class TargetConstant; class TargetDescription; class TargetLoweringObjectFile; class TargetMCInstLowering; namespace mc { class MCStreamer; } // namespace mc struct AsmPrinterOptions final { bool EmitFunctionDirectives = true; bool EmitCFI = true; bool EmitBlockLabels = true; bool EmitInstructionSymbols = true; bool VerifyInput = true; }; class AsmPrinter { public: AsmPrinter(const TargetDescription &Target, const TargetMCInstLowering &Lowering, const TargetLoweringObjectFile &ObjectFile, DataLayout Layout, MachineMCContext &Context, mc::MCStreamer &Streamer, AsmPrinterOptions Options = {}) noexcept : Target(&Target), Lowering(&Lowering), ObjectFile(&ObjectFile), Layout(std::move(Layout)), Context(&Context), Streamer(&Streamer), Options(Options) {} virtual ~AsmPrinter() = default; [[nodiscard]] Expected emitCompilationUnit(const CompilationUnit &Unit); [[nodiscard]] Expected emitFunction(const MachineFunction &Function); protected: [[nodiscard]] virtual Expected emitStartOfAsmFile(); [[nodiscard]] virtual Expected emitEndOfAsmFile(); [[nodiscard]] virtual Expected emitTargetConstant(const TargetConstant &Constant); [[nodiscard]] virtual Expected emitTargetJumpTable(const MachineFunction &Function, const MachineJumpTableEntry &Entry); [[nodiscard]] MachineMCContext &machineContext() const noexcept { return *Context; } [[nodiscard]] mc::MCStreamer &streamer() const noexcept { return *Streamer; } private: [[nodiscard]] Expected verifyFunction(const MachineFunction &Function) const; [[nodiscard]] Expected emitGlobalObjects(const CompilationUnit &Unit); [[nodiscard]] Expected emitFunctionImpl(const MachineFunction &Function); [[nodiscard]] Expected emitFunctionBody(const MachineFunction &Function); [[nodiscard]] Expected emitConstantPool(const MachineFunction &Function); [[nodiscard]] Expected emitJumpTables(const MachineFunction &Function); [[nodiscard]] Expected emitGenericConstant(const GenericConstantData &Constant, std::uint64_t AllocationSize, std::size_t Depth = 0); [[nodiscard]] Expected emitGlobalInitializer(const GlobalInitializer &Initializer, std::size_t Depth = 0); const TargetDescription *Target; const TargetMCInstLowering *Lowering; const TargetLoweringObjectFile *ObjectFile; DataLayout Layout; MachineMCContext *Context; mc::MCStreamer *Streamer; AsmPrinterOptions Options; bool EmissionStarted = false; bool EmissionFinished = false; }; } // namespace rcc #endif // RCC_CODEGEN_ASMPRINTER_H