Daniel Dunbar | ba1da8a | 2009-06-23 23:39:15 +0000 | [diff] [blame] | 1 | //===- lib/MC/MCContext.cpp - Machine Code Context ------------------------===// |
Daniel Dunbar | ecc63f8 | 2009-06-23 22:01:43 +0000 | [diff] [blame] | 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 | #include "llvm/MC/MCContext.h" |
Chris Lattner | 1a5c28f | 2010-03-11 22:56:10 +0000 | [diff] [blame] | 11 | #include "llvm/MC/MCAsmInfo.h" |
Chris Lattner | f0559e4 | 2010-04-08 20:30:37 +0000 | [diff] [blame] | 12 | #include "llvm/MC/MCSectionMachO.h" |
Chris Lattner | 74aae47 | 2010-04-08 21:26:26 +0000 | [diff] [blame] | 13 | #include "llvm/MC/MCSectionELF.h" |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 14 | #include "llvm/MC/MCSectionCOFF.h" |
Daniel Dunbar | ecc63f8 | 2009-06-23 22:01:43 +0000 | [diff] [blame] | 15 | #include "llvm/MC/MCSymbol.h" |
Kevin Enderby | ebe7fcd | 2010-05-17 23:08:19 +0000 | [diff] [blame] | 16 | #include "llvm/MC/MCLabel.h" |
Kevin Enderby | 7cbf73a | 2010-07-28 20:55:35 +0000 | [diff] [blame] | 17 | #include "llvm/MC/MCDwarf.h" |
Chris Lattner | 7c5b021 | 2009-10-19 22:49:00 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/SmallString.h" |
| 19 | #include "llvm/ADT/Twine.h" |
Daniel Dunbar | ecc63f8 | 2009-06-23 22:01:43 +0000 | [diff] [blame] | 20 | using namespace llvm; |
| 21 | |
Chris Lattner | f0559e4 | 2010-04-08 20:30:37 +0000 | [diff] [blame] | 22 | typedef StringMap<const MCSectionMachO*> MachOUniqueMapTy; |
Chris Lattner | 74aae47 | 2010-04-08 21:26:26 +0000 | [diff] [blame] | 23 | typedef StringMap<const MCSectionELF*> ELFUniqueMapTy; |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 24 | typedef StringMap<const MCSectionCOFF*> COFFUniqueMapTy; |
Chris Lattner | f0559e4 | 2010-04-08 20:30:37 +0000 | [diff] [blame] | 25 | |
| 26 | |
Kevin Enderby | c1840b3 | 2010-08-24 20:32:42 +0000 | [diff] [blame] | 27 | MCContext::MCContext(const MCAsmInfo &mai) : MAI(mai), NextUniqueID(0), |
Rafael Espindola | af6b5808 | 2010-11-16 21:20:32 +0000 | [diff] [blame] | 28 | CurrentDwarfLoc(0,0,0,DWARF2_FLAG_IS_STMT,0,0) { |
Chris Lattner | f0559e4 | 2010-04-08 20:30:37 +0000 | [diff] [blame] | 29 | MachOUniquingMap = 0; |
Chris Lattner | 74aae47 | 2010-04-08 21:26:26 +0000 | [diff] [blame] | 30 | ELFUniquingMap = 0; |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 31 | COFFUniquingMap = 0; |
Kevin Enderby | f187ac5 | 2010-06-28 21:45:58 +0000 | [diff] [blame] | 32 | |
| 33 | SecureLogFile = getenv("AS_SECURE_LOG_FILE"); |
| 34 | SecureLog = 0; |
| 35 | SecureLogUsed = false; |
Kevin Enderby | c1840b3 | 2010-08-24 20:32:42 +0000 | [diff] [blame] | 36 | |
| 37 | DwarfLocSeen = false; |
Daniel Dunbar | ecc63f8 | 2009-06-23 22:01:43 +0000 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | MCContext::~MCContext() { |
Chris Lattner | f0559e4 | 2010-04-08 20:30:37 +0000 | [diff] [blame] | 41 | // NOTE: The symbols are all allocated out of a bump pointer allocator, |
Chris Lattner | c9d3152 | 2009-08-13 00:21:53 +0000 | [diff] [blame] | 42 | // we don't need to free them here. |
Michael J. Spencer | 326990f | 2010-11-26 04:16:08 +0000 | [diff] [blame^] | 43 | |
Chris Lattner | f0559e4 | 2010-04-08 20:30:37 +0000 | [diff] [blame] | 44 | // If we have the MachO uniquing map, free it. |
| 45 | delete (MachOUniqueMapTy*)MachOUniquingMap; |
Chris Lattner | 74aae47 | 2010-04-08 21:26:26 +0000 | [diff] [blame] | 46 | delete (ELFUniqueMapTy*)ELFUniquingMap; |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 47 | delete (COFFUniqueMapTy*)COFFUniquingMap; |
Kevin Enderby | f187ac5 | 2010-06-28 21:45:58 +0000 | [diff] [blame] | 48 | |
| 49 | // If the stream for the .secure_log_unique directive was created free it. |
| 50 | delete (raw_ostream*)SecureLog; |
Daniel Dunbar | ecc63f8 | 2009-06-23 22:01:43 +0000 | [diff] [blame] | 51 | } |
| 52 | |
Chris Lattner | f0559e4 | 2010-04-08 20:30:37 +0000 | [diff] [blame] | 53 | //===----------------------------------------------------------------------===// |
| 54 | // Symbol Manipulation |
| 55 | //===----------------------------------------------------------------------===// |
| 56 | |
Chris Lattner | 9b97a73 | 2010-03-30 18:10:53 +0000 | [diff] [blame] | 57 | MCSymbol *MCContext::GetOrCreateSymbol(StringRef Name) { |
Chris Lattner | 00685bb | 2010-03-10 01:29:27 +0000 | [diff] [blame] | 58 | assert(!Name.empty() && "Normal symbols cannot be unnamed!"); |
Michael J. Spencer | 326990f | 2010-11-26 04:16:08 +0000 | [diff] [blame^] | 59 | |
Chris Lattner | 9b97a73 | 2010-03-30 18:10:53 +0000 | [diff] [blame] | 60 | // Determine whether this is an assembler temporary or normal label. |
| 61 | bool isTemporary = Name.startswith(MAI.getPrivateGlobalPrefix()); |
Michael J. Spencer | 326990f | 2010-11-26 04:16:08 +0000 | [diff] [blame^] | 62 | |
Chris Lattner | c28cc09 | 2010-03-15 06:15:35 +0000 | [diff] [blame] | 63 | // Do the lookup and get the entire StringMapEntry. We want access to the |
| 64 | // key if we are creating the entry. |
| 65 | StringMapEntry<MCSymbol*> &Entry = Symbols.GetOrCreateValue(Name); |
| 66 | if (Entry.getValue()) return Entry.getValue(); |
Chris Lattner | c69485e | 2009-06-24 04:31:49 +0000 | [diff] [blame] | 67 | |
Chris Lattner | c28cc09 | 2010-03-15 06:15:35 +0000 | [diff] [blame] | 68 | // Ok, the entry doesn't already exist. Have the MCSymbol object itself refer |
| 69 | // to the copy of the string that is embedded in the StringMapEntry. |
| 70 | MCSymbol *Result = new (*this) MCSymbol(Entry.getKey(), isTemporary); |
| 71 | Entry.setValue(Result); |
| 72 | return Result; |
Chris Lattner | c69485e | 2009-06-24 04:31:49 +0000 | [diff] [blame] | 73 | } |
| 74 | |
Chris Lattner | 9b97a73 | 2010-03-30 18:10:53 +0000 | [diff] [blame] | 75 | MCSymbol *MCContext::GetOrCreateSymbol(const Twine &Name) { |
Chris Lattner | 7c5b021 | 2009-10-19 22:49:00 +0000 | [diff] [blame] | 76 | SmallString<128> NameSV; |
| 77 | Name.toVector(NameSV); |
Chris Lattner | 9b97a73 | 2010-03-30 18:10:53 +0000 | [diff] [blame] | 78 | return GetOrCreateSymbol(NameSV.str()); |
Chris Lattner | 7c5b021 | 2009-10-19 22:49:00 +0000 | [diff] [blame] | 79 | } |
| 80 | |
Chris Lattner | 1d72a76 | 2010-03-14 08:23:30 +0000 | [diff] [blame] | 81 | MCSymbol *MCContext::CreateTempSymbol() { |
Chris Lattner | 9b97a73 | 2010-03-30 18:10:53 +0000 | [diff] [blame] | 82 | return GetOrCreateSymbol(Twine(MAI.getPrivateGlobalPrefix()) + |
| 83 | "tmp" + Twine(NextUniqueID++)); |
Chris Lattner | 1d72a76 | 2010-03-14 08:23:30 +0000 | [diff] [blame] | 84 | } |
| 85 | |
Kevin Enderby | ebe7fcd | 2010-05-17 23:08:19 +0000 | [diff] [blame] | 86 | unsigned MCContext::NextInstance(int64_t LocalLabelVal) { |
Benjamin Kramer | 47f9a49 | 2010-05-18 12:15:34 +0000 | [diff] [blame] | 87 | MCLabel *&Label = Instances[LocalLabelVal]; |
| 88 | if (!Label) |
| 89 | Label = new (*this) MCLabel(0); |
| 90 | return Label->incInstance(); |
Kevin Enderby | ebe7fcd | 2010-05-17 23:08:19 +0000 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | unsigned MCContext::GetInstance(int64_t LocalLabelVal) { |
Benjamin Kramer | 47f9a49 | 2010-05-18 12:15:34 +0000 | [diff] [blame] | 94 | MCLabel *&Label = Instances[LocalLabelVal]; |
| 95 | if (!Label) |
| 96 | Label = new (*this) MCLabel(0); |
| 97 | return Label->getInstance(); |
Kevin Enderby | ebe7fcd | 2010-05-17 23:08:19 +0000 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | MCSymbol *MCContext::CreateDirectionalLocalSymbol(int64_t LocalLabelVal) { |
| 101 | return GetOrCreateSymbol(Twine(MAI.getPrivateGlobalPrefix()) + |
| 102 | Twine(LocalLabelVal) + |
| 103 | "\2" + |
Duncan Sands | 3472766 | 2010-07-12 08:16:59 +0000 | [diff] [blame] | 104 | Twine(NextInstance(LocalLabelVal))); |
Kevin Enderby | ebe7fcd | 2010-05-17 23:08:19 +0000 | [diff] [blame] | 105 | } |
| 106 | MCSymbol *MCContext::GetDirectionalLocalSymbol(int64_t LocalLabelVal, |
| 107 | int bORf) { |
| 108 | return GetOrCreateSymbol(Twine(MAI.getPrivateGlobalPrefix()) + |
| 109 | Twine(LocalLabelVal) + |
| 110 | "\2" + |
Duncan Sands | 3472766 | 2010-07-12 08:16:59 +0000 | [diff] [blame] | 111 | Twine(GetInstance(LocalLabelVal) + bORf)); |
Kevin Enderby | ebe7fcd | 2010-05-17 23:08:19 +0000 | [diff] [blame] | 112 | } |
| 113 | |
Daniel Dunbar | 2928c83 | 2009-11-06 10:58:06 +0000 | [diff] [blame] | 114 | MCSymbol *MCContext::LookupSymbol(StringRef Name) const { |
Daniel Dunbar | ecc63f8 | 2009-06-23 22:01:43 +0000 | [diff] [blame] | 115 | return Symbols.lookup(Name); |
| 116 | } |
Chris Lattner | f0559e4 | 2010-04-08 20:30:37 +0000 | [diff] [blame] | 117 | |
| 118 | //===----------------------------------------------------------------------===// |
| 119 | // Section Management |
| 120 | //===----------------------------------------------------------------------===// |
| 121 | |
| 122 | const MCSectionMachO *MCContext:: |
| 123 | getMachOSection(StringRef Segment, StringRef Section, |
| 124 | unsigned TypeAndAttributes, |
| 125 | unsigned Reserved2, SectionKind Kind) { |
Michael J. Spencer | 326990f | 2010-11-26 04:16:08 +0000 | [diff] [blame^] | 126 | |
Chris Lattner | f0559e4 | 2010-04-08 20:30:37 +0000 | [diff] [blame] | 127 | // We unique sections by their segment/section pair. The returned section |
| 128 | // may not have the same flags as the requested section, if so this should be |
| 129 | // diagnosed by the client as an error. |
Michael J. Spencer | 326990f | 2010-11-26 04:16:08 +0000 | [diff] [blame^] | 130 | |
Chris Lattner | f0559e4 | 2010-04-08 20:30:37 +0000 | [diff] [blame] | 131 | // Create the map if it doesn't already exist. |
| 132 | if (MachOUniquingMap == 0) |
| 133 | MachOUniquingMap = new MachOUniqueMapTy(); |
| 134 | MachOUniqueMapTy &Map = *(MachOUniqueMapTy*)MachOUniquingMap; |
Michael J. Spencer | 326990f | 2010-11-26 04:16:08 +0000 | [diff] [blame^] | 135 | |
Chris Lattner | f0559e4 | 2010-04-08 20:30:37 +0000 | [diff] [blame] | 136 | // Form the name to look up. |
| 137 | SmallString<64> Name; |
| 138 | Name += Segment; |
| 139 | Name.push_back(','); |
| 140 | Name += Section; |
Michael J. Spencer | 326990f | 2010-11-26 04:16:08 +0000 | [diff] [blame^] | 141 | |
Chris Lattner | f0559e4 | 2010-04-08 20:30:37 +0000 | [diff] [blame] | 142 | // Do the lookup, if we have a hit, return it. |
| 143 | const MCSectionMachO *&Entry = Map[Name.str()]; |
| 144 | if (Entry) return Entry; |
Michael J. Spencer | 326990f | 2010-11-26 04:16:08 +0000 | [diff] [blame^] | 145 | |
Chris Lattner | f0559e4 | 2010-04-08 20:30:37 +0000 | [diff] [blame] | 146 | // Otherwise, return a new section. |
Chris Lattner | 74aae47 | 2010-04-08 21:26:26 +0000 | [diff] [blame] | 147 | return Entry = new (*this) MCSectionMachO(Segment, Section, TypeAndAttributes, |
| 148 | Reserved2, Kind); |
Chris Lattner | f0559e4 | 2010-04-08 20:30:37 +0000 | [diff] [blame] | 149 | } |
Chris Lattner | 74aae47 | 2010-04-08 21:26:26 +0000 | [diff] [blame] | 150 | |
Rafael Espindola | 4283f4b | 2010-11-10 19:05:07 +0000 | [diff] [blame] | 151 | const MCSectionELF *MCContext:: |
Chris Lattner | 74aae47 | 2010-04-08 21:26:26 +0000 | [diff] [blame] | 152 | getELFSection(StringRef Section, unsigned Type, unsigned Flags, |
Rafael Espindola | 2ff9e83 | 2010-11-11 18:13:52 +0000 | [diff] [blame] | 153 | SectionKind Kind) { |
| 154 | return getELFSection(Section, Type, Flags, Kind, 0, ""); |
| 155 | } |
| 156 | |
| 157 | const MCSectionELF *MCContext:: |
| 158 | getELFSection(StringRef Section, unsigned Type, unsigned Flags, |
| 159 | SectionKind Kind, unsigned EntrySize, StringRef Group) { |
Chris Lattner | 74aae47 | 2010-04-08 21:26:26 +0000 | [diff] [blame] | 160 | if (ELFUniquingMap == 0) |
| 161 | ELFUniquingMap = new ELFUniqueMapTy(); |
| 162 | ELFUniqueMapTy &Map = *(ELFUniqueMapTy*)ELFUniquingMap; |
Michael J. Spencer | 326990f | 2010-11-26 04:16:08 +0000 | [diff] [blame^] | 163 | |
Chris Lattner | 74aae47 | 2010-04-08 21:26:26 +0000 | [diff] [blame] | 164 | // Do the lookup, if we have a hit, return it. |
| 165 | StringMapEntry<const MCSectionELF*> &Entry = Map.GetOrCreateValue(Section); |
| 166 | if (Entry.getValue()) return Entry.getValue(); |
Michael J. Spencer | 326990f | 2010-11-26 04:16:08 +0000 | [diff] [blame^] | 167 | |
Jan Wen Voung | 186e7a0 | 2010-09-30 05:59:22 +0000 | [diff] [blame] | 168 | // Possibly refine the entry size first. |
| 169 | if (!EntrySize) { |
| 170 | EntrySize = MCSectionELF::DetermineEntrySize(Kind); |
| 171 | } |
Rafael Espindola | 2ff9e83 | 2010-11-11 18:13:52 +0000 | [diff] [blame] | 172 | |
| 173 | MCSymbol *GroupSym = NULL; |
| 174 | if (!Group.empty()) |
| 175 | GroupSym = GetOrCreateSymbol(Group); |
| 176 | |
Chris Lattner | 74aae47 | 2010-04-08 21:26:26 +0000 | [diff] [blame] | 177 | MCSectionELF *Result = new (*this) MCSectionELF(Entry.getKey(), Type, Flags, |
Rafael Espindola | 2ff9e83 | 2010-11-11 18:13:52 +0000 | [diff] [blame] | 178 | Kind, EntrySize, GroupSym); |
Chris Lattner | 74aae47 | 2010-04-08 21:26:26 +0000 | [diff] [blame] | 179 | Entry.setValue(Result); |
| 180 | return Result; |
| 181 | } |
| 182 | |
Rafael Espindola | 2ff9e83 | 2010-11-11 18:13:52 +0000 | [diff] [blame] | 183 | const MCSectionELF *MCContext::CreateELFGroupSection() { |
| 184 | MCSectionELF *Result = |
| 185 | new (*this) MCSectionELF(".group", MCSectionELF::SHT_GROUP, 0, |
| 186 | SectionKind::getReadOnly(), 4, NULL); |
| 187 | return Result; |
| 188 | } |
| 189 | |
Chris Lattner | 6e5ce28 | 2010-05-07 21:49:09 +0000 | [diff] [blame] | 190 | const MCSection *MCContext::getCOFFSection(StringRef Section, |
| 191 | unsigned Characteristics, |
| 192 | int Selection, |
| 193 | SectionKind Kind) { |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 194 | if (COFFUniquingMap == 0) |
| 195 | COFFUniquingMap = new COFFUniqueMapTy(); |
| 196 | COFFUniqueMapTy &Map = *(COFFUniqueMapTy*)COFFUniquingMap; |
Michael J. Spencer | 326990f | 2010-11-26 04:16:08 +0000 | [diff] [blame^] | 197 | |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 198 | // Do the lookup, if we have a hit, return it. |
| 199 | StringMapEntry<const MCSectionCOFF*> &Entry = Map.GetOrCreateValue(Section); |
| 200 | if (Entry.getValue()) return Entry.getValue(); |
Michael J. Spencer | 326990f | 2010-11-26 04:16:08 +0000 | [diff] [blame^] | 201 | |
Chris Lattner | 6e5ce28 | 2010-05-07 21:49:09 +0000 | [diff] [blame] | 202 | MCSectionCOFF *Result = new (*this) MCSectionCOFF(Entry.getKey(), |
| 203 | Characteristics, |
| 204 | Selection, Kind); |
Michael J. Spencer | 326990f | 2010-11-26 04:16:08 +0000 | [diff] [blame^] | 205 | |
Chris Lattner | eb40a0f | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 206 | Entry.setValue(Result); |
| 207 | return Result; |
| 208 | } |
Kevin Enderby | 7cbf73a | 2010-07-28 20:55:35 +0000 | [diff] [blame] | 209 | |
| 210 | //===----------------------------------------------------------------------===// |
| 211 | // Dwarf Management |
| 212 | //===----------------------------------------------------------------------===// |
| 213 | |
| 214 | /// GetDwarfFile - takes a file name an number to place in the dwarf file and |
| 215 | /// directory tables. If the file number has already been allocated it is an |
| 216 | /// error and zero is returned and the client reports the error, else the |
| 217 | /// allocated file number is returned. The file numbers may be in any order. |
| 218 | unsigned MCContext::GetDwarfFile(StringRef FileName, unsigned FileNumber) { |
| 219 | // TODO: a FileNumber of zero says to use the next available file number. |
| 220 | // Note: in GenericAsmParser::ParseDirectiveFile() FileNumber was checked |
| 221 | // to not be less than one. This needs to be change to be not less than zero. |
| 222 | |
| 223 | // Make space for this FileNumber in the MCDwarfFiles vector if needed. |
| 224 | if (FileNumber >= MCDwarfFiles.size()) { |
| 225 | MCDwarfFiles.resize(FileNumber + 1); |
| 226 | } else { |
| 227 | MCDwarfFile *&ExistingFile = MCDwarfFiles[FileNumber]; |
| 228 | if (ExistingFile) |
| 229 | // It is an error to use see the same number more than once. |
| 230 | return 0; |
| 231 | } |
| 232 | |
| 233 | // Get the new MCDwarfFile slot for this FileNumber. |
| 234 | MCDwarfFile *&File = MCDwarfFiles[FileNumber]; |
| 235 | |
| 236 | // Separate the directory part from the basename of the FileName. |
| 237 | std::pair<StringRef, StringRef> Slash = FileName.rsplit('/'); |
| 238 | |
| 239 | // Find or make a entry in the MCDwarfDirs vector for this Directory. |
Kevin Enderby | 7cbf73a | 2010-07-28 20:55:35 +0000 | [diff] [blame] | 240 | StringRef Name; |
| 241 | unsigned DirIndex; |
| 242 | // Capture directory name. |
| 243 | if (Slash.second.empty()) { |
| 244 | Name = Slash.first; |
| 245 | DirIndex = 0; // For FileNames with no directories a DirIndex of 0 is used. |
| 246 | } else { |
Benjamin Kramer | 3bce5ad | 2010-07-29 13:53:19 +0000 | [diff] [blame] | 247 | StringRef Directory = Slash.first; |
Kevin Enderby | 7cbf73a | 2010-07-28 20:55:35 +0000 | [diff] [blame] | 248 | Name = Slash.second; |
Kevin Enderby | b07ce60 | 2010-08-09 22:52:14 +0000 | [diff] [blame] | 249 | for (DirIndex = 0; DirIndex < MCDwarfDirs.size(); DirIndex++) { |
Benjamin Kramer | 3bce5ad | 2010-07-29 13:53:19 +0000 | [diff] [blame] | 250 | if (Directory == MCDwarfDirs[DirIndex]) |
Kevin Enderby | 232ab94 | 2010-08-31 22:55:11 +0000 | [diff] [blame] | 251 | break; |
Kevin Enderby | 7cbf73a | 2010-07-28 20:55:35 +0000 | [diff] [blame] | 252 | } |
| 253 | if (DirIndex >= MCDwarfDirs.size()) { |
Benjamin Kramer | 3bce5ad | 2010-07-29 13:53:19 +0000 | [diff] [blame] | 254 | char *Buf = static_cast<char *>(Allocate(Directory.size())); |
| 255 | memcpy(Buf, Directory.data(), Directory.size()); |
| 256 | MCDwarfDirs.push_back(StringRef(Buf, Directory.size())); |
Kevin Enderby | 7cbf73a | 2010-07-28 20:55:35 +0000 | [diff] [blame] | 257 | } |
Kevin Enderby | b07ce60 | 2010-08-09 22:52:14 +0000 | [diff] [blame] | 258 | // The DirIndex is one based, as DirIndex of 0 is used for FileNames with |
| 259 | // no directories. MCDwarfDirs[] is unlike MCDwarfFiles[] in that the |
| 260 | // directory names are stored at MCDwarfDirs[DirIndex-1] where FileNames are |
| 261 | // stored at MCDwarfFiles[FileNumber].Name . |
| 262 | DirIndex++; |
Kevin Enderby | 7cbf73a | 2010-07-28 20:55:35 +0000 | [diff] [blame] | 263 | } |
Michael J. Spencer | 326990f | 2010-11-26 04:16:08 +0000 | [diff] [blame^] | 264 | |
Kevin Enderby | 7cbf73a | 2010-07-28 20:55:35 +0000 | [diff] [blame] | 265 | // Now make the MCDwarfFile entry and place it in the slot in the MCDwarfFiles |
| 266 | // vector. |
Benjamin Kramer | 3bce5ad | 2010-07-29 13:53:19 +0000 | [diff] [blame] | 267 | char *Buf = static_cast<char *>(Allocate(Name.size())); |
| 268 | memcpy(Buf, Name.data(), Name.size()); |
| 269 | File = new (*this) MCDwarfFile(StringRef(Buf, Name.size()), DirIndex); |
Kevin Enderby | 7cbf73a | 2010-07-28 20:55:35 +0000 | [diff] [blame] | 270 | |
| 271 | // return the allocated FileNumber. |
| 272 | return FileNumber; |
| 273 | } |
Kevin Enderby | c1840b3 | 2010-08-24 20:32:42 +0000 | [diff] [blame] | 274 | |
Kevin Enderby | 3f55c24 | 2010-10-04 20:17:24 +0000 | [diff] [blame] | 275 | /// isValidDwarfFileNumber - takes a dwarf file number and returns true if it |
Kevin Enderby | c1840b3 | 2010-08-24 20:32:42 +0000 | [diff] [blame] | 276 | /// currently is assigned and false otherwise. |
Kevin Enderby | 3f55c24 | 2010-10-04 20:17:24 +0000 | [diff] [blame] | 277 | bool MCContext::isValidDwarfFileNumber(unsigned FileNumber) { |
Kevin Enderby | c1840b3 | 2010-08-24 20:32:42 +0000 | [diff] [blame] | 278 | if(FileNumber == 0 || FileNumber >= MCDwarfFiles.size()) |
| 279 | return false; |
| 280 | |
Kevin Enderby | 3f55c24 | 2010-10-04 20:17:24 +0000 | [diff] [blame] | 281 | return MCDwarfFiles[FileNumber] != 0; |
Kevin Enderby | c1840b3 | 2010-08-24 20:32:42 +0000 | [diff] [blame] | 282 | } |