blob: 73ffdc0a4bd59ca3162b9b7984932d3578a3fcf8 [file] [log] [blame]
Daniel Dunbarba1da8a2009-06-23 23:39:15 +00001//===- lib/MC/MCContext.cpp - Machine Code Context ------------------------===//
Daniel Dunbarecc63f82009-06-23 22:01:43 +00002//
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#include "llvm/MC/MCContext.h"
Chris Lattner7c5b0212009-10-19 22:49:00 +000011#include "llvm/ADT/SmallString.h"
12#include "llvm/ADT/Twine.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000013#include "llvm/MC/MCAsmInfo.h"
14#include "llvm/MC/MCDwarf.h"
15#include "llvm/MC/MCLabel.h"
16#include "llvm/MC/MCObjectFileInfo.h"
17#include "llvm/MC/MCRegisterInfo.h"
18#include "llvm/MC/MCSectionCOFF.h"
19#include "llvm/MC/MCSectionELF.h"
20#include "llvm/MC/MCSectionMachO.h"
21#include "llvm/MC/MCSymbol.h"
Rafael Espindolac85dca62011-01-23 04:28:49 +000022#include "llvm/Support/ELF.h"
Jim Grosbach82f4ce52012-01-26 23:20:11 +000023#include "llvm/Support/ErrorHandling.h"
Rafael Espindola76858a72013-06-14 20:26:58 +000024#include "llvm/Support/FileSystem.h"
Eric Christopher6c583142012-12-18 00:31:01 +000025#include "llvm/Support/MemoryBuffer.h"
Jim Grosbach82f4ce52012-01-26 23:20:11 +000026#include "llvm/Support/Signals.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000027#include "llvm/Support/SourceMgr.h"
David Blaikie2b3ea3c2013-10-22 23:41:52 +000028#include <map>
29
Daniel Dunbarecc63f82009-06-23 22:01:43 +000030using namespace llvm;
31
David Blaikie2b3ea3c2013-10-22 23:41:52 +000032typedef std::pair<std::string, std::string> SectionGroupPair;
33
Chris Lattnerf0559e42010-04-08 20:30:37 +000034typedef StringMap<const MCSectionMachO*> MachOUniqueMapTy;
David Blaikie2b3ea3c2013-10-22 23:41:52 +000035typedef std::map<SectionGroupPair, const MCSectionELF *> ELFUniqueMapTy;
Bill Wendling0ae07092013-11-27 06:44:18 +000036typedef std::map<SectionGroupPair, const MCSectionCOFF *> COFFUniqueMapTy;
Chris Lattnerf0559e42010-04-08 20:30:37 +000037
Bill Wendling99cb6222013-06-18 07:20:20 +000038MCContext::MCContext(const MCAsmInfo *mai, const MCRegisterInfo *mri,
Pedro Artigas873a1dd2012-12-06 22:12:44 +000039 const MCObjectFileInfo *mofi, const SourceMgr *mgr,
Stephen Hines36b56882014-04-23 16:57:46 -070040 bool DoAutoReset)
41 : SrcMgr(mgr), MAI(mai), MRI(mri), MOFI(mofi), Allocator(),
42 Symbols(Allocator), UsedNames(Allocator), NextUniqueID(0),
43 CurrentDwarfLoc(0, 0, 0, DWARF2_FLAG_IS_STMT, 0, 0), DwarfLocSeen(false),
44 GenDwarfForAssembly(false), GenDwarfFileNumber(0),
45 AllowTemporaryLabels(true), DwarfCompileUnitID(0),
46 AutoReset(DoAutoReset) {
Pedro Artigas5399d252012-12-12 22:59:46 +000047
Rafael Espindola76858a72013-06-14 20:26:58 +000048 error_code EC = llvm::sys::fs::current_path(CompilationDir);
Stephen Hines36b56882014-04-23 16:57:46 -070049 if (EC)
50 CompilationDir.clear();
Rafael Espindola76858a72013-06-14 20:26:58 +000051
Chris Lattnerf0559e42010-04-08 20:30:37 +000052 MachOUniquingMap = 0;
Chris Lattner74aae472010-04-08 21:26:26 +000053 ELFUniquingMap = 0;
Chris Lattnereb40a0f2010-05-07 17:17:41 +000054 COFFUniquingMap = 0;
Kevin Enderbyf187ac52010-06-28 21:45:58 +000055
56 SecureLogFile = getenv("AS_SECURE_LOG_FILE");
57 SecureLog = 0;
58 SecureLogUsed = false;
Eric Christopher6c583142012-12-18 00:31:01 +000059
60 if (SrcMgr && SrcMgr->getNumBuffers() > 0)
61 MainFileName = SrcMgr->getMemoryBuffer(0)->getBufferIdentifier();
Pedro Artigas873a1dd2012-12-06 22:12:44 +000062}
63
64MCContext::~MCContext() {
65
Pedro Artigas5399d252012-12-12 22:59:46 +000066 if (AutoReset)
67 reset();
Pedro Artigas873a1dd2012-12-06 22:12:44 +000068
69 // NOTE: The symbols are all allocated out of a bump pointer allocator,
70 // we don't need to free them here.
Stephen Hines36b56882014-04-23 16:57:46 -070071
Pedro Artigas873a1dd2012-12-06 22:12:44 +000072 // If the stream for the .secure_log_unique directive was created free it.
73 delete (raw_ostream*)SecureLog;
74}
75
76//===----------------------------------------------------------------------===//
77// Module Lifetime Management
78//===----------------------------------------------------------------------===//
79
Pedro Artigas5399d252012-12-12 22:59:46 +000080void MCContext::reset() {
Pedro Artigas873a1dd2012-12-06 22:12:44 +000081 UsedNames.clear();
82 Symbols.clear();
83 Allocator.Reset();
84 Instances.clear();
Stephen Hines36b56882014-04-23 16:57:46 -070085 MCDwarfLineTablesCUMap.clear();
Pedro Artigas873a1dd2012-12-06 22:12:44 +000086 MCGenDwarfLabelEntries.clear();
87 DwarfDebugFlags = StringRef();
Pedro Artigas9e7924d2013-02-20 00:10:29 +000088 DwarfCompileUnitID = 0;
Pedro Artigas873a1dd2012-12-06 22:12:44 +000089 CurrentDwarfLoc = MCDwarfLoc(0,0,0,DWARF2_FLAG_IS_STMT,0,0);
Michael J. Spencer326990f2010-11-26 04:16:08 +000090
Chris Lattnerf0559e42010-04-08 20:30:37 +000091 // If we have the MachO uniquing map, free it.
92 delete (MachOUniqueMapTy*)MachOUniquingMap;
Chris Lattner74aae472010-04-08 21:26:26 +000093 delete (ELFUniqueMapTy*)ELFUniquingMap;
Chris Lattnereb40a0f2010-05-07 17:17:41 +000094 delete (COFFUniqueMapTy*)COFFUniquingMap;
Pedro Artigas873a1dd2012-12-06 22:12:44 +000095 MachOUniquingMap = 0;
96 ELFUniquingMap = 0;
97 COFFUniquingMap = 0;
Pedro Artigas5399d252012-12-12 22:59:46 +000098
99 NextUniqueID = 0;
100 AllowTemporaryLabels = true;
101 DwarfLocSeen = false;
102 GenDwarfForAssembly = false;
103 GenDwarfFileNumber = 0;
Daniel Dunbarecc63f82009-06-23 22:01:43 +0000104}
105
Chris Lattnerf0559e42010-04-08 20:30:37 +0000106//===----------------------------------------------------------------------===//
107// Symbol Manipulation
108//===----------------------------------------------------------------------===//
109
Chris Lattner9b97a732010-03-30 18:10:53 +0000110MCSymbol *MCContext::GetOrCreateSymbol(StringRef Name) {
Chris Lattner00685bb2010-03-10 01:29:27 +0000111 assert(!Name.empty() && "Normal symbols cannot be unnamed!");
Michael J. Spencer326990f2010-11-26 04:16:08 +0000112
Chris Lattnerc28cc092010-03-15 06:15:35 +0000113 // Do the lookup and get the entire StringMapEntry. We want access to the
114 // key if we are creating the entry.
115 StringMapEntry<MCSymbol*> &Entry = Symbols.GetOrCreateValue(Name);
Rafael Espindola9f447242010-12-01 20:46:11 +0000116 MCSymbol *Sym = Entry.getValue();
117
118 if (Sym)
119 return Sym;
120
121 Sym = CreateSymbol(Name);
122 Entry.setValue(Sym);
123 return Sym;
124}
125
126MCSymbol *MCContext::CreateSymbol(StringRef Name) {
Daniel Dunbarc6cf43d2011-03-28 22:49:15 +0000127 // Determine whether this is an assembler temporary or normal label, if used.
128 bool isTemporary = false;
129 if (AllowTemporaryLabels)
Bill Wendling99cb6222013-06-18 07:20:20 +0000130 isTemporary = Name.startswith(MAI->getPrivateGlobalPrefix());
Rafael Espindola9f447242010-12-01 20:46:11 +0000131
132 StringMapEntry<bool> *NameEntry = &UsedNames.GetOrCreateValue(Name);
133 if (NameEntry->getValue()) {
Stephen Hines36b56882014-04-23 16:57:46 -0700134 assert(isTemporary && "Cannot rename non-temporary symbols");
Benjamin Kramerc18214a2011-04-09 11:26:27 +0000135 SmallString<128> NewName = Name;
Rafael Espindola9f447242010-12-01 20:46:11 +0000136 do {
Benjamin Kramerc18214a2011-04-09 11:26:27 +0000137 NewName.resize(Name.size());
138 raw_svector_ostream(NewName) << NextUniqueID++;
139 NameEntry = &UsedNames.GetOrCreateValue(NewName);
Rafael Espindola9f447242010-12-01 20:46:11 +0000140 } while (NameEntry->getValue());
141 }
142 NameEntry->setValue(true);
Chris Lattnerc69485e2009-06-24 04:31:49 +0000143
Chris Lattnerc28cc092010-03-15 06:15:35 +0000144 // Ok, the entry doesn't already exist. Have the MCSymbol object itself refer
Rafael Espindola9f447242010-12-01 20:46:11 +0000145 // to the copy of the string that is embedded in the UsedNames entry.
146 MCSymbol *Result = new (*this) MCSymbol(NameEntry->getKey(), isTemporary);
147
148 return Result;
Chris Lattnerc69485e2009-06-24 04:31:49 +0000149}
150
Chris Lattner9b97a732010-03-30 18:10:53 +0000151MCSymbol *MCContext::GetOrCreateSymbol(const Twine &Name) {
Chris Lattner7c5b0212009-10-19 22:49:00 +0000152 SmallString<128> NameSV;
Stephen Hines36b56882014-04-23 16:57:46 -0700153 return GetOrCreateSymbol(Name.toStringRef(NameSV));
154}
155
156MCSymbol *MCContext::CreateLinkerPrivateTempSymbol() {
157 SmallString<128> NameSV;
158 raw_svector_ostream(NameSV)
159 << MAI->getLinkerPrivateGlobalPrefix() << "tmp" << NextUniqueID++;
160 return CreateSymbol(NameSV);
Chris Lattner7c5b0212009-10-19 22:49:00 +0000161}
162
Chris Lattner1d72a762010-03-14 08:23:30 +0000163MCSymbol *MCContext::CreateTempSymbol() {
Rafael Espindola9f447242010-12-01 20:46:11 +0000164 SmallString<128> NameSV;
Benjamin Kramerc18214a2011-04-09 11:26:27 +0000165 raw_svector_ostream(NameSV)
Bill Wendling99cb6222013-06-18 07:20:20 +0000166 << MAI->getPrivateGlobalPrefix() << "tmp" << NextUniqueID++;
Rafael Espindola9f447242010-12-01 20:46:11 +0000167 return CreateSymbol(NameSV);
Chris Lattner1d72a762010-03-14 08:23:30 +0000168}
169
Stephen Hines36b56882014-04-23 16:57:46 -0700170unsigned MCContext::NextInstance(unsigned LocalLabelVal) {
Benjamin Kramer47f9a492010-05-18 12:15:34 +0000171 MCLabel *&Label = Instances[LocalLabelVal];
172 if (!Label)
173 Label = new (*this) MCLabel(0);
174 return Label->incInstance();
Kevin Enderbyebe7fcd2010-05-17 23:08:19 +0000175}
176
Stephen Hines36b56882014-04-23 16:57:46 -0700177unsigned MCContext::GetInstance(unsigned LocalLabelVal) {
Benjamin Kramer47f9a492010-05-18 12:15:34 +0000178 MCLabel *&Label = Instances[LocalLabelVal];
179 if (!Label)
180 Label = new (*this) MCLabel(0);
181 return Label->getInstance();
Kevin Enderbyebe7fcd2010-05-17 23:08:19 +0000182}
183
Stephen Hines36b56882014-04-23 16:57:46 -0700184MCSymbol *MCContext::getOrCreateDirectionalLocalSymbol(unsigned LocalLabelVal,
185 unsigned Instance) {
186 MCSymbol *&Sym = LocalSymbols[std::make_pair(LocalLabelVal, Instance)];
187 if (!Sym)
188 Sym = CreateTempSymbol();
189 return Sym;
Kevin Enderbyebe7fcd2010-05-17 23:08:19 +0000190}
Stephen Hines36b56882014-04-23 16:57:46 -0700191
192MCSymbol *MCContext::CreateDirectionalLocalSymbol(unsigned LocalLabelVal) {
193 unsigned Instance = NextInstance(LocalLabelVal);
194 return getOrCreateDirectionalLocalSymbol(LocalLabelVal, Instance);
195}
196
197MCSymbol *MCContext::GetDirectionalLocalSymbol(unsigned LocalLabelVal,
198 bool Before) {
199 unsigned Instance = GetInstance(LocalLabelVal);
200 if (!Before)
201 ++Instance;
202 return getOrCreateDirectionalLocalSymbol(LocalLabelVal, Instance);
Kevin Enderbyebe7fcd2010-05-17 23:08:19 +0000203}
204
Daniel Dunbar2928c832009-11-06 10:58:06 +0000205MCSymbol *MCContext::LookupSymbol(StringRef Name) const {
Daniel Dunbarecc63f82009-06-23 22:01:43 +0000206 return Symbols.lookup(Name);
207}
Chris Lattnerf0559e42010-04-08 20:30:37 +0000208
Roman Divackyf145c132012-09-18 17:10:37 +0000209MCSymbol *MCContext::LookupSymbol(const Twine &Name) const {
210 SmallString<128> NameSV;
211 Name.toVector(NameSV);
212 return LookupSymbol(NameSV.str());
213}
214
Chris Lattnerf0559e42010-04-08 20:30:37 +0000215//===----------------------------------------------------------------------===//
216// Section Management
217//===----------------------------------------------------------------------===//
218
219const MCSectionMachO *MCContext::
220getMachOSection(StringRef Segment, StringRef Section,
221 unsigned TypeAndAttributes,
222 unsigned Reserved2, SectionKind Kind) {
Michael J. Spencer326990f2010-11-26 04:16:08 +0000223
Chris Lattnerf0559e42010-04-08 20:30:37 +0000224 // We unique sections by their segment/section pair. The returned section
225 // may not have the same flags as the requested section, if so this should be
226 // diagnosed by the client as an error.
Michael J. Spencer326990f2010-11-26 04:16:08 +0000227
Chris Lattnerf0559e42010-04-08 20:30:37 +0000228 // Create the map if it doesn't already exist.
229 if (MachOUniquingMap == 0)
230 MachOUniquingMap = new MachOUniqueMapTy();
231 MachOUniqueMapTy &Map = *(MachOUniqueMapTy*)MachOUniquingMap;
Michael J. Spencer326990f2010-11-26 04:16:08 +0000232
Chris Lattnerf0559e42010-04-08 20:30:37 +0000233 // Form the name to look up.
234 SmallString<64> Name;
235 Name += Segment;
236 Name.push_back(',');
237 Name += Section;
Michael J. Spencer326990f2010-11-26 04:16:08 +0000238
Chris Lattnerf0559e42010-04-08 20:30:37 +0000239 // Do the lookup, if we have a hit, return it.
240 const MCSectionMachO *&Entry = Map[Name.str()];
241 if (Entry) return Entry;
Michael J. Spencer326990f2010-11-26 04:16:08 +0000242
Chris Lattnerf0559e42010-04-08 20:30:37 +0000243 // Otherwise, return a new section.
Chris Lattner74aae472010-04-08 21:26:26 +0000244 return Entry = new (*this) MCSectionMachO(Segment, Section, TypeAndAttributes,
245 Reserved2, Kind);
Chris Lattnerf0559e42010-04-08 20:30:37 +0000246}
Chris Lattner74aae472010-04-08 21:26:26 +0000247
Rafael Espindola4283f4b2010-11-10 19:05:07 +0000248const MCSectionELF *MCContext::
Chris Lattner74aae472010-04-08 21:26:26 +0000249getELFSection(StringRef Section, unsigned Type, unsigned Flags,
Rafael Espindola2ff9e832010-11-11 18:13:52 +0000250 SectionKind Kind) {
251 return getELFSection(Section, Type, Flags, Kind, 0, "");
252}
253
254const MCSectionELF *MCContext::
255getELFSection(StringRef Section, unsigned Type, unsigned Flags,
256 SectionKind Kind, unsigned EntrySize, StringRef Group) {
Chris Lattner74aae472010-04-08 21:26:26 +0000257 if (ELFUniquingMap == 0)
258 ELFUniquingMap = new ELFUniqueMapTy();
259 ELFUniqueMapTy &Map = *(ELFUniqueMapTy*)ELFUniquingMap;
Michael J. Spencer326990f2010-11-26 04:16:08 +0000260
Stephen Hines36b56882014-04-23 16:57:46 -0700261 SmallString<32> ZDebugName;
262 if (MAI->compressDebugSections() && Section.startswith(".debug_") &&
263 Section != ".debug_frame" && Section != ".debug_line")
264 Section = (".z" + Section.drop_front(1)).toStringRef(ZDebugName);
265
Chris Lattner74aae472010-04-08 21:26:26 +0000266 // Do the lookup, if we have a hit, return it.
David Blaikie2b3ea3c2013-10-22 23:41:52 +0000267 std::pair<ELFUniqueMapTy::iterator, bool> Entry = Map.insert(
268 std::make_pair(SectionGroupPair(Section, Group), (MCSectionELF *)0));
269 if (!Entry.second) return Entry.first->second;
Michael J. Spencer326990f2010-11-26 04:16:08 +0000270
Jan Wen Voung186e7a02010-09-30 05:59:22 +0000271 // Possibly refine the entry size first.
272 if (!EntrySize) {
273 EntrySize = MCSectionELF::DetermineEntrySize(Kind);
274 }
Rafael Espindola2ff9e832010-11-11 18:13:52 +0000275
276 MCSymbol *GroupSym = NULL;
277 if (!Group.empty())
278 GroupSym = GetOrCreateSymbol(Group);
279
David Blaikie2b3ea3c2013-10-22 23:41:52 +0000280 MCSectionELF *Result = new (*this) MCSectionELF(
281 Entry.first->first.first, Type, Flags, Kind, EntrySize, GroupSym);
282 Entry.first->second = Result;
Chris Lattner74aae472010-04-08 21:26:26 +0000283 return Result;
284}
285
Rafael Espindola2ff9e832010-11-11 18:13:52 +0000286const MCSectionELF *MCContext::CreateELFGroupSection() {
287 MCSectionELF *Result =
Rafael Espindolac85dca62011-01-23 04:28:49 +0000288 new (*this) MCSectionELF(".group", ELF::SHT_GROUP, 0,
Rafael Espindola2ff9e832010-11-11 18:13:52 +0000289 SectionKind::getReadOnly(), 4, NULL);
290 return Result;
291}
292
Bill Wendling0ae07092013-11-27 06:44:18 +0000293const MCSectionCOFF *
294MCContext::getCOFFSection(StringRef Section, unsigned Characteristics,
295 SectionKind Kind, StringRef COMDATSymName,
296 int Selection, const MCSectionCOFF *Assoc) {
Chris Lattnereb40a0f2010-05-07 17:17:41 +0000297 if (COFFUniquingMap == 0)
298 COFFUniquingMap = new COFFUniqueMapTy();
299 COFFUniqueMapTy &Map = *(COFFUniqueMapTy*)COFFUniquingMap;
Michael J. Spencer326990f2010-11-26 04:16:08 +0000300
Chris Lattnereb40a0f2010-05-07 17:17:41 +0000301 // Do the lookup, if we have a hit, return it.
Michael J. Spencer326990f2010-11-26 04:16:08 +0000302
Bill Wendling0ae07092013-11-27 06:44:18 +0000303 SectionGroupPair P(Section, COMDATSymName);
304 std::pair<COFFUniqueMapTy::iterator, bool> Entry =
305 Map.insert(std::make_pair(P, (MCSectionCOFF *)0));
306 COFFUniqueMapTy::iterator Iter = Entry.first;
307 if (!Entry.second)
308 return Iter->second;
Michael J. Spencer326990f2010-11-26 04:16:08 +0000309
Bill Wendling0ae07092013-11-27 06:44:18 +0000310 const MCSymbol *COMDATSymbol = NULL;
311 if (!COMDATSymName.empty())
312 COMDATSymbol = GetOrCreateSymbol(COMDATSymName);
313
314 MCSectionCOFF *Result =
315 new (*this) MCSectionCOFF(Iter->first.first, Characteristics,
316 COMDATSymbol, Selection, Assoc, Kind);
317
318 Iter->second = Result;
Chris Lattnereb40a0f2010-05-07 17:17:41 +0000319 return Result;
320}
Kevin Enderby7cbf73a2010-07-28 20:55:35 +0000321
Bill Wendling0ae07092013-11-27 06:44:18 +0000322const MCSectionCOFF *
323MCContext::getCOFFSection(StringRef Section, unsigned Characteristics,
324 SectionKind Kind) {
325 return getCOFFSection(Section, Characteristics, Kind, "", 0);
326}
327
Nico Rieck80646282013-07-06 12:13:10 +0000328const MCSectionCOFF *MCContext::getCOFFSection(StringRef Section) {
329 if (COFFUniquingMap == 0)
330 COFFUniquingMap = new COFFUniqueMapTy();
331 COFFUniqueMapTy &Map = *(COFFUniqueMapTy*)COFFUniquingMap;
332
Bill Wendling0ae07092013-11-27 06:44:18 +0000333 SectionGroupPair P(Section, "");
334 COFFUniqueMapTy::iterator Iter = Map.find(P);
335 if (Iter == Map.end())
336 return 0;
337 return Iter->second;
Nico Rieck80646282013-07-06 12:13:10 +0000338}
339
Kevin Enderby7cbf73a2010-07-28 20:55:35 +0000340//===----------------------------------------------------------------------===//
341// Dwarf Management
342//===----------------------------------------------------------------------===//
343
344/// GetDwarfFile - takes a file name an number to place in the dwarf file and
345/// directory tables. If the file number has already been allocated it is an
346/// error and zero is returned and the client reports the error, else the
347/// allocated file number is returned. The file numbers may be in any order.
Nick Lewycky44d798d2011-10-17 23:05:28 +0000348unsigned MCContext::GetDwarfFile(StringRef Directory, StringRef FileName,
Manman Ren3de61b42013-03-07 01:42:00 +0000349 unsigned FileNumber, unsigned CUID) {
Stephen Hines36b56882014-04-23 16:57:46 -0700350 MCDwarfLineTable &Table = MCDwarfLineTablesCUMap[CUID];
351 return Table.getFile(Directory, FileName, FileNumber);
Kevin Enderby7cbf73a2010-07-28 20:55:35 +0000352}
Kevin Enderbyc1840b32010-08-24 20:32:42 +0000353
Kevin Enderby3f55c242010-10-04 20:17:24 +0000354/// isValidDwarfFileNumber - takes a dwarf file number and returns true if it
Kevin Enderbyc1840b32010-08-24 20:32:42 +0000355/// currently is assigned and false otherwise.
Manman Ren3de61b42013-03-07 01:42:00 +0000356bool MCContext::isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID) {
Stephen Hines36b56882014-04-23 16:57:46 -0700357 const SmallVectorImpl<MCDwarfFile>& MCDwarfFiles = getMCDwarfFiles(CUID);
Kevin Enderbyc1840b32010-08-24 20:32:42 +0000358 if(FileNumber == 0 || FileNumber >= MCDwarfFiles.size())
359 return false;
360
Stephen Hines36b56882014-04-23 16:57:46 -0700361 return !MCDwarfFiles[FileNumber].Name.empty();
Kevin Enderbyc1840b32010-08-24 20:32:42 +0000362}
Jim Grosbach82f4ce52012-01-26 23:20:11 +0000363
364void MCContext::FatalError(SMLoc Loc, const Twine &Msg) {
365 // If we have a source manager and a location, use it. Otherwise just
366 // use the generic report_fatal_error().
367 if (!SrcMgr || Loc == SMLoc())
Stephen Hines36b56882014-04-23 16:57:46 -0700368 report_fatal_error(Msg, false);
Jim Grosbach82f4ce52012-01-26 23:20:11 +0000369
370 // Use the source manager to print the message.
371 SrcMgr->PrintMessage(Loc, SourceMgr::DK_Error, Msg);
372
373 // If we reached here, we are failing ungracefully. Run the interrupt handlers
374 // to make sure any special cleanups get done, in particular that we remove
375 // files registered with RemoveFileOnSignal.
376 sys::RunInterruptHandlers();
377 exit(1);
378}