1*9880d681SAndroid Build Coastguard Worker //===- MCContext.h - Machine Code Context -----------------------*- C++ -*-===//
2*9880d681SAndroid Build Coastguard Worker //
3*9880d681SAndroid Build Coastguard Worker // The LLVM Compiler Infrastructure
4*9880d681SAndroid Build Coastguard Worker //
5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source
6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details.
7*9880d681SAndroid Build Coastguard Worker //
8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*9880d681SAndroid Build Coastguard Worker
10*9880d681SAndroid Build Coastguard Worker #ifndef LLVM_MC_MCCONTEXT_H
11*9880d681SAndroid Build Coastguard Worker #define LLVM_MC_MCCONTEXT_H
12*9880d681SAndroid Build Coastguard Worker
13*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/DenseMap.h"
14*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/SetVector.h"
15*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/SmallString.h"
16*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/SmallVector.h"
17*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/StringMap.h"
18*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/Twine.h"
19*9880d681SAndroid Build Coastguard Worker #include "llvm/MC/MCCodeView.h"
20*9880d681SAndroid Build Coastguard Worker #include "llvm/MC/MCDwarf.h"
21*9880d681SAndroid Build Coastguard Worker #include "llvm/MC/MCSubtargetInfo.h"
22*9880d681SAndroid Build Coastguard Worker #include "llvm/MC/SectionKind.h"
23*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/Allocator.h"
24*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/Compiler.h"
25*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/raw_ostream.h"
26*9880d681SAndroid Build Coastguard Worker #include <map>
27*9880d681SAndroid Build Coastguard Worker #include <tuple>
28*9880d681SAndroid Build Coastguard Worker #include <vector> // FIXME: Shouldn't be needed.
29*9880d681SAndroid Build Coastguard Worker
30*9880d681SAndroid Build Coastguard Worker namespace llvm {
31*9880d681SAndroid Build Coastguard Worker class MCAsmInfo;
32*9880d681SAndroid Build Coastguard Worker class MCExpr;
33*9880d681SAndroid Build Coastguard Worker class MCSection;
34*9880d681SAndroid Build Coastguard Worker class MCSymbol;
35*9880d681SAndroid Build Coastguard Worker class MCSymbolELF;
36*9880d681SAndroid Build Coastguard Worker class MCLabel;
37*9880d681SAndroid Build Coastguard Worker struct MCDwarfFile;
38*9880d681SAndroid Build Coastguard Worker class MCDwarfLoc;
39*9880d681SAndroid Build Coastguard Worker class MCObjectFileInfo;
40*9880d681SAndroid Build Coastguard Worker class MCRegisterInfo;
41*9880d681SAndroid Build Coastguard Worker class MCLineSection;
42*9880d681SAndroid Build Coastguard Worker class SMLoc;
43*9880d681SAndroid Build Coastguard Worker class MCSectionMachO;
44*9880d681SAndroid Build Coastguard Worker class MCSectionELF;
45*9880d681SAndroid Build Coastguard Worker class MCSectionCOFF;
46*9880d681SAndroid Build Coastguard Worker class CodeViewContext;
47*9880d681SAndroid Build Coastguard Worker
48*9880d681SAndroid Build Coastguard Worker /// Context object for machine code objects. This class owns all of the
49*9880d681SAndroid Build Coastguard Worker /// sections that it creates.
50*9880d681SAndroid Build Coastguard Worker ///
51*9880d681SAndroid Build Coastguard Worker class MCContext {
52*9880d681SAndroid Build Coastguard Worker MCContext(const MCContext &) = delete;
53*9880d681SAndroid Build Coastguard Worker MCContext &operator=(const MCContext &) = delete;
54*9880d681SAndroid Build Coastguard Worker
55*9880d681SAndroid Build Coastguard Worker public:
56*9880d681SAndroid Build Coastguard Worker typedef StringMap<MCSymbol *, BumpPtrAllocator &> SymbolTable;
57*9880d681SAndroid Build Coastguard Worker
58*9880d681SAndroid Build Coastguard Worker private:
59*9880d681SAndroid Build Coastguard Worker /// The SourceMgr for this object, if any.
60*9880d681SAndroid Build Coastguard Worker const SourceMgr *SrcMgr;
61*9880d681SAndroid Build Coastguard Worker
62*9880d681SAndroid Build Coastguard Worker /// The MCAsmInfo for this target.
63*9880d681SAndroid Build Coastguard Worker const MCAsmInfo *MAI;
64*9880d681SAndroid Build Coastguard Worker
65*9880d681SAndroid Build Coastguard Worker /// The MCRegisterInfo for this target.
66*9880d681SAndroid Build Coastguard Worker const MCRegisterInfo *MRI;
67*9880d681SAndroid Build Coastguard Worker
68*9880d681SAndroid Build Coastguard Worker /// The MCObjectFileInfo for this target.
69*9880d681SAndroid Build Coastguard Worker const MCObjectFileInfo *MOFI;
70*9880d681SAndroid Build Coastguard Worker
71*9880d681SAndroid Build Coastguard Worker std::unique_ptr<CodeViewContext> CVContext;
72*9880d681SAndroid Build Coastguard Worker
73*9880d681SAndroid Build Coastguard Worker /// Allocator object used for creating machine code objects.
74*9880d681SAndroid Build Coastguard Worker ///
75*9880d681SAndroid Build Coastguard Worker /// We use a bump pointer allocator to avoid the need to track all allocated
76*9880d681SAndroid Build Coastguard Worker /// objects.
77*9880d681SAndroid Build Coastguard Worker BumpPtrAllocator Allocator;
78*9880d681SAndroid Build Coastguard Worker
79*9880d681SAndroid Build Coastguard Worker SpecificBumpPtrAllocator<MCSectionCOFF> COFFAllocator;
80*9880d681SAndroid Build Coastguard Worker SpecificBumpPtrAllocator<MCSectionELF> ELFAllocator;
81*9880d681SAndroid Build Coastguard Worker SpecificBumpPtrAllocator<MCSectionMachO> MachOAllocator;
82*9880d681SAndroid Build Coastguard Worker
83*9880d681SAndroid Build Coastguard Worker /// Bindings of names to symbols.
84*9880d681SAndroid Build Coastguard Worker SymbolTable Symbols;
85*9880d681SAndroid Build Coastguard Worker
86*9880d681SAndroid Build Coastguard Worker /// ELF sections can have a corresponding symbol. This maps one to the
87*9880d681SAndroid Build Coastguard Worker /// other.
88*9880d681SAndroid Build Coastguard Worker DenseMap<const MCSectionELF *, MCSymbolELF *> SectionSymbols;
89*9880d681SAndroid Build Coastguard Worker
90*9880d681SAndroid Build Coastguard Worker /// A mapping from a local label number and an instance count to a symbol.
91*9880d681SAndroid Build Coastguard Worker /// For example, in the assembly
92*9880d681SAndroid Build Coastguard Worker /// 1:
93*9880d681SAndroid Build Coastguard Worker /// 2:
94*9880d681SAndroid Build Coastguard Worker /// 1:
95*9880d681SAndroid Build Coastguard Worker /// We have three labels represented by the pairs (1, 0), (2, 0) and (1, 1)
96*9880d681SAndroid Build Coastguard Worker DenseMap<std::pair<unsigned, unsigned>, MCSymbol *> LocalSymbols;
97*9880d681SAndroid Build Coastguard Worker
98*9880d681SAndroid Build Coastguard Worker /// Keeps tracks of names that were used both for used declared and
99*9880d681SAndroid Build Coastguard Worker /// artificial symbols. The value is "true" if the name has been used for a
100*9880d681SAndroid Build Coastguard Worker /// non-section symbol (there can be at most one of those, plus an unlimited
101*9880d681SAndroid Build Coastguard Worker /// number of section symbols with the same name).
102*9880d681SAndroid Build Coastguard Worker StringMap<bool, BumpPtrAllocator &> UsedNames;
103*9880d681SAndroid Build Coastguard Worker
104*9880d681SAndroid Build Coastguard Worker /// The next ID to dole out to an unnamed assembler temporary symbol with
105*9880d681SAndroid Build Coastguard Worker /// a given prefix.
106*9880d681SAndroid Build Coastguard Worker StringMap<unsigned> NextID;
107*9880d681SAndroid Build Coastguard Worker
108*9880d681SAndroid Build Coastguard Worker /// Instances of directional local labels.
109*9880d681SAndroid Build Coastguard Worker DenseMap<unsigned, MCLabel *> Instances;
110*9880d681SAndroid Build Coastguard Worker /// NextInstance() creates the next instance of the directional local label
111*9880d681SAndroid Build Coastguard Worker /// for the LocalLabelVal and adds it to the map if needed.
112*9880d681SAndroid Build Coastguard Worker unsigned NextInstance(unsigned LocalLabelVal);
113*9880d681SAndroid Build Coastguard Worker /// GetInstance() gets the current instance of the directional local label
114*9880d681SAndroid Build Coastguard Worker /// for the LocalLabelVal and adds it to the map if needed.
115*9880d681SAndroid Build Coastguard Worker unsigned GetInstance(unsigned LocalLabelVal);
116*9880d681SAndroid Build Coastguard Worker
117*9880d681SAndroid Build Coastguard Worker /// The file name of the log file from the environment variable
118*9880d681SAndroid Build Coastguard Worker /// AS_SECURE_LOG_FILE. Which must be set before the .secure_log_unique
119*9880d681SAndroid Build Coastguard Worker /// directive is used or it is an error.
120*9880d681SAndroid Build Coastguard Worker char *SecureLogFile;
121*9880d681SAndroid Build Coastguard Worker /// The stream that gets written to for the .secure_log_unique directive.
122*9880d681SAndroid Build Coastguard Worker std::unique_ptr<raw_fd_ostream> SecureLog;
123*9880d681SAndroid Build Coastguard Worker /// Boolean toggled when .secure_log_unique / .secure_log_reset is seen to
124*9880d681SAndroid Build Coastguard Worker /// catch errors if .secure_log_unique appears twice without
125*9880d681SAndroid Build Coastguard Worker /// .secure_log_reset appearing between them.
126*9880d681SAndroid Build Coastguard Worker bool SecureLogUsed;
127*9880d681SAndroid Build Coastguard Worker
128*9880d681SAndroid Build Coastguard Worker /// The compilation directory to use for DW_AT_comp_dir.
129*9880d681SAndroid Build Coastguard Worker SmallString<128> CompilationDir;
130*9880d681SAndroid Build Coastguard Worker
131*9880d681SAndroid Build Coastguard Worker /// The main file name if passed in explicitly.
132*9880d681SAndroid Build Coastguard Worker std::string MainFileName;
133*9880d681SAndroid Build Coastguard Worker
134*9880d681SAndroid Build Coastguard Worker /// The dwarf file and directory tables from the dwarf .file directive.
135*9880d681SAndroid Build Coastguard Worker /// We now emit a line table for each compile unit. To reduce the prologue
136*9880d681SAndroid Build Coastguard Worker /// size of each line table, the files and directories used by each compile
137*9880d681SAndroid Build Coastguard Worker /// unit are separated.
138*9880d681SAndroid Build Coastguard Worker std::map<unsigned, MCDwarfLineTable> MCDwarfLineTablesCUMap;
139*9880d681SAndroid Build Coastguard Worker
140*9880d681SAndroid Build Coastguard Worker /// The current dwarf line information from the last dwarf .loc directive.
141*9880d681SAndroid Build Coastguard Worker MCDwarfLoc CurrentDwarfLoc;
142*9880d681SAndroid Build Coastguard Worker bool DwarfLocSeen;
143*9880d681SAndroid Build Coastguard Worker
144*9880d681SAndroid Build Coastguard Worker /// The current CodeView line information from the last .cv_loc directive.
145*9880d681SAndroid Build Coastguard Worker MCCVLoc CurrentCVLoc = MCCVLoc(0, 0, 0, 0, false, true);
146*9880d681SAndroid Build Coastguard Worker bool CVLocSeen = false;
147*9880d681SAndroid Build Coastguard Worker
148*9880d681SAndroid Build Coastguard Worker /// Generate dwarf debugging info for assembly source files.
149*9880d681SAndroid Build Coastguard Worker bool GenDwarfForAssembly;
150*9880d681SAndroid Build Coastguard Worker
151*9880d681SAndroid Build Coastguard Worker /// The current dwarf file number when generate dwarf debugging info for
152*9880d681SAndroid Build Coastguard Worker /// assembly source files.
153*9880d681SAndroid Build Coastguard Worker unsigned GenDwarfFileNumber;
154*9880d681SAndroid Build Coastguard Worker
155*9880d681SAndroid Build Coastguard Worker /// Sections for generating the .debug_ranges and .debug_aranges sections.
156*9880d681SAndroid Build Coastguard Worker SetVector<MCSection *> SectionsForRanges;
157*9880d681SAndroid Build Coastguard Worker
158*9880d681SAndroid Build Coastguard Worker /// The information gathered from labels that will have dwarf label
159*9880d681SAndroid Build Coastguard Worker /// entries when generating dwarf assembly source files.
160*9880d681SAndroid Build Coastguard Worker std::vector<MCGenDwarfLabelEntry> MCGenDwarfLabelEntries;
161*9880d681SAndroid Build Coastguard Worker
162*9880d681SAndroid Build Coastguard Worker /// The string to embed in the debug information for the compile unit, if
163*9880d681SAndroid Build Coastguard Worker /// non-empty.
164*9880d681SAndroid Build Coastguard Worker StringRef DwarfDebugFlags;
165*9880d681SAndroid Build Coastguard Worker
166*9880d681SAndroid Build Coastguard Worker /// The string to embed in as the dwarf AT_producer for the compile unit, if
167*9880d681SAndroid Build Coastguard Worker /// non-empty.
168*9880d681SAndroid Build Coastguard Worker StringRef DwarfDebugProducer;
169*9880d681SAndroid Build Coastguard Worker
170*9880d681SAndroid Build Coastguard Worker /// The maximum version of dwarf that we should emit.
171*9880d681SAndroid Build Coastguard Worker uint16_t DwarfVersion;
172*9880d681SAndroid Build Coastguard Worker
173*9880d681SAndroid Build Coastguard Worker /// Honor temporary labels, this is useful for debugging semantic
174*9880d681SAndroid Build Coastguard Worker /// differences between temporary and non-temporary labels (primarily on
175*9880d681SAndroid Build Coastguard Worker /// Darwin).
176*9880d681SAndroid Build Coastguard Worker bool AllowTemporaryLabels;
177*9880d681SAndroid Build Coastguard Worker bool UseNamesOnTempLabels = true;
178*9880d681SAndroid Build Coastguard Worker
179*9880d681SAndroid Build Coastguard Worker /// The Compile Unit ID that we are currently processing.
180*9880d681SAndroid Build Coastguard Worker unsigned DwarfCompileUnitID;
181*9880d681SAndroid Build Coastguard Worker
182*9880d681SAndroid Build Coastguard Worker struct ELFSectionKey {
183*9880d681SAndroid Build Coastguard Worker std::string SectionName;
184*9880d681SAndroid Build Coastguard Worker StringRef GroupName;
185*9880d681SAndroid Build Coastguard Worker unsigned UniqueID;
ELFSectionKeyELFSectionKey186*9880d681SAndroid Build Coastguard Worker ELFSectionKey(StringRef SectionName, StringRef GroupName,
187*9880d681SAndroid Build Coastguard Worker unsigned UniqueID)
188*9880d681SAndroid Build Coastguard Worker : SectionName(SectionName), GroupName(GroupName), UniqueID(UniqueID) {
189*9880d681SAndroid Build Coastguard Worker }
190*9880d681SAndroid Build Coastguard Worker bool operator<(const ELFSectionKey &Other) const {
191*9880d681SAndroid Build Coastguard Worker if (SectionName != Other.SectionName)
192*9880d681SAndroid Build Coastguard Worker return SectionName < Other.SectionName;
193*9880d681SAndroid Build Coastguard Worker if (GroupName != Other.GroupName)
194*9880d681SAndroid Build Coastguard Worker return GroupName < Other.GroupName;
195*9880d681SAndroid Build Coastguard Worker return UniqueID < Other.UniqueID;
196*9880d681SAndroid Build Coastguard Worker }
197*9880d681SAndroid Build Coastguard Worker };
198*9880d681SAndroid Build Coastguard Worker
199*9880d681SAndroid Build Coastguard Worker struct COFFSectionKey {
200*9880d681SAndroid Build Coastguard Worker std::string SectionName;
201*9880d681SAndroid Build Coastguard Worker StringRef GroupName;
202*9880d681SAndroid Build Coastguard Worker int SelectionKey;
203*9880d681SAndroid Build Coastguard Worker unsigned UniqueID;
COFFSectionKeyCOFFSectionKey204*9880d681SAndroid Build Coastguard Worker COFFSectionKey(StringRef SectionName, StringRef GroupName,
205*9880d681SAndroid Build Coastguard Worker int SelectionKey, unsigned UniqueID)
206*9880d681SAndroid Build Coastguard Worker : SectionName(SectionName), GroupName(GroupName),
207*9880d681SAndroid Build Coastguard Worker SelectionKey(SelectionKey), UniqueID(UniqueID) {}
208*9880d681SAndroid Build Coastguard Worker bool operator<(const COFFSectionKey &Other) const {
209*9880d681SAndroid Build Coastguard Worker if (SectionName != Other.SectionName)
210*9880d681SAndroid Build Coastguard Worker return SectionName < Other.SectionName;
211*9880d681SAndroid Build Coastguard Worker if (GroupName != Other.GroupName)
212*9880d681SAndroid Build Coastguard Worker return GroupName < Other.GroupName;
213*9880d681SAndroid Build Coastguard Worker if (SelectionKey != Other.SelectionKey)
214*9880d681SAndroid Build Coastguard Worker return SelectionKey < Other.SelectionKey;
215*9880d681SAndroid Build Coastguard Worker return UniqueID < Other.UniqueID;
216*9880d681SAndroid Build Coastguard Worker }
217*9880d681SAndroid Build Coastguard Worker };
218*9880d681SAndroid Build Coastguard Worker
219*9880d681SAndroid Build Coastguard Worker StringMap<MCSectionMachO *> MachOUniquingMap;
220*9880d681SAndroid Build Coastguard Worker std::map<ELFSectionKey, MCSectionELF *> ELFUniquingMap;
221*9880d681SAndroid Build Coastguard Worker std::map<COFFSectionKey, MCSectionCOFF *> COFFUniquingMap;
222*9880d681SAndroid Build Coastguard Worker StringMap<bool> ELFRelSecNames;
223*9880d681SAndroid Build Coastguard Worker
224*9880d681SAndroid Build Coastguard Worker SpecificBumpPtrAllocator<MCSubtargetInfo> MCSubtargetAllocator;
225*9880d681SAndroid Build Coastguard Worker
226*9880d681SAndroid Build Coastguard Worker /// Do automatic reset in destructor
227*9880d681SAndroid Build Coastguard Worker bool AutoReset;
228*9880d681SAndroid Build Coastguard Worker
229*9880d681SAndroid Build Coastguard Worker bool HadError;
230*9880d681SAndroid Build Coastguard Worker
231*9880d681SAndroid Build Coastguard Worker MCSymbol *createSymbolImpl(const StringMapEntry<bool> *Name,
232*9880d681SAndroid Build Coastguard Worker bool CanBeUnnamed);
233*9880d681SAndroid Build Coastguard Worker MCSymbol *createSymbol(StringRef Name, bool AlwaysAddSuffix,
234*9880d681SAndroid Build Coastguard Worker bool IsTemporary);
235*9880d681SAndroid Build Coastguard Worker
236*9880d681SAndroid Build Coastguard Worker MCSymbol *getOrCreateDirectionalLocalSymbol(unsigned LocalLabelVal,
237*9880d681SAndroid Build Coastguard Worker unsigned Instance);
238*9880d681SAndroid Build Coastguard Worker
239*9880d681SAndroid Build Coastguard Worker public:
240*9880d681SAndroid Build Coastguard Worker explicit MCContext(const MCAsmInfo *MAI, const MCRegisterInfo *MRI,
241*9880d681SAndroid Build Coastguard Worker const MCObjectFileInfo *MOFI,
242*9880d681SAndroid Build Coastguard Worker const SourceMgr *Mgr = nullptr, bool DoAutoReset = true);
243*9880d681SAndroid Build Coastguard Worker ~MCContext();
244*9880d681SAndroid Build Coastguard Worker
getSourceManager()245*9880d681SAndroid Build Coastguard Worker const SourceMgr *getSourceManager() const { return SrcMgr; }
246*9880d681SAndroid Build Coastguard Worker
getAsmInfo()247*9880d681SAndroid Build Coastguard Worker const MCAsmInfo *getAsmInfo() const { return MAI; }
248*9880d681SAndroid Build Coastguard Worker
getRegisterInfo()249*9880d681SAndroid Build Coastguard Worker const MCRegisterInfo *getRegisterInfo() const { return MRI; }
250*9880d681SAndroid Build Coastguard Worker
getObjectFileInfo()251*9880d681SAndroid Build Coastguard Worker const MCObjectFileInfo *getObjectFileInfo() const { return MOFI; }
252*9880d681SAndroid Build Coastguard Worker
253*9880d681SAndroid Build Coastguard Worker CodeViewContext &getCVContext();
254*9880d681SAndroid Build Coastguard Worker
setAllowTemporaryLabels(bool Value)255*9880d681SAndroid Build Coastguard Worker void setAllowTemporaryLabels(bool Value) { AllowTemporaryLabels = Value; }
setUseNamesOnTempLabels(bool Value)256*9880d681SAndroid Build Coastguard Worker void setUseNamesOnTempLabels(bool Value) { UseNamesOnTempLabels = Value; }
257*9880d681SAndroid Build Coastguard Worker
258*9880d681SAndroid Build Coastguard Worker /// \name Module Lifetime Management
259*9880d681SAndroid Build Coastguard Worker /// @{
260*9880d681SAndroid Build Coastguard Worker
261*9880d681SAndroid Build Coastguard Worker /// reset - return object to right after construction state to prepare
262*9880d681SAndroid Build Coastguard Worker /// to process a new module
263*9880d681SAndroid Build Coastguard Worker void reset();
264*9880d681SAndroid Build Coastguard Worker
265*9880d681SAndroid Build Coastguard Worker /// @}
266*9880d681SAndroid Build Coastguard Worker
267*9880d681SAndroid Build Coastguard Worker /// \name Symbol Management
268*9880d681SAndroid Build Coastguard Worker /// @{
269*9880d681SAndroid Build Coastguard Worker
270*9880d681SAndroid Build Coastguard Worker /// Create and return a new linker temporary symbol with a unique but
271*9880d681SAndroid Build Coastguard Worker /// unspecified name.
272*9880d681SAndroid Build Coastguard Worker MCSymbol *createLinkerPrivateTempSymbol();
273*9880d681SAndroid Build Coastguard Worker
274*9880d681SAndroid Build Coastguard Worker /// Create and return a new assembler temporary symbol with a unique but
275*9880d681SAndroid Build Coastguard Worker /// unspecified name.
276*9880d681SAndroid Build Coastguard Worker MCSymbol *createTempSymbol(bool CanBeUnnamed = true);
277*9880d681SAndroid Build Coastguard Worker
278*9880d681SAndroid Build Coastguard Worker MCSymbol *createTempSymbol(const Twine &Name, bool AlwaysAddSuffix,
279*9880d681SAndroid Build Coastguard Worker bool CanBeUnnamed = true);
280*9880d681SAndroid Build Coastguard Worker
281*9880d681SAndroid Build Coastguard Worker /// Create the definition of a directional local symbol for numbered label
282*9880d681SAndroid Build Coastguard Worker /// (used for "1:" definitions).
283*9880d681SAndroid Build Coastguard Worker MCSymbol *createDirectionalLocalSymbol(unsigned LocalLabelVal);
284*9880d681SAndroid Build Coastguard Worker
285*9880d681SAndroid Build Coastguard Worker /// Create and return a directional local symbol for numbered label (used
286*9880d681SAndroid Build Coastguard Worker /// for "1b" or 1f" references).
287*9880d681SAndroid Build Coastguard Worker MCSymbol *getDirectionalLocalSymbol(unsigned LocalLabelVal, bool Before);
288*9880d681SAndroid Build Coastguard Worker
289*9880d681SAndroid Build Coastguard Worker /// Lookup the symbol inside with the specified \p Name. If it exists,
290*9880d681SAndroid Build Coastguard Worker /// return it. If not, create a forward reference and return it.
291*9880d681SAndroid Build Coastguard Worker ///
292*9880d681SAndroid Build Coastguard Worker /// \param Name - The symbol name, which must be unique across all symbols.
293*9880d681SAndroid Build Coastguard Worker MCSymbol *getOrCreateSymbol(const Twine &Name);
294*9880d681SAndroid Build Coastguard Worker
295*9880d681SAndroid Build Coastguard Worker MCSymbolELF *getOrCreateSectionSymbol(const MCSectionELF &Section);
296*9880d681SAndroid Build Coastguard Worker
297*9880d681SAndroid Build Coastguard Worker /// Gets a symbol that will be defined to the final stack offset of a local
298*9880d681SAndroid Build Coastguard Worker /// variable after codegen.
299*9880d681SAndroid Build Coastguard Worker ///
300*9880d681SAndroid Build Coastguard Worker /// \param Idx - The index of a local variable passed to @llvm.localescape.
301*9880d681SAndroid Build Coastguard Worker MCSymbol *getOrCreateFrameAllocSymbol(StringRef FuncName, unsigned Idx);
302*9880d681SAndroid Build Coastguard Worker
303*9880d681SAndroid Build Coastguard Worker MCSymbol *getOrCreateParentFrameOffsetSymbol(StringRef FuncName);
304*9880d681SAndroid Build Coastguard Worker
305*9880d681SAndroid Build Coastguard Worker MCSymbol *getOrCreateLSDASymbol(StringRef FuncName);
306*9880d681SAndroid Build Coastguard Worker
307*9880d681SAndroid Build Coastguard Worker /// Get the symbol for \p Name, or null.
308*9880d681SAndroid Build Coastguard Worker MCSymbol *lookupSymbol(const Twine &Name) const;
309*9880d681SAndroid Build Coastguard Worker
310*9880d681SAndroid Build Coastguard Worker /// getSymbols - Get a reference for the symbol table for clients that
311*9880d681SAndroid Build Coastguard Worker /// want to, for example, iterate over all symbols. 'const' because we
312*9880d681SAndroid Build Coastguard Worker /// still want any modifications to the table itself to use the MCContext
313*9880d681SAndroid Build Coastguard Worker /// APIs.
getSymbols()314*9880d681SAndroid Build Coastguard Worker const SymbolTable &getSymbols() const { return Symbols; }
315*9880d681SAndroid Build Coastguard Worker
316*9880d681SAndroid Build Coastguard Worker /// @}
317*9880d681SAndroid Build Coastguard Worker
318*9880d681SAndroid Build Coastguard Worker /// \name Section Management
319*9880d681SAndroid Build Coastguard Worker /// @{
320*9880d681SAndroid Build Coastguard Worker
321*9880d681SAndroid Build Coastguard Worker enum : unsigned {
322*9880d681SAndroid Build Coastguard Worker /// Pass this value as the UniqueID during section creation to get the
323*9880d681SAndroid Build Coastguard Worker /// generic section with the given name and characteristics. The usual
324*9880d681SAndroid Build Coastguard Worker /// sections such as .text use this ID.
325*9880d681SAndroid Build Coastguard Worker GenericSectionID = ~0U
326*9880d681SAndroid Build Coastguard Worker };
327*9880d681SAndroid Build Coastguard Worker
328*9880d681SAndroid Build Coastguard Worker /// Return the MCSection for the specified mach-o section. This requires
329*9880d681SAndroid Build Coastguard Worker /// the operands to be valid.
330*9880d681SAndroid Build Coastguard Worker MCSectionMachO *getMachOSection(StringRef Segment, StringRef Section,
331*9880d681SAndroid Build Coastguard Worker unsigned TypeAndAttributes,
332*9880d681SAndroid Build Coastguard Worker unsigned Reserved2, SectionKind K,
333*9880d681SAndroid Build Coastguard Worker const char *BeginSymName = nullptr);
334*9880d681SAndroid Build Coastguard Worker
335*9880d681SAndroid Build Coastguard Worker MCSectionMachO *getMachOSection(StringRef Segment, StringRef Section,
336*9880d681SAndroid Build Coastguard Worker unsigned TypeAndAttributes, SectionKind K,
337*9880d681SAndroid Build Coastguard Worker const char *BeginSymName = nullptr) {
338*9880d681SAndroid Build Coastguard Worker return getMachOSection(Segment, Section, TypeAndAttributes, 0, K,
339*9880d681SAndroid Build Coastguard Worker BeginSymName);
340*9880d681SAndroid Build Coastguard Worker }
341*9880d681SAndroid Build Coastguard Worker
getELFSection(const Twine & Section,unsigned Type,unsigned Flags)342*9880d681SAndroid Build Coastguard Worker MCSectionELF *getELFSection(const Twine &Section, unsigned Type,
343*9880d681SAndroid Build Coastguard Worker unsigned Flags) {
344*9880d681SAndroid Build Coastguard Worker return getELFSection(Section, Type, Flags, nullptr);
345*9880d681SAndroid Build Coastguard Worker }
346*9880d681SAndroid Build Coastguard Worker
getELFSection(const Twine & Section,unsigned Type,unsigned Flags,const char * BeginSymName)347*9880d681SAndroid Build Coastguard Worker MCSectionELF *getELFSection(const Twine &Section, unsigned Type,
348*9880d681SAndroid Build Coastguard Worker unsigned Flags, const char *BeginSymName) {
349*9880d681SAndroid Build Coastguard Worker return getELFSection(Section, Type, Flags, 0, "", BeginSymName);
350*9880d681SAndroid Build Coastguard Worker }
351*9880d681SAndroid Build Coastguard Worker
getELFSection(const Twine & Section,unsigned Type,unsigned Flags,unsigned EntrySize,const Twine & Group)352*9880d681SAndroid Build Coastguard Worker MCSectionELF *getELFSection(const Twine &Section, unsigned Type,
353*9880d681SAndroid Build Coastguard Worker unsigned Flags, unsigned EntrySize,
354*9880d681SAndroid Build Coastguard Worker const Twine &Group) {
355*9880d681SAndroid Build Coastguard Worker return getELFSection(Section, Type, Flags, EntrySize, Group, nullptr);
356*9880d681SAndroid Build Coastguard Worker }
357*9880d681SAndroid Build Coastguard Worker
getELFSection(const Twine & Section,unsigned Type,unsigned Flags,unsigned EntrySize,const Twine & Group,const char * BeginSymName)358*9880d681SAndroid Build Coastguard Worker MCSectionELF *getELFSection(const Twine &Section, unsigned Type,
359*9880d681SAndroid Build Coastguard Worker unsigned Flags, unsigned EntrySize,
360*9880d681SAndroid Build Coastguard Worker const Twine &Group, const char *BeginSymName) {
361*9880d681SAndroid Build Coastguard Worker return getELFSection(Section, Type, Flags, EntrySize, Group, ~0,
362*9880d681SAndroid Build Coastguard Worker BeginSymName);
363*9880d681SAndroid Build Coastguard Worker }
364*9880d681SAndroid Build Coastguard Worker
getELFSection(const Twine & Section,unsigned Type,unsigned Flags,unsigned EntrySize,const Twine & Group,unsigned UniqueID)365*9880d681SAndroid Build Coastguard Worker MCSectionELF *getELFSection(const Twine &Section, unsigned Type,
366*9880d681SAndroid Build Coastguard Worker unsigned Flags, unsigned EntrySize,
367*9880d681SAndroid Build Coastguard Worker const Twine &Group, unsigned UniqueID) {
368*9880d681SAndroid Build Coastguard Worker return getELFSection(Section, Type, Flags, EntrySize, Group, UniqueID,
369*9880d681SAndroid Build Coastguard Worker nullptr);
370*9880d681SAndroid Build Coastguard Worker }
371*9880d681SAndroid Build Coastguard Worker
372*9880d681SAndroid Build Coastguard Worker MCSectionELF *getELFSection(const Twine &Section, unsigned Type,
373*9880d681SAndroid Build Coastguard Worker unsigned Flags, unsigned EntrySize,
374*9880d681SAndroid Build Coastguard Worker const Twine &Group, unsigned UniqueID,
375*9880d681SAndroid Build Coastguard Worker const char *BeginSymName);
376*9880d681SAndroid Build Coastguard Worker
377*9880d681SAndroid Build Coastguard Worker MCSectionELF *getELFSection(const Twine &Section, unsigned Type,
378*9880d681SAndroid Build Coastguard Worker unsigned Flags, unsigned EntrySize,
379*9880d681SAndroid Build Coastguard Worker const MCSymbolELF *Group, unsigned UniqueID,
380*9880d681SAndroid Build Coastguard Worker const char *BeginSymName,
381*9880d681SAndroid Build Coastguard Worker const MCSectionELF *Associated);
382*9880d681SAndroid Build Coastguard Worker
383*9880d681SAndroid Build Coastguard Worker /// Get a section with the provided group identifier. This section is
384*9880d681SAndroid Build Coastguard Worker /// named by concatenating \p Prefix with '.' then \p Suffix. The \p Type
385*9880d681SAndroid Build Coastguard Worker /// describes the type of the section and \p Flags are used to further
386*9880d681SAndroid Build Coastguard Worker /// configure this named section.
387*9880d681SAndroid Build Coastguard Worker MCSectionELF *getELFNamedSection(const Twine &Prefix, const Twine &Suffix,
388*9880d681SAndroid Build Coastguard Worker unsigned Type, unsigned Flags,
389*9880d681SAndroid Build Coastguard Worker unsigned EntrySize = 0);
390*9880d681SAndroid Build Coastguard Worker
391*9880d681SAndroid Build Coastguard Worker MCSectionELF *createELFRelSection(const Twine &Name, unsigned Type,
392*9880d681SAndroid Build Coastguard Worker unsigned Flags, unsigned EntrySize,
393*9880d681SAndroid Build Coastguard Worker const MCSymbolELF *Group,
394*9880d681SAndroid Build Coastguard Worker const MCSectionELF *Associated);
395*9880d681SAndroid Build Coastguard Worker
396*9880d681SAndroid Build Coastguard Worker void renameELFSection(MCSectionELF *Section, StringRef Name);
397*9880d681SAndroid Build Coastguard Worker
398*9880d681SAndroid Build Coastguard Worker MCSectionELF *createELFGroupSection(const MCSymbolELF *Group);
399*9880d681SAndroid Build Coastguard Worker
400*9880d681SAndroid Build Coastguard Worker MCSectionCOFF *getCOFFSection(StringRef Section, unsigned Characteristics,
401*9880d681SAndroid Build Coastguard Worker SectionKind Kind, StringRef COMDATSymName,
402*9880d681SAndroid Build Coastguard Worker int Selection,
403*9880d681SAndroid Build Coastguard Worker unsigned UniqueID = GenericSectionID,
404*9880d681SAndroid Build Coastguard Worker const char *BeginSymName = nullptr);
405*9880d681SAndroid Build Coastguard Worker
406*9880d681SAndroid Build Coastguard Worker MCSectionCOFF *getCOFFSection(StringRef Section, unsigned Characteristics,
407*9880d681SAndroid Build Coastguard Worker SectionKind Kind,
408*9880d681SAndroid Build Coastguard Worker const char *BeginSymName = nullptr);
409*9880d681SAndroid Build Coastguard Worker
410*9880d681SAndroid Build Coastguard Worker MCSectionCOFF *getCOFFSection(StringRef Section);
411*9880d681SAndroid Build Coastguard Worker
412*9880d681SAndroid Build Coastguard Worker /// Gets or creates a section equivalent to Sec that is associated with the
413*9880d681SAndroid Build Coastguard Worker /// section containing KeySym. For example, to create a debug info section
414*9880d681SAndroid Build Coastguard Worker /// associated with an inline function, pass the normal debug info section
415*9880d681SAndroid Build Coastguard Worker /// as Sec and the function symbol as KeySym.
416*9880d681SAndroid Build Coastguard Worker MCSectionCOFF *
417*9880d681SAndroid Build Coastguard Worker getAssociativeCOFFSection(MCSectionCOFF *Sec, const MCSymbol *KeySym,
418*9880d681SAndroid Build Coastguard Worker unsigned UniqueID = GenericSectionID);
419*9880d681SAndroid Build Coastguard Worker
420*9880d681SAndroid Build Coastguard Worker // Create and save a copy of STI and return a reference to the copy.
421*9880d681SAndroid Build Coastguard Worker MCSubtargetInfo &getSubtargetCopy(const MCSubtargetInfo &STI);
422*9880d681SAndroid Build Coastguard Worker
423*9880d681SAndroid Build Coastguard Worker /// @}
424*9880d681SAndroid Build Coastguard Worker
425*9880d681SAndroid Build Coastguard Worker /// \name Dwarf Management
426*9880d681SAndroid Build Coastguard Worker /// @{
427*9880d681SAndroid Build Coastguard Worker
428*9880d681SAndroid Build Coastguard Worker /// \brief Get the compilation directory for DW_AT_comp_dir
429*9880d681SAndroid Build Coastguard Worker /// The compilation directory should be set with \c setCompilationDir before
430*9880d681SAndroid Build Coastguard Worker /// calling this function. If it is unset, an empty string will be returned.
getCompilationDir()431*9880d681SAndroid Build Coastguard Worker StringRef getCompilationDir() const { return CompilationDir; }
432*9880d681SAndroid Build Coastguard Worker
433*9880d681SAndroid Build Coastguard Worker /// \brief Set the compilation directory for DW_AT_comp_dir
setCompilationDir(StringRef S)434*9880d681SAndroid Build Coastguard Worker void setCompilationDir(StringRef S) { CompilationDir = S.str(); }
435*9880d681SAndroid Build Coastguard Worker
436*9880d681SAndroid Build Coastguard Worker /// \brief Get the main file name for use in error messages and debug
437*9880d681SAndroid Build Coastguard Worker /// info. This can be set to ensure we've got the correct file name
438*9880d681SAndroid Build Coastguard Worker /// after preprocessing or for -save-temps.
getMainFileName()439*9880d681SAndroid Build Coastguard Worker const std::string &getMainFileName() const { return MainFileName; }
440*9880d681SAndroid Build Coastguard Worker
441*9880d681SAndroid Build Coastguard Worker /// \brief Set the main file name and override the default.
setMainFileName(StringRef S)442*9880d681SAndroid Build Coastguard Worker void setMainFileName(StringRef S) { MainFileName = S; }
443*9880d681SAndroid Build Coastguard Worker
444*9880d681SAndroid Build Coastguard Worker /// Creates an entry in the dwarf file and directory tables.
445*9880d681SAndroid Build Coastguard Worker unsigned getDwarfFile(StringRef Directory, StringRef FileName,
446*9880d681SAndroid Build Coastguard Worker unsigned FileNumber, unsigned CUID);
447*9880d681SAndroid Build Coastguard Worker
448*9880d681SAndroid Build Coastguard Worker bool isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID = 0);
449*9880d681SAndroid Build Coastguard Worker
getMCDwarfLineTables()450*9880d681SAndroid Build Coastguard Worker const std::map<unsigned, MCDwarfLineTable> &getMCDwarfLineTables() const {
451*9880d681SAndroid Build Coastguard Worker return MCDwarfLineTablesCUMap;
452*9880d681SAndroid Build Coastguard Worker }
453*9880d681SAndroid Build Coastguard Worker
getMCDwarfLineTable(unsigned CUID)454*9880d681SAndroid Build Coastguard Worker MCDwarfLineTable &getMCDwarfLineTable(unsigned CUID) {
455*9880d681SAndroid Build Coastguard Worker return MCDwarfLineTablesCUMap[CUID];
456*9880d681SAndroid Build Coastguard Worker }
457*9880d681SAndroid Build Coastguard Worker
getMCDwarfLineTable(unsigned CUID)458*9880d681SAndroid Build Coastguard Worker const MCDwarfLineTable &getMCDwarfLineTable(unsigned CUID) const {
459*9880d681SAndroid Build Coastguard Worker auto I = MCDwarfLineTablesCUMap.find(CUID);
460*9880d681SAndroid Build Coastguard Worker assert(I != MCDwarfLineTablesCUMap.end());
461*9880d681SAndroid Build Coastguard Worker return I->second;
462*9880d681SAndroid Build Coastguard Worker }
463*9880d681SAndroid Build Coastguard Worker
464*9880d681SAndroid Build Coastguard Worker const SmallVectorImpl<MCDwarfFile> &getMCDwarfFiles(unsigned CUID = 0) {
465*9880d681SAndroid Build Coastguard Worker return getMCDwarfLineTable(CUID).getMCDwarfFiles();
466*9880d681SAndroid Build Coastguard Worker }
467*9880d681SAndroid Build Coastguard Worker const SmallVectorImpl<std::string> &getMCDwarfDirs(unsigned CUID = 0) {
468*9880d681SAndroid Build Coastguard Worker return getMCDwarfLineTable(CUID).getMCDwarfDirs();
469*9880d681SAndroid Build Coastguard Worker }
470*9880d681SAndroid Build Coastguard Worker
hasMCLineSections()471*9880d681SAndroid Build Coastguard Worker bool hasMCLineSections() const {
472*9880d681SAndroid Build Coastguard Worker for (const auto &Table : MCDwarfLineTablesCUMap)
473*9880d681SAndroid Build Coastguard Worker if (!Table.second.getMCDwarfFiles().empty() || Table.second.getLabel())
474*9880d681SAndroid Build Coastguard Worker return true;
475*9880d681SAndroid Build Coastguard Worker return false;
476*9880d681SAndroid Build Coastguard Worker }
getDwarfCompileUnitID()477*9880d681SAndroid Build Coastguard Worker unsigned getDwarfCompileUnitID() { return DwarfCompileUnitID; }
setDwarfCompileUnitID(unsigned CUIndex)478*9880d681SAndroid Build Coastguard Worker void setDwarfCompileUnitID(unsigned CUIndex) {
479*9880d681SAndroid Build Coastguard Worker DwarfCompileUnitID = CUIndex;
480*9880d681SAndroid Build Coastguard Worker }
setMCLineTableCompilationDir(unsigned CUID,StringRef CompilationDir)481*9880d681SAndroid Build Coastguard Worker void setMCLineTableCompilationDir(unsigned CUID, StringRef CompilationDir) {
482*9880d681SAndroid Build Coastguard Worker getMCDwarfLineTable(CUID).setCompilationDir(CompilationDir);
483*9880d681SAndroid Build Coastguard Worker }
484*9880d681SAndroid Build Coastguard Worker
485*9880d681SAndroid Build Coastguard Worker /// Saves the information from the currently parsed dwarf .loc directive
486*9880d681SAndroid Build Coastguard Worker /// and sets DwarfLocSeen. When the next instruction is assembled an entry
487*9880d681SAndroid Build Coastguard Worker /// in the line number table with this information and the address of the
488*9880d681SAndroid Build Coastguard Worker /// instruction will be created.
setCurrentDwarfLoc(unsigned FileNum,unsigned Line,unsigned Column,unsigned Flags,unsigned Isa,unsigned Discriminator)489*9880d681SAndroid Build Coastguard Worker void setCurrentDwarfLoc(unsigned FileNum, unsigned Line, unsigned Column,
490*9880d681SAndroid Build Coastguard Worker unsigned Flags, unsigned Isa,
491*9880d681SAndroid Build Coastguard Worker unsigned Discriminator) {
492*9880d681SAndroid Build Coastguard Worker CurrentDwarfLoc.setFileNum(FileNum);
493*9880d681SAndroid Build Coastguard Worker CurrentDwarfLoc.setLine(Line);
494*9880d681SAndroid Build Coastguard Worker CurrentDwarfLoc.setColumn(Column);
495*9880d681SAndroid Build Coastguard Worker CurrentDwarfLoc.setFlags(Flags);
496*9880d681SAndroid Build Coastguard Worker CurrentDwarfLoc.setIsa(Isa);
497*9880d681SAndroid Build Coastguard Worker CurrentDwarfLoc.setDiscriminator(Discriminator);
498*9880d681SAndroid Build Coastguard Worker DwarfLocSeen = true;
499*9880d681SAndroid Build Coastguard Worker }
clearDwarfLocSeen()500*9880d681SAndroid Build Coastguard Worker void clearDwarfLocSeen() { DwarfLocSeen = false; }
501*9880d681SAndroid Build Coastguard Worker
getDwarfLocSeen()502*9880d681SAndroid Build Coastguard Worker bool getDwarfLocSeen() { return DwarfLocSeen; }
getCurrentDwarfLoc()503*9880d681SAndroid Build Coastguard Worker const MCDwarfLoc &getCurrentDwarfLoc() { return CurrentDwarfLoc; }
504*9880d681SAndroid Build Coastguard Worker
getGenDwarfForAssembly()505*9880d681SAndroid Build Coastguard Worker bool getGenDwarfForAssembly() { return GenDwarfForAssembly; }
setGenDwarfForAssembly(bool Value)506*9880d681SAndroid Build Coastguard Worker void setGenDwarfForAssembly(bool Value) { GenDwarfForAssembly = Value; }
getGenDwarfFileNumber()507*9880d681SAndroid Build Coastguard Worker unsigned getGenDwarfFileNumber() { return GenDwarfFileNumber; }
setGenDwarfFileNumber(unsigned FileNumber)508*9880d681SAndroid Build Coastguard Worker void setGenDwarfFileNumber(unsigned FileNumber) {
509*9880d681SAndroid Build Coastguard Worker GenDwarfFileNumber = FileNumber;
510*9880d681SAndroid Build Coastguard Worker }
getGenDwarfSectionSyms()511*9880d681SAndroid Build Coastguard Worker const SetVector<MCSection *> &getGenDwarfSectionSyms() {
512*9880d681SAndroid Build Coastguard Worker return SectionsForRanges;
513*9880d681SAndroid Build Coastguard Worker }
addGenDwarfSection(MCSection * Sec)514*9880d681SAndroid Build Coastguard Worker bool addGenDwarfSection(MCSection *Sec) {
515*9880d681SAndroid Build Coastguard Worker return SectionsForRanges.insert(Sec);
516*9880d681SAndroid Build Coastguard Worker }
517*9880d681SAndroid Build Coastguard Worker
518*9880d681SAndroid Build Coastguard Worker void finalizeDwarfSections(MCStreamer &MCOS);
getMCGenDwarfLabelEntries()519*9880d681SAndroid Build Coastguard Worker const std::vector<MCGenDwarfLabelEntry> &getMCGenDwarfLabelEntries() const {
520*9880d681SAndroid Build Coastguard Worker return MCGenDwarfLabelEntries;
521*9880d681SAndroid Build Coastguard Worker }
addMCGenDwarfLabelEntry(const MCGenDwarfLabelEntry & E)522*9880d681SAndroid Build Coastguard Worker void addMCGenDwarfLabelEntry(const MCGenDwarfLabelEntry &E) {
523*9880d681SAndroid Build Coastguard Worker MCGenDwarfLabelEntries.push_back(E);
524*9880d681SAndroid Build Coastguard Worker }
525*9880d681SAndroid Build Coastguard Worker
setDwarfDebugFlags(StringRef S)526*9880d681SAndroid Build Coastguard Worker void setDwarfDebugFlags(StringRef S) { DwarfDebugFlags = S; }
getDwarfDebugFlags()527*9880d681SAndroid Build Coastguard Worker StringRef getDwarfDebugFlags() { return DwarfDebugFlags; }
528*9880d681SAndroid Build Coastguard Worker
setDwarfDebugProducer(StringRef S)529*9880d681SAndroid Build Coastguard Worker void setDwarfDebugProducer(StringRef S) { DwarfDebugProducer = S; }
getDwarfDebugProducer()530*9880d681SAndroid Build Coastguard Worker StringRef getDwarfDebugProducer() { return DwarfDebugProducer; }
531*9880d681SAndroid Build Coastguard Worker
setDwarfVersion(uint16_t v)532*9880d681SAndroid Build Coastguard Worker void setDwarfVersion(uint16_t v) { DwarfVersion = v; }
getDwarfVersion()533*9880d681SAndroid Build Coastguard Worker uint16_t getDwarfVersion() const { return DwarfVersion; }
534*9880d681SAndroid Build Coastguard Worker
535*9880d681SAndroid Build Coastguard Worker /// @}
536*9880d681SAndroid Build Coastguard Worker
537*9880d681SAndroid Build Coastguard Worker
538*9880d681SAndroid Build Coastguard Worker /// \name CodeView Management
539*9880d681SAndroid Build Coastguard Worker /// @{
540*9880d681SAndroid Build Coastguard Worker
541*9880d681SAndroid Build Coastguard Worker /// Creates an entry in the cv file table.
542*9880d681SAndroid Build Coastguard Worker unsigned getCVFile(StringRef FileName, unsigned FileNumber);
543*9880d681SAndroid Build Coastguard Worker
544*9880d681SAndroid Build Coastguard Worker /// Saves the information from the currently parsed .cv_loc directive
545*9880d681SAndroid Build Coastguard Worker /// and sets CVLocSeen. When the next instruction is assembled an entry
546*9880d681SAndroid Build Coastguard Worker /// in the line number table with this information and the address of the
547*9880d681SAndroid Build Coastguard Worker /// instruction will be created.
setCurrentCVLoc(unsigned FunctionId,unsigned FileNo,unsigned Line,unsigned Column,bool PrologueEnd,bool IsStmt)548*9880d681SAndroid Build Coastguard Worker void setCurrentCVLoc(unsigned FunctionId, unsigned FileNo, unsigned Line,
549*9880d681SAndroid Build Coastguard Worker unsigned Column, bool PrologueEnd, bool IsStmt) {
550*9880d681SAndroid Build Coastguard Worker CurrentCVLoc.setFunctionId(FunctionId);
551*9880d681SAndroid Build Coastguard Worker CurrentCVLoc.setFileNum(FileNo);
552*9880d681SAndroid Build Coastguard Worker CurrentCVLoc.setLine(Line);
553*9880d681SAndroid Build Coastguard Worker CurrentCVLoc.setColumn(Column);
554*9880d681SAndroid Build Coastguard Worker CurrentCVLoc.setPrologueEnd(PrologueEnd);
555*9880d681SAndroid Build Coastguard Worker CurrentCVLoc.setIsStmt(IsStmt);
556*9880d681SAndroid Build Coastguard Worker CVLocSeen = true;
557*9880d681SAndroid Build Coastguard Worker }
clearCVLocSeen()558*9880d681SAndroid Build Coastguard Worker void clearCVLocSeen() { CVLocSeen = false; }
559*9880d681SAndroid Build Coastguard Worker
getCVLocSeen()560*9880d681SAndroid Build Coastguard Worker bool getCVLocSeen() { return CVLocSeen; }
getCurrentCVLoc()561*9880d681SAndroid Build Coastguard Worker const MCCVLoc &getCurrentCVLoc() { return CurrentCVLoc; }
562*9880d681SAndroid Build Coastguard Worker
563*9880d681SAndroid Build Coastguard Worker bool isValidCVFileNumber(unsigned FileNumber);
564*9880d681SAndroid Build Coastguard Worker /// @}
565*9880d681SAndroid Build Coastguard Worker
getSecureLogFile()566*9880d681SAndroid Build Coastguard Worker char *getSecureLogFile() { return SecureLogFile; }
getSecureLog()567*9880d681SAndroid Build Coastguard Worker raw_fd_ostream *getSecureLog() { return SecureLog.get(); }
getSecureLogUsed()568*9880d681SAndroid Build Coastguard Worker bool getSecureLogUsed() { return SecureLogUsed; }
setSecureLog(std::unique_ptr<raw_fd_ostream> Value)569*9880d681SAndroid Build Coastguard Worker void setSecureLog(std::unique_ptr<raw_fd_ostream> Value) {
570*9880d681SAndroid Build Coastguard Worker SecureLog = std::move(Value);
571*9880d681SAndroid Build Coastguard Worker }
setSecureLogUsed(bool Value)572*9880d681SAndroid Build Coastguard Worker void setSecureLogUsed(bool Value) { SecureLogUsed = Value; }
573*9880d681SAndroid Build Coastguard Worker
574*9880d681SAndroid Build Coastguard Worker void *allocate(unsigned Size, unsigned Align = 8) {
575*9880d681SAndroid Build Coastguard Worker return Allocator.Allocate(Size, Align);
576*9880d681SAndroid Build Coastguard Worker }
deallocate(void * Ptr)577*9880d681SAndroid Build Coastguard Worker void deallocate(void *Ptr) {}
578*9880d681SAndroid Build Coastguard Worker
hadError()579*9880d681SAndroid Build Coastguard Worker bool hadError() { return HadError; }
580*9880d681SAndroid Build Coastguard Worker void reportError(SMLoc L, const Twine &Msg);
581*9880d681SAndroid Build Coastguard Worker // Unrecoverable error has occurred. Display the best diagnostic we can
582*9880d681SAndroid Build Coastguard Worker // and bail via exit(1). For now, most MC backend errors are unrecoverable.
583*9880d681SAndroid Build Coastguard Worker // FIXME: We should really do something about that.
584*9880d681SAndroid Build Coastguard Worker LLVM_ATTRIBUTE_NORETURN void reportFatalError(SMLoc L,
585*9880d681SAndroid Build Coastguard Worker const Twine &Msg);
586*9880d681SAndroid Build Coastguard Worker };
587*9880d681SAndroid Build Coastguard Worker
588*9880d681SAndroid Build Coastguard Worker } // end namespace llvm
589*9880d681SAndroid Build Coastguard Worker
590*9880d681SAndroid Build Coastguard Worker // operator new and delete aren't allowed inside namespaces.
591*9880d681SAndroid Build Coastguard Worker // The throw specifications are mandated by the standard.
592*9880d681SAndroid Build Coastguard Worker /// \brief Placement new for using the MCContext's allocator.
593*9880d681SAndroid Build Coastguard Worker ///
594*9880d681SAndroid Build Coastguard Worker /// This placement form of operator new uses the MCContext's allocator for
595*9880d681SAndroid Build Coastguard Worker /// obtaining memory. It is a non-throwing new, which means that it returns
596*9880d681SAndroid Build Coastguard Worker /// null on error. (If that is what the allocator does. The current does, so if
597*9880d681SAndroid Build Coastguard Worker /// this ever changes, this operator will have to be changed, too.)
598*9880d681SAndroid Build Coastguard Worker /// Usage looks like this (assuming there's an MCContext 'Context' in scope):
599*9880d681SAndroid Build Coastguard Worker /// \code
600*9880d681SAndroid Build Coastguard Worker /// // Default alignment (8)
601*9880d681SAndroid Build Coastguard Worker /// IntegerLiteral *Ex = new (Context) IntegerLiteral(arguments);
602*9880d681SAndroid Build Coastguard Worker /// // Specific alignment
603*9880d681SAndroid Build Coastguard Worker /// IntegerLiteral *Ex2 = new (Context, 4) IntegerLiteral(arguments);
604*9880d681SAndroid Build Coastguard Worker /// \endcode
605*9880d681SAndroid Build Coastguard Worker /// Please note that you cannot use delete on the pointer; it must be
606*9880d681SAndroid Build Coastguard Worker /// deallocated using an explicit destructor call followed by
607*9880d681SAndroid Build Coastguard Worker /// \c Context.Deallocate(Ptr).
608*9880d681SAndroid Build Coastguard Worker ///
609*9880d681SAndroid Build Coastguard Worker /// \param Bytes The number of bytes to allocate. Calculated by the compiler.
610*9880d681SAndroid Build Coastguard Worker /// \param C The MCContext that provides the allocator.
611*9880d681SAndroid Build Coastguard Worker /// \param Alignment The alignment of the allocated memory (if the underlying
612*9880d681SAndroid Build Coastguard Worker /// allocator supports it).
613*9880d681SAndroid Build Coastguard Worker /// \return The allocated memory. Could be NULL.
614*9880d681SAndroid Build Coastguard Worker inline void *operator new(size_t Bytes, llvm::MCContext &C,
615*9880d681SAndroid Build Coastguard Worker size_t Alignment = 8) LLVM_NOEXCEPT {
616*9880d681SAndroid Build Coastguard Worker return C.allocate(Bytes, Alignment);
617*9880d681SAndroid Build Coastguard Worker }
618*9880d681SAndroid Build Coastguard Worker /// \brief Placement delete companion to the new above.
619*9880d681SAndroid Build Coastguard Worker ///
620*9880d681SAndroid Build Coastguard Worker /// This operator is just a companion to the new above. There is no way of
621*9880d681SAndroid Build Coastguard Worker /// invoking it directly; see the new operator for more details. This operator
622*9880d681SAndroid Build Coastguard Worker /// is called implicitly by the compiler if a placement new expression using
623*9880d681SAndroid Build Coastguard Worker /// the MCContext throws in the object constructor.
delete(void * Ptr,llvm::MCContext & C,size_t)624*9880d681SAndroid Build Coastguard Worker inline void operator delete(void *Ptr, llvm::MCContext &C,
625*9880d681SAndroid Build Coastguard Worker size_t) LLVM_NOEXCEPT {
626*9880d681SAndroid Build Coastguard Worker C.deallocate(Ptr);
627*9880d681SAndroid Build Coastguard Worker }
628*9880d681SAndroid Build Coastguard Worker
629*9880d681SAndroid Build Coastguard Worker /// This placement form of operator new[] uses the MCContext's allocator for
630*9880d681SAndroid Build Coastguard Worker /// obtaining memory. It is a non-throwing new[], which means that it returns
631*9880d681SAndroid Build Coastguard Worker /// null on error.
632*9880d681SAndroid Build Coastguard Worker /// Usage looks like this (assuming there's an MCContext 'Context' in scope):
633*9880d681SAndroid Build Coastguard Worker /// \code
634*9880d681SAndroid Build Coastguard Worker /// // Default alignment (8)
635*9880d681SAndroid Build Coastguard Worker /// char *data = new (Context) char[10];
636*9880d681SAndroid Build Coastguard Worker /// // Specific alignment
637*9880d681SAndroid Build Coastguard Worker /// char *data = new (Context, 4) char[10];
638*9880d681SAndroid Build Coastguard Worker /// \endcode
639*9880d681SAndroid Build Coastguard Worker /// Please note that you cannot use delete on the pointer; it must be
640*9880d681SAndroid Build Coastguard Worker /// deallocated using an explicit destructor call followed by
641*9880d681SAndroid Build Coastguard Worker /// \c Context.Deallocate(Ptr).
642*9880d681SAndroid Build Coastguard Worker ///
643*9880d681SAndroid Build Coastguard Worker /// \param Bytes The number of bytes to allocate. Calculated by the compiler.
644*9880d681SAndroid Build Coastguard Worker /// \param C The MCContext that provides the allocator.
645*9880d681SAndroid Build Coastguard Worker /// \param Alignment The alignment of the allocated memory (if the underlying
646*9880d681SAndroid Build Coastguard Worker /// allocator supports it).
647*9880d681SAndroid Build Coastguard Worker /// \return The allocated memory. Could be NULL.
648*9880d681SAndroid Build Coastguard Worker inline void *operator new[](size_t Bytes, llvm::MCContext &C,
649*9880d681SAndroid Build Coastguard Worker size_t Alignment = 8) LLVM_NOEXCEPT {
650*9880d681SAndroid Build Coastguard Worker return C.allocate(Bytes, Alignment);
651*9880d681SAndroid Build Coastguard Worker }
652*9880d681SAndroid Build Coastguard Worker
653*9880d681SAndroid Build Coastguard Worker /// \brief Placement delete[] companion to the new[] above.
654*9880d681SAndroid Build Coastguard Worker ///
655*9880d681SAndroid Build Coastguard Worker /// This operator is just a companion to the new[] above. There is no way of
656*9880d681SAndroid Build Coastguard Worker /// invoking it directly; see the new[] operator for more details. This operator
657*9880d681SAndroid Build Coastguard Worker /// is called implicitly by the compiler if a placement new[] expression using
658*9880d681SAndroid Build Coastguard Worker /// the MCContext throws in the object constructor.
659*9880d681SAndroid Build Coastguard Worker inline void operator delete[](void *Ptr, llvm::MCContext &C) LLVM_NOEXCEPT {
660*9880d681SAndroid Build Coastguard Worker C.deallocate(Ptr);
661*9880d681SAndroid Build Coastguard Worker }
662*9880d681SAndroid Build Coastguard Worker
663*9880d681SAndroid Build Coastguard Worker #endif
664