39 :
SrcMgr(mgr), MAI(mai), MRI(mri), MOFI(mofi), Allocator(),
40 Symbols(Allocator), UsedNames(Allocator),
43 AllowTemporaryLabels(
true), DwarfCompileUnitID(0),
44 AutoReset(DoAutoReset) {
48 CompilationDir.
clear();
50 SecureLogFile = getenv(
"AS_SECURE_LOG_FILE");
52 SecureLogUsed =
false;
76 for (
auto &
I : ELFUniquingMap)
77 I.second->~MCSectionELF();
78 for (
auto &
I : COFFUniquingMap)
79 I.second->~MCSectionCOFF();
80 for (
auto &
I : MachOUniquingMap)
81 I.second->~MCSectionMachO();
87 CompilationDir.
clear();
89 MCDwarfLineTablesCUMap.clear();
90 SectionsForRanges.clear();
91 MCGenDwarfLabelEntries.clear();
93 DwarfCompileUnitID = 0;
96 MachOUniquingMap.clear();
97 ELFUniquingMap.clear();
98 COFFUniquingMap.clear();
101 AllowTemporaryLabels =
true;
102 DwarfLocSeen =
false;
103 GenDwarfForAssembly =
false;
104 GenDwarfFileNumber = 0;
115 assert(!NameRef.
empty() &&
"Normal symbols cannot be unnamed!");
119 Sym = createSymbol(NameRef,
false,
false);
133 Sym = cast<MCSymbolELF>(OldSym);
137 auto NameIter = UsedNames.insert(std::make_pair(Name,
true)).first;
138 Sym =
new (&*NameIter, *
this)
MCSymbolELF(&*NameIter,
false);
149 "$frame_escape_" +
Twine(Idx));
154 "$parent_frame_offset");
180 if (CanBeUnnamed && !UseNamesOnTempLabels)
181 return createSymbolImpl(
nullptr,
true);
185 bool IsTemporary = CanBeUnnamed;
186 if (AllowTemporaryLabels && !IsTemporary)
190 bool AddSuffix = AlwaysAddSuffix;
191 unsigned &NextUniqueID = NextID[
Name];
197 auto NameEntry = UsedNames.insert(std::make_pair(NewName,
true));
198 if (NameEntry.second) {
201 return createSymbolImpl(&*NameEntry.first, IsTemporary);
203 assert(IsTemporary &&
"Cannot rename non-temporary symbols");
213 return createSymbol(NameSV, AlwaysAddSuffix, CanBeUnnamed);
219 return createSymbol(NameSV,
true,
false);
226 unsigned MCContext::NextInstance(
unsigned LocalLabelVal) {
229 Label =
new (*this)
MCLabel(0);
233 unsigned MCContext::GetInstance(
unsigned LocalLabelVal) {
234 MCLabel *&Label = Instances[LocalLabelVal];
236 Label =
new (*this)
MCLabel(0);
240 MCSymbol *MCContext::getOrCreateDirectionalLocalSymbol(
unsigned LocalLabelVal,
242 MCSymbol *&Sym = LocalSymbols[std::make_pair(LocalLabelVal, Instance)];
249 unsigned Instance = NextInstance(LocalLabelVal);
250 return getOrCreateDirectionalLocalSymbol(LocalLabelVal, Instance);
255 unsigned Instance = GetInstance(LocalLabelVal);
258 return getOrCreateDirectionalLocalSymbol(LocalLabelVal, Instance);
264 return Symbols.
lookup(NameRef);
272 unsigned TypeAndAttributes,
274 const char *BeginSymName) {
296 return Entry =
new (*this)
MCSectionMachO(Segment, Section, TypeAndAttributes,
297 Reserved2, Kind, Begin);
303 GroupName = Group->getName();
306 ELFUniquingMap.erase(
308 auto I = ELFUniquingMap.insert(std::make_pair(
309 ELFSectionKey{
Name, GroupName, UniqueID},
317 unsigned Flags,
unsigned EntrySize,
322 std::tie(I, Inserted) = ELFRelSecNames.
insert(std::make_pair(Name,
true));
326 EntrySize, Group,
true,
nullptr, Associated);
330 unsigned Flags,
unsigned EntrySize,
332 const char *BeginSymName) {
337 return getELFSection(Section, Type, Flags, EntrySize, GroupSym, UniqueID,
338 BeginSymName,
nullptr);
342 unsigned Flags,
unsigned EntrySize,
345 const char *BeginSymName,
351 auto IterBool = ELFUniquingMap.insert(
352 std::make_pair(ELFSectionKey{
Section, Group, UniqueID},
nullptr));
353 auto &Entry = *IterBool.first;
354 if (!IterBool.second)
357 StringRef CachedName = Entry.first.SectionName;
370 new (*this)
MCSectionELF(CachedName, Type, Flags, Kind, EntrySize,
371 GroupSym, UniqueID, Begin, Associated);
372 Entry.second = Result;
379 Group, ~0,
nullptr,
nullptr);
387 const char *BeginSymName) {
389 if (!COMDATSymName.
empty()) {
391 COMDATSymName = COMDATSymbol->
getName();
395 COFFSectionKey
T{
Section, COMDATSymName, Selection};
396 auto IterBool = COFFUniquingMap.insert(std::make_pair(
T,
nullptr));
397 auto Iter = IterBool.first;
398 if (!IterBool.second)
405 StringRef CachedName = Iter->first.SectionName;
407 CachedName, Characteristics, COMDATSymbol, Selection, Kind, Begin);
409 Iter->second = Result;
416 const char *BeginSymName) {
417 return getCOFFSection(Section, Characteristics, Kind,
"", 0, BeginSymName);
422 auto Iter = COFFUniquingMap.find(
T);
423 if (Iter == COFFUniquingMap.end())
452 unsigned FileNumber,
unsigned CUID) {
454 return Table.
getFile(Directory, FileName, FileNumber);
461 if (FileNumber == 0 || FileNumber >= MCDwarfFiles.
size())
464 return !MCDwarfFiles[FileNumber].Name.
empty();
470 SectionsForRanges.remove_if(
477 if (!SrcMgr || Loc ==
SMLoc())
MCSymbolELF * getOrCreateSectionSymbol(const MCSectionELF &Section)
Instances of this class represent a uniqued identifier for a section in the current translation unit...
void push_back(const T &Elt)
MCSymbol * getDirectionalLocalSymbol(unsigned LocalLabelVal, bool Before)
Create and return a directional local symbol for numbered label (used for "1b" or 1f" references)...
StringRef getSectionName() const
MCSectionMachO - This represents a section on a Mach-O system (used by Mac OS X). ...
size_t size() const
size - Get the string size.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
MCSectionELF * getELFSection(StringRef Section, unsigned Type, unsigned Flags)
const SmallVectorImpl< MCDwarfFile > & getMCDwarfFiles(unsigned CUID=0)
MCSymbol * getOrCreateFrameAllocSymbol(StringRef FuncName, unsigned Idx)
Gets a symbol that will be defined to the final stack offset of a local variable after codegen...
void reset()
reset - return object to right after construction state to prepare to process a new module ...
const char * getPrivateGlobalPrefix() const
MCSymbol * createDirectionalLocalSymbol(unsigned LocalLabelVal)
Create the definition of a directional local symbol for numbered label (used for "1:" definitions)...
LLVM_ATTRIBUTE_NORETURN void reportFatalError(SMLoc L, const Twine &Msg) const
unsigned getUniqueID() const
const char * getLinkerPrivateGlobalPrefix() const
MCSymbol * getOrCreateParentFrameOffsetSymbol(StringRef FuncName)
A raw_ostream that writes to an SmallVector or SmallString.
std::error_code current_path(SmallVectorImpl< char > &result)
Get the current path.
MCSymbol * lookupSymbol(const Twine &Name) const
Get the symbol for Name, or null.
unsigned getInstance() const
Get the current instance of this Directional Local Label.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const char *reason, bool gen_crash_diag=true)
Reports a serious error, calling any installed error handler.
MCSectionCOFF - This represents a section on Windows.
unsigned getMainFileID() const
#define DWARF2_FLAG_IS_STMT
MCSymbol * createLinkerPrivateTempSymbol()
Create and return a new linker temporary symbol with a unique but unspecified name.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
void Reset()
Deallocate all but the current slab and reset the current pointer to the beginning of it...
void renameELFSection(MCSectionELF *Section, StringRef Name)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void finalizeDwarfSections(MCStreamer &MCOS)
Remove empty sections from SectionStartEndSyms, to avoid generating useless debug info for them...
virtual bool mayHaveInstructions(MCSection &Sec) const
MCSectionMachO * getMachOSection(StringRef Segment, StringRef Section, unsigned TypeAndAttributes, unsigned Reserved2, SectionKind K, const char *BeginSymName=nullptr)
Return the MCSection for the specified mach-o section.
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
Environment getObjectFileType() const
Instances of this class represent the information from a dwarf .loc directive.
static cl::opt< std::string > FuncName("cppfname", cl::desc("Specify the name of the generated function"), cl::value_desc("function name"))
const MCSymbolELF * getGroup() const
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
This class is intended to be used as a base class for asm properties and features specific to the tar...
Streaming machine code generation interface.
MCSymbol * createTempSymbol(bool CanBeUnnamed=true)
Create and return a new assembler temporary symbol with a unique but unspecified name.
The instances of the Type class are immutable: once they are created, they are never changed...
unsigned getNumBuffers() const
void RunInterruptHandlers()
This function runs all the registered interrupt handlers, including the removal of files registered b...
cl::opt< int > DwarfVersion("dwarf-version", cl::desc("Dwarf version"), cl::init(0))
SectionKind - This is a simple POD value that classifies the properties of a section.
MCSectionELF * createELFRelSection(StringRef Name, unsigned Type, unsigned Flags, unsigned EntrySize, const MCSymbolELF *Group, const MCSectionELF *Associated)
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling...
unsigned getCharacteristics() const
bool isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID=0)
isValidDwarfFileNumber - takes a dwarf file number and returns true if it currently is assigned and f...
unsigned incInstance()
Increment the current instance of this Directional Local Label.
bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
ValueTy lookup(StringRef Key) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
SectionKind getKind() const
MCSymbol * getOrCreateLSDASymbol(StringRef FuncName)
StringRef getSectionName() const
StringRef toStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single StringRef if it can be represented as such.
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
StringRef getName() const
getName - Get the symbol name.
const MemoryBuffer * getMemoryBuffer(unsigned i) const
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
MCSectionCOFF * getAssociativeCOFFSection(MCSectionCOFF *Sec, const MCSymbol *KeySym)
Gets or creates a section equivalent to Sec that is associated with the section containing KeySym...
COFFYAML::WeakExternalCharacteristics Characteristics
MCSectionELF - This represents a section on linux, lots of unix variants and some bare metal systems...
MCSectionELF * createELFGroupSection(const MCSymbolELF *Group)
MCSectionCOFF * getCOFFSection(StringRef Section, unsigned Characteristics, SectionKind Kind, StringRef COMDATSymName, int Selection, const char *BeginSymName=nullptr)
Instances of this class represent a label name in the MC file, and MCLabel are created and uniqued by...
const ARM::ArchExtKind Kind
unsigned getDwarfFile(StringRef Directory, StringRef FileName, unsigned FileNumber, unsigned CUID)
Creates an entry in the dwarf file and directory tables.
This class implements an extremely fast bulk output stream that can only output to a stream...
StringRef - Represent a constant reference to a string, i.e.
bool isUndefined() const
isUndefined - Check if this symbol undefined (i.e., implicitly defined).
void PrintMessage(raw_ostream &OS, SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges=None, ArrayRef< SMFixIt > FixIts=None, bool ShowColors=true) const
Emit a message about the specified location with the specified string.
Represents a location in source code.
unsigned getFile(StringRef &Directory, StringRef &FileName, unsigned FileNumber=0)
static SectionKind getReadOnly()
bool empty() const
empty - Check if the string is empty.
static SectionKind getText()