Path: blob/main/contrib/llvm-project/llvm/lib/DWARFLinker/Parallel/DWARFEmitterImpl.h
35292 views
//===- DwarfEmitterImpl.h ---------------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLVM_LIB_DWARFLINKER_PARALLEL_DWARFEMITTERIMPL_H9#define LLVM_LIB_DWARFLINKER_PARALLEL_DWARFEMITTERIMPL_H1011#include "DWARFLinkerCompileUnit.h"12#include "llvm/BinaryFormat/Swift.h"13#include "llvm/CodeGen/AccelTable.h"14#include "llvm/CodeGen/AsmPrinter.h"15#include "llvm/DWARFLinker/Parallel/DWARFLinker.h"16#include "llvm/MC/MCAsmInfo.h"17#include "llvm/MC/MCContext.h"18#include "llvm/MC/MCInstrInfo.h"19#include "llvm/MC/MCObjectFileInfo.h"20#include "llvm/MC/MCRegisterInfo.h"21#include "llvm/MC/MCStreamer.h"22#include "llvm/MC/MCSubtargetInfo.h"23#include "llvm/Target/TargetMachine.h"2425namespace llvm {2627/// User of DwarfEmitterImpl should call initialization code28/// for AsmPrinter:29///30/// InitializeAllTargetInfos();31/// InitializeAllTargetMCs();32/// InitializeAllTargets();33/// InitializeAllAsmPrinters();3435template <typename DataT> class AccelTable;36class MCCodeEmitter;3738namespace dwarf_linker {39namespace parallel {4041using DebugNamesUnitsOffsets = std::vector<std::variant<MCSymbol *, uint64_t>>;42using CompUnitIDToIdx = DenseMap<unsigned, unsigned>;4344/// This class emits DWARF data to the output stream. It emits already45/// generated section data and specific data, which could not be generated46/// by CompileUnit.47class DwarfEmitterImpl {48public:49DwarfEmitterImpl(DWARFLinker::OutputFileType OutFileType,50raw_pwrite_stream &OutFile)51: OutFile(OutFile), OutFileType(OutFileType) {}5253/// Initialize AsmPrinter data.54Error init(Triple TheTriple, StringRef Swift5ReflectionSegmentName);5556/// Returns triple of output stream.57const Triple &getTargetTriple() { return MC->getTargetTriple(); }5859/// Dump the file to the disk.60void finish() { MS->finish(); }6162/// Emit abbreviations.63void emitAbbrevs(const SmallVector<std::unique_ptr<DIEAbbrev>> &Abbrevs,64unsigned DwarfVersion);6566/// Emit compile unit header.67void emitCompileUnitHeader(DwarfUnit &Unit);6869/// Emit DIE recursively.70void emitDIE(DIE &Die);7172/// Returns size of generated .debug_info section.73uint64_t getDebugInfoSectionSize() const { return DebugInfoSectionSize; }7475/// Emits .debug_names section according to the specified \p Table.76void emitDebugNames(DWARF5AccelTable &Table,77DebugNamesUnitsOffsets &CUOffsets,78CompUnitIDToIdx &UnitIDToIdxMap);7980/// Emits .apple_names section according to the specified \p Table.81void emitAppleNames(AccelTable<AppleAccelTableStaticOffsetData> &Table);8283/// Emits .apple_namespaces section according to the specified \p Table.84void emitAppleNamespaces(AccelTable<AppleAccelTableStaticOffsetData> &Table);8586/// Emits .apple_objc section according to the specified \p Table.87void emitAppleObjc(AccelTable<AppleAccelTableStaticOffsetData> &Table);8889/// Emits .apple_types section according to the specified \p Table.90void emitAppleTypes(AccelTable<AppleAccelTableStaticTypeData> &Table);9192private:93// Enumerate all string patches and write them into the destination section.94// Order of patches is the same as in original input file. To avoid emitting95// the same string twice we accumulate NextOffset value. Thus if string96// offset smaller than NextOffset value then the patch is skipped (as that97// string was emitted earlier).98template <typename PatchTy>99void emitStringsImpl(ArrayList<PatchTy> &StringPatches,100const StringEntryToDwarfStringPoolEntryMap &Strings,101uint64_t &NextOffset, MCSection *OutSection);102103/// \defgroup MCObjects MC layer objects constructed by the streamer104/// @{105std::unique_ptr<MCRegisterInfo> MRI;106std::unique_ptr<MCAsmInfo> MAI;107std::unique_ptr<MCObjectFileInfo> MOFI;108std::unique_ptr<MCContext> MC;109MCAsmBackend *MAB; // Owned by MCStreamer110std::unique_ptr<MCInstrInfo> MII;111std::unique_ptr<MCSubtargetInfo> MSTI;112MCInstPrinter *MIP; // Owned by AsmPrinter113MCCodeEmitter *MCE; // Owned by MCStreamer114MCStreamer *MS; // Owned by AsmPrinter115std::unique_ptr<TargetMachine> TM;116std::unique_ptr<AsmPrinter> Asm;117/// @}118119/// The output file we stream the linked Dwarf to.120raw_pwrite_stream &OutFile;121DWARFLinkerBase::OutputFileType OutFileType =122DWARFLinkerBase::OutputFileType::Object;123124uint64_t DebugInfoSectionSize = 0;125};126127} // end of namespace parallel128} // end of namespace dwarf_linker129} // end of namespace llvm130131#endif // LLVM_LIB_DWARFLINKER_PARALLEL_DWARFEMITTERIMPL_H132133134