Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 1 | //===-- PIC16TargetObjectFile.cpp - PIC16 object files --------------------===// |
| 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 "PIC16TargetObjectFile.h" |
| 11 | #include "PIC16ISelLowering.h" |
| 12 | #include "PIC16TargetMachine.h" |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame] | 13 | #include "PIC16Section.h" |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 14 | #include "llvm/DerivedTypes.h" |
| 15 | #include "llvm/Module.h" |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 16 | #include "llvm/MC/MCSection.h" |
Chris Lattner | fbf1d27 | 2009-08-08 20:14:13 +0000 | [diff] [blame] | 17 | #include "llvm/MC/MCContext.h" |
Chris Lattner | 93b6db3 | 2009-08-08 23:39:42 +0000 | [diff] [blame] | 18 | #include "llvm/Support/raw_ostream.h" |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 19 | using namespace llvm; |
| 20 | |
Chris Lattner | 93b6db3 | 2009-08-08 23:39:42 +0000 | [diff] [blame] | 21 | |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame] | 22 | PIC16TargetObjectFile::PIC16TargetObjectFile() { |
Chris Lattner | 93b6db3 | 2009-08-08 23:39:42 +0000 | [diff] [blame] | 23 | } |
| 24 | |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame] | 25 | /// Find a pic16 section. If not found, create one. |
| 26 | PIC16Section *PIC16TargetObjectFile:: |
| 27 | getPIC16Section(const std::string &Name, PIC16SectionType Ty, |
| 28 | const std::string &Address, int Color) const { |
Chris Lattner | 93b6db3 | 2009-08-08 23:39:42 +0000 | [diff] [blame] | 29 | |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame] | 30 | /// Return if we have an already existing one. |
| 31 | PIC16Section *&Entry = SectionsByName[Name]; |
Chris Lattner | 873bc4c | 2009-08-13 00:26:52 +0000 | [diff] [blame] | 32 | if (Entry) |
| 33 | return Entry; |
| 34 | |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame] | 35 | |
| 36 | Entry = PIC16Section::Create(Name, Ty, Address, Color, getContext()); |
| 37 | return Entry; |
Chris Lattner | fbf1d27 | 2009-08-08 20:14:13 +0000 | [diff] [blame] | 38 | } |
| 39 | |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame] | 40 | /// Find a standard pic16 data section. If not found, create one and keep |
| 41 | /// track of it by adding it to appropriate std section list. |
| 42 | PIC16Section *PIC16TargetObjectFile:: |
| 43 | getPIC16DataSection(const std::string &Name, PIC16SectionType Ty, |
| 44 | const std::string &Address, int Color) const { |
Chris Lattner | fbf1d27 | 2009-08-08 20:14:13 +0000 | [diff] [blame] | 45 | |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame] | 46 | /// Return if we have an already existing one. |
| 47 | PIC16Section *&Entry = SectionsByName[Name]; |
| 48 | if (Entry) |
| 49 | return Entry; |
| 50 | |
| 51 | |
| 52 | /// Else create a new one and add it to appropriate section list. |
| 53 | Entry = PIC16Section::Create(Name, Ty, Address, Color, getContext()); |
| 54 | |
| 55 | switch (Ty) { |
| 56 | default: llvm_unreachable ("unknow standard section type."); |
| 57 | case UDATA: UDATASections_.push_back(Entry); break; |
| 58 | case IDATA: IDATASections_.push_back(Entry); break; |
| 59 | case ROMDATA: ROMDATASection_ = Entry; break; |
| 60 | } |
| 61 | |
| 62 | return Entry; |
| 63 | } |
| 64 | |
| 65 | |
| 66 | /// Find a standard pic16 autos section. If not found, create one and keep |
| 67 | /// track of it by adding it to appropriate std section list. |
| 68 | PIC16Section *PIC16TargetObjectFile:: |
| 69 | getPIC16AutoSection(const std::string &Name, PIC16SectionType Ty, |
| 70 | const std::string &Address, int Color) const { |
| 71 | |
| 72 | /// Return if we have an already existing one. |
| 73 | PIC16Section *&Entry = SectionsByName[Name]; |
| 74 | if (Entry) |
| 75 | return Entry; |
| 76 | |
| 77 | |
| 78 | /// Else create a new one and add it to appropriate section list. |
| 79 | Entry = PIC16Section::Create(Name, Ty, Address, Color, getContext()); |
| 80 | |
| 81 | assert (Ty == UDATA_OVR && "incorrect section type for autos"); |
| 82 | AUTOSections_.push_back(Entry); |
| 83 | |
| 84 | return Entry; |
| 85 | } |
| 86 | |
| 87 | /// Find a pic16 user section. If not found, create one and keep |
| 88 | /// track of it by adding it to appropriate std section list. |
| 89 | PIC16Section *PIC16TargetObjectFile:: |
| 90 | getPIC16UserSection(const std::string &Name, PIC16SectionType Ty, |
| 91 | const std::string &Address, int Color) const { |
| 92 | |
| 93 | /// Return if we have an already existing one. |
| 94 | PIC16Section *&Entry = SectionsByName[Name]; |
| 95 | if (Entry) |
| 96 | return Entry; |
| 97 | |
| 98 | |
| 99 | /// Else create a new one and add it to appropriate section list. |
| 100 | Entry = PIC16Section::Create(Name, Ty, Address, Color, getContext()); |
| 101 | |
| 102 | USERSections_.push_back(Entry); |
| 103 | |
| 104 | return Entry; |
| 105 | } |
| 106 | |
| 107 | /// Do some standard llvm stuff. PIC16 really does not need any of this. |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 108 | void PIC16TargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &tm){ |
| 109 | TargetLoweringObjectFile::Initialize(Ctx, tm); |
| 110 | TM = &tm; |
| 111 | |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame] | 112 | // BSSSection = getPIC16DataSection("udata.#", UDATA); |
| 113 | // ReadOnlySection = getPIC16DataSection("romdata.#", ROMDATA); |
| 114 | // DataSection = getPIC16DataSection("idata.#", IDATA); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 115 | |
| 116 | // Need because otherwise a .text symbol is emitted by DwarfWriter |
| 117 | // in BeginModule, and gpasm cribbs for that .text symbol. |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame] | 118 | // FIXME: below |
| 119 | // TextSection = getPIC16DataSection("", UDATA); |
| 120 | ROMDATASection_ = NULL; |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 121 | } |
| 122 | |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame] | 123 | /// allocateUDATA - Allocate a un-initialized global to an existing or new UDATA |
| 124 | /// section and return that section. |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 125 | const MCSection * |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame] | 126 | PIC16TargetObjectFile::allocateUDATA(const GlobalVariable *GV) const { |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 127 | assert(GV->hasInitializer() && "This global doesn't need space"); |
| 128 | Constant *C = GV->getInitializer(); |
| 129 | assert(C->isNullValue() && "Unitialized globals has non-zero initializer"); |
| 130 | |
| 131 | // Find how much space this global needs. |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 132 | const TargetData *TD = TM->getTargetData(); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 133 | const Type *Ty = C->getType(); |
| 134 | unsigned ValSize = TD->getTypeAllocSize(Ty); |
| 135 | |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame] | 136 | // Go through all UDATA Sections and assign this variable |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 137 | // to the first available section having enough space. |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame] | 138 | PIC16Section *Found = NULL; |
| 139 | for (unsigned i = 0; i < UDATASections_.size(); i++) { |
| 140 | if (DataBankSize - UDATASections_[i]->getSize() >= ValSize) { |
| 141 | Found = UDATASections_[i]; |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 142 | break; |
| 143 | } |
| 144 | } |
| 145 | |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame] | 146 | // No UDATA section spacious enough was found. Crate a new one. |
| 147 | if (!Found) { |
| 148 | std::string name = PAN::getUdataSectionName(UDATASections_.size()); |
| 149 | Found = getPIC16DataSection(name.c_str(), UDATA); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 150 | } |
| 151 | |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame] | 152 | // Insert the GV into this UDATA section. |
| 153 | Found->Items.push_back(GV); |
| 154 | Found->setSize(Found->getSize() + ValSize); |
| 155 | return Found; |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 156 | } |
| 157 | |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame] | 158 | /// allocateIDATA - allocate an initialized global into an existing |
| 159 | /// or new section and return that section. |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 160 | const MCSection * |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame] | 161 | PIC16TargetObjectFile::allocateIDATA(const GlobalVariable *GV) const{ |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 162 | assert(GV->hasInitializer() && "This global doesn't need space"); |
| 163 | Constant *C = GV->getInitializer(); |
| 164 | assert(!C->isNullValue() && "initialized globals has zero initializer"); |
| 165 | assert(GV->getType()->getAddressSpace() == PIC16ISD::RAM_SPACE && |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame] | 166 | "can allocate initialized RAM data only"); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 167 | |
| 168 | // Find how much space this global needs. |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 169 | const TargetData *TD = TM->getTargetData(); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 170 | const Type *Ty = C->getType(); |
| 171 | unsigned ValSize = TD->getTypeAllocSize(Ty); |
| 172 | |
| 173 | // Go through all IDATA Sections and assign this variable |
| 174 | // to the first available section having enough space. |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame] | 175 | PIC16Section *Found = NULL; |
| 176 | for (unsigned i = 0; i < IDATASections_.size(); i++) { |
| 177 | if (DataBankSize - IDATASections_[i]->getSize() >= ValSize) { |
| 178 | Found = IDATASections_[i]; |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 179 | break; |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | // No IDATA section spacious enough was found. Crate a new one. |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame] | 184 | if (!Found) { |
| 185 | std::string name = PAN::getIdataSectionName(IDATASections_.size()); |
| 186 | Found = getPIC16DataSection(name.c_str(), IDATA); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | // Insert the GV into this IDATA. |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame] | 190 | Found->Items.push_back(GV); |
| 191 | Found->setSize(Found->getSize() + ValSize); |
| 192 | return Found; |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 193 | } |
| 194 | |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame] | 195 | // Allocate a program memory variable into ROMDATA section. |
| 196 | const MCSection * |
| 197 | PIC16TargetObjectFile::allocateROMDATA(const GlobalVariable *GV) const { |
| 198 | |
| 199 | std::string name = PAN::getRomdataSectionName(); |
| 200 | PIC16Section *S = getPIC16DataSection(name.c_str(), ROMDATA); |
| 201 | |
| 202 | S->Items.push_back(GV); |
| 203 | return S; |
| 204 | } |
| 205 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 206 | // Get the section for an automatic variable of a function. |
| 207 | // For PIC16 they are globals only with mangled names. |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 208 | const MCSection * |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame] | 209 | PIC16TargetObjectFile::allocateAUTO(const GlobalVariable *GV) const { |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 210 | |
| 211 | const std::string name = PAN::getSectionNameForSym(GV->getName()); |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame] | 212 | PIC16Section *S = getPIC16AutoSection(name.c_str()); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 213 | |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame] | 214 | S->Items.push_back(GV); |
| 215 | return S; |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | |
| 219 | // Override default implementation to put the true globals into |
| 220 | // multiple data sections if required. |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 221 | const MCSection * |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 222 | PIC16TargetObjectFile::SelectSectionForGlobal(const GlobalValue *GV1, |
Chris Lattner | f9650c0 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 223 | SectionKind Kind, |
Chris Lattner | e53a600 | 2009-07-29 05:09:30 +0000 | [diff] [blame] | 224 | Mangler *Mang, |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 225 | const TargetMachine &TM) const { |
| 226 | // We select the section based on the initializer here, so it really |
| 227 | // has to be a GlobalVariable. |
| 228 | const GlobalVariable *GV = dyn_cast<GlobalVariable>(GV1); |
| 229 | if (!GV) |
Chris Lattner | f9650c0 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 230 | return TargetLoweringObjectFile::SelectSectionForGlobal(GV1, Kind, Mang,TM); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 231 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 232 | assert(GV->hasInitializer() && "A def without initializer?"); |
| 233 | |
| 234 | // First, if this is an automatic variable for a function, get the section |
| 235 | // name for it and return. |
| 236 | std::string name = GV->getName(); |
| 237 | if (PAN::isLocalName(name)) |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame] | 238 | return allocateAUTO(GV); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 239 | |
| 240 | // See if this is an uninitialized global. |
| 241 | const Constant *C = GV->getInitializer(); |
| 242 | if (C->isNullValue()) |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame] | 243 | return allocateUDATA(GV); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 244 | |
| 245 | // If this is initialized data in RAM. Put it in the correct IDATA section. |
| 246 | if (GV->getType()->getAddressSpace() == PIC16ISD::RAM_SPACE) |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame] | 247 | return allocateIDATA(GV); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 248 | |
| 249 | // This is initialized data in rom, put it in the readonly section. |
| 250 | if (GV->getType()->getAddressSpace() == PIC16ISD::ROM_SPACE) |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame] | 251 | return allocateROMDATA(GV); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 252 | |
| 253 | // Else let the default implementation take care of it. |
Chris Lattner | f9650c0 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 254 | return TargetLoweringObjectFile::SelectSectionForGlobal(GV, Kind, Mang,TM); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | PIC16TargetObjectFile::~PIC16TargetObjectFile() { |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame] | 258 | #if 0 |
| 259 | for (unsigned i = 0; i < UDATASections_.size(); i++) |
| 260 | delete UDATASections_[i]; |
| 261 | for (unsigned i = 0; i < IDATASections_.size(); i++) |
| 262 | delete IDATASections_[i]; |
| 263 | |
| 264 | delete ROMDATASection_; |
| 265 | |
| 266 | for (unsigned i = 0; i < AUTOSections_.size(); i++) |
| 267 | delete AUTOSections_[i]; |
| 268 | |
| 269 | for (unsigned i = 0; i < USERSections_.size(); i++) |
| 270 | delete USERSections_[i]; |
| 271 | #endif |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame] | 275 | /// getExplicitSectionGlobal - Allow the target to completely override |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 276 | /// section assignment of a global. |
Chris Lattner | 24f654c | 2009-08-06 16:39:58 +0000 | [diff] [blame] | 277 | const MCSection *PIC16TargetObjectFile:: |
| 278 | getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, |
| 279 | Mangler *Mang, const TargetMachine &TM) const { |
| 280 | assert(GV->hasSection()); |
| 281 | |
| 282 | if (const GlobalVariable *GVar = cast<GlobalVariable>(GV)) { |
| 283 | std::string SectName = GVar->getSection(); |
| 284 | // If address for a variable is specified, get the address and create |
| 285 | // section. |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame] | 286 | // FIXME: move this attribute checking in PAN. |
Chris Lattner | 24f654c | 2009-08-06 16:39:58 +0000 | [diff] [blame] | 287 | std::string AddrStr = "Address="; |
| 288 | if (SectName.compare(0, AddrStr.length(), AddrStr) == 0) { |
| 289 | std::string SectAddr = SectName.substr(AddrStr.length()); |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame] | 290 | return allocateAtGivenAddress(GVar, SectAddr); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 291 | } |
Chris Lattner | 24f654c | 2009-08-06 16:39:58 +0000 | [diff] [blame] | 292 | |
| 293 | // Create the section specified with section attribute. |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame] | 294 | return allocateInGivenSection(GVar); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 295 | } |
| 296 | |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame] | 297 | return getPIC16DataSection(GV->getSection().c_str(), UDATA); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 298 | } |
| 299 | |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame] | 300 | // Interface used by AsmPrinter to get a code section for a function. |
| 301 | const PIC16Section * |
| 302 | PIC16TargetObjectFile::SectionForCode(const std::string &FnName) const { |
| 303 | const std::string &sec_name = PAN::getCodeSectionName(FnName); |
| 304 | return getPIC16Section(sec_name, CODE); |
| 305 | } |
| 306 | |
| 307 | // Interface used by AsmPrinter to get a frame section for a function. |
| 308 | const PIC16Section * |
| 309 | PIC16TargetObjectFile::SectionForFrame(const std::string &FnName) const { |
| 310 | const std::string &sec_name = PAN::getFrameSectionName(FnName); |
| 311 | return getPIC16Section(sec_name, UDATA_OVR); |
| 312 | } |
| 313 | |
| 314 | // Allocate a global var in existing or new section of given name. |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 315 | const MCSection * |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame] | 316 | PIC16TargetObjectFile::allocateInGivenSection(const GlobalVariable *GV) const { |
| 317 | // Determine the type of section that we need to create. |
| 318 | PIC16SectionType SecTy; |
| 319 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 320 | // See if this is an uninitialized global. |
| 321 | const Constant *C = GV->getInitializer(); |
| 322 | if (C->isNullValue()) |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame] | 323 | SecTy = UDATA; |
Daniel Dunbar | 1ead150 | 2009-10-15 15:02:14 +0000 | [diff] [blame] | 324 | // If this is initialized data in RAM. Put it in the correct IDATA section. |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame] | 325 | else if (GV->getType()->getAddressSpace() == PIC16ISD::RAM_SPACE) |
| 326 | SecTy = IDATA; |
Daniel Dunbar | 1ead150 | 2009-10-15 15:02:14 +0000 | [diff] [blame] | 327 | // This is initialized data in rom, put it in the readonly section. |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame] | 328 | else if (GV->getType()->getAddressSpace() == PIC16ISD::ROM_SPACE) |
| 329 | SecTy = ROMDATA; |
| 330 | else |
| 331 | llvm_unreachable ("Could not determine section type for global"); |
Daniel Dunbar | 1ead150 | 2009-10-15 15:02:14 +0000 | [diff] [blame] | 332 | |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame] | 333 | PIC16Section *S = getPIC16UserSection(GV->getSection().c_str(), SecTy); |
| 334 | S->Items.push_back(GV); |
| 335 | return S; |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 336 | } |
| 337 | |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame] | 338 | // Allocate a global var in a new absolute sections at given address. |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 339 | const MCSection * |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame] | 340 | PIC16TargetObjectFile::allocateAtGivenAddress(const GlobalVariable *GV, |
| 341 | const std::string &Addr) const { |
| 342 | // Determine the type of section that we need to create. |
| 343 | PIC16SectionType SecTy; |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 344 | |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame] | 345 | // See if this is an uninitialized global. |
| 346 | const Constant *C = GV->getInitializer(); |
| 347 | if (C->isNullValue()) |
| 348 | SecTy = UDATA; |
| 349 | // If this is initialized data in RAM. Put it in the correct IDATA section. |
| 350 | else if (GV->getType()->getAddressSpace() == PIC16ISD::RAM_SPACE) |
| 351 | SecTy = IDATA; |
| 352 | // This is initialized data in rom, put it in the readonly section. |
| 353 | else if (GV->getType()->getAddressSpace() == PIC16ISD::ROM_SPACE) |
| 354 | SecTy = ROMDATA; |
| 355 | else |
| 356 | llvm_unreachable ("Could not determine section type for global"); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 357 | |
Sanjiv Gupta | 753ec15 | 2009-10-15 19:26:25 +0000 | [diff] [blame] | 358 | std::string Prefix = GV->getNameStr() + "." + Addr + "."; |
| 359 | std::string SName = PAN::getUserSectionName(Prefix); |
| 360 | PIC16Section *S = getPIC16UserSection(SName.c_str(), SecTy, Addr.c_str()); |
| 361 | S->Items.push_back(GV); |
| 362 | return S; |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 363 | } |
| 364 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 365 | |