Coverage Report

Created: 2017-10-03 07:32

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