1 //===- DWARFLinkerGlobalData.h ----------------------------------*- C++ -*-===//
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-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIB_DWARFLINKERPARALLEL_DWARFLINKERGLOBALDATA_H
10 #define LLVM_LIB_DWARFLINKERPARALLEL_DWARFLINKERGLOBALDATA_H
12 #include "llvm/DWARFLinkerParallel/DWARFLinker.h"
13 #include "llvm/DWARFLinkerParallel/StringPool.h"
14 #include "llvm/Support/PerThreadBumpPtrAllocator.h"
21 namespace dwarflinker_parallel
{
23 using TranslatorFuncTy
= std::function
<StringRef(StringRef
)>;
24 using MessageHandlerTy
= std::function
<void(
25 const Twine
&Warning
, StringRef Context
, const DWARFDie
*DIE
)>;
28 struct DWARFLinkerOptions
{
29 /// DWARF version for the output.
30 uint16_t TargetDWARFVersion
= 0;
32 /// Generate processing log to the standard output.
36 bool Statistics
= false;
38 /// Verify the input DWARF.
39 bool VerifyInputDWARF
= false;
41 /// Do not emit output.
42 bool NoOutput
= false;
44 /// Do not unique types according to ODR
47 /// Update index tables.
48 bool UpdateIndexTablesOnly
= false;
50 /// Whether we want a static variable to force us to keep its enclosing
52 bool KeepFunctionForStatic
= false;
54 /// Allow to generate valid, but non deterministic output.
55 bool AllowNonDeterministicOutput
= false;
57 /// Number of threads.
60 /// The accelerator table kinds
61 SmallVector
<DWARFLinker::AccelTableKind
, 1> AccelTables
;
63 /// Prepend path for the clang modules.
64 std::string PrependPath
;
66 /// input verification handler(it might be called asynchronously).
67 DWARFLinker::InputVerificationHandlerTy InputVerificationHandler
= nullptr;
69 /// A list of all .swiftinterface files referenced by the debug
70 /// info, mapping Module name to path on disk. The entries need to
71 /// be uniqued and sorted and there are only few entries expected
72 /// per compile unit, which is why this is a std::map.
73 /// this is dsymutil specific fag.
75 /// (it might be called asynchronously).
76 DWARFLinker::SwiftInterfacesMapTy
*ParseableSwiftInterfaces
= nullptr;
78 /// A list of remappings to apply to file paths.
80 /// (it might be called asynchronously).
81 DWARFLinker::ObjectPrefixMapTy
*ObjectPrefixMap
= nullptr;
84 class DWARFLinkerImpl
;
86 /// This class keeps data and services common for the whole linking process.
87 class LinkingGlobalData
{
88 friend DWARFLinkerImpl
;
91 /// Returns global per-thread allocator.
92 parallel::PerThreadBumpPtrAllocator
&getAllocator() { return Allocator
; }
94 /// Returns global string pool.
95 StringPool
&getStringPool() { return Strings
; }
97 /// Set translation function.
98 void setTranslator(TranslatorFuncTy Translator
) {
99 this->Translator
= Translator
;
102 /// Translate specified string.
103 StringRef
translateString(StringRef String
) {
105 return Translator(String
);
110 /// Returns linking options.
111 const DWARFLinkerOptions
&getOptions() const { return Options
; }
113 /// Set warning handler.
114 void setWarningHandler(MessageHandlerTy Handler
) { WarningHandler
= Handler
; }
116 /// Set error handler.
117 void setErrorHandler(MessageHandlerTy Handler
) { ErrorHandler
= Handler
; }
120 void warn(const Twine
&Warning
, StringRef Context
,
121 const DWARFDie
*DIE
= nullptr) {
123 (WarningHandler
)(Warning
, Context
, DIE
);
127 void warn(Error Warning
, StringRef Context
, const DWARFDie
*DIE
= nullptr) {
128 handleAllErrors(std::move(Warning
), [&](ErrorInfoBase
&Info
) {
129 warn(Info
.message(), Context
, DIE
);
134 void error(const Twine
&Err
, StringRef Context
,
135 const DWARFDie
*DIE
= nullptr) {
137 (ErrorHandler
)(Err
, Context
, DIE
);
141 void error(Error Err
, StringRef Context
, const DWARFDie
*DIE
= nullptr) {
142 handleAllErrors(std::move(Err
), [&](ErrorInfoBase
&Info
) {
143 error(Info
.message(), Context
, DIE
);
148 parallel::PerThreadBumpPtrAllocator Allocator
;
150 TranslatorFuncTy Translator
;
151 DWARFLinkerOptions Options
;
152 MessageHandlerTy WarningHandler
;
153 MessageHandlerTy ErrorHandler
;
156 } // end of namespace dwarflinker_parallel
157 } // end namespace llvm
159 #endif // LLVM_LIB_DWARFLINKERPARALLEL_DWARFLINKERGLOBALDATA_H