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