blob: c855632d9f5a5c66c3de2cd69dfb05bcf402d0c8 [file] [log] [blame]
Sanjiv Gupta0e687712008-05-13 09:02:57 +00001//===-- PIC16TargetAsmInfo.cpp - PIC16 asm properties ---------------------===//
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// This file contains the declarations of the PIC16TargetAsmInfo properties.
11//
12//===----------------------------------------------------------------------===//
13
14#include "PIC16TargetAsmInfo.h"
Dan Gohman8f092252008-11-03 18:22:42 +000015#include "PIC16TargetMachine.h"
Sanjiv Gupta1b046942009-01-13 19:18:47 +000016#include "llvm/GlobalValue.h"
Sanjiv Guptad8d27f42009-05-06 08:02:01 +000017#include "llvm/GlobalVariable.h"
18#include "llvm/DerivedTypes.h"
Sanjiv Gupta0e687712008-05-13 09:02:57 +000019
20using namespace llvm;
21
22PIC16TargetAsmInfo::
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000023PIC16TargetAsmInfo(const PIC16TargetMachine &TM)
Dan Gohman8f092252008-11-03 18:22:42 +000024 : TargetAsmInfo(TM) {
Sanjiv Gupta0e687712008-05-13 09:02:57 +000025 CommentString = ";";
Sanjiv Gupta211f3622009-05-10 05:23:47 +000026 GlobalPrefix = PAN::getTagName(PAN::PREFIX_SYMBOL);
27 GlobalDirective = "\tglobal\t";
28 ExternDirective = "\textern\t";
29
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000030 Data8bitsDirective = " db ";
Sanjiv Guptac8d7bc82009-01-30 04:25:10 +000031 Data16bitsDirective = " dw ";
32 Data32bitsDirective = " dl ";
Sanjiv Gupta53cf8292009-07-06 18:09:11 +000033 Data64bitsDirective = NULL;
Sanjiv Guptac8d7bc82009-01-30 04:25:10 +000034 RomData8bitsDirective = " dw ";
35 RomData16bitsDirective = " rom_di ";
Sanjiv Gupta3b020fe2009-02-02 16:53:06 +000036 RomData32bitsDirective = " rom_dl ";
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000037 ZeroDirective = NULL;
Sanjiv Gupta1b046942009-01-13 19:18:47 +000038 AsciiDirective = " dt ";
39 AscizDirective = NULL;
Chris Lattner5fe575f2009-07-27 05:32:16 +000040 BSSSection_ = getNamedSection("udata.# UDATA", SectionKind::BSS);
41 ReadOnlySection = getNamedSection("romdata.# ROMDATA", SectionKind::ReadOnly);
42 DataSection = getNamedSection("idata.# IDATA", SectionKind::DataRel);
Sanjiv Gupta1b046942009-01-13 19:18:47 +000043 SwitchToSectionDirective = "";
Sanjiv Guptac1fa70c2009-04-08 06:24:04 +000044 // Need because otherwise a .text symbol is emitted by DwarfWriter
45 // in BeginModule, and gpasm cribbs for that .text symbol.
Chris Lattner5fe575f2009-07-27 05:32:16 +000046 TextSection = getUnnamedSection("", SectionKind::Text);
Sanjiv Gupta505996f2009-07-06 10:18:37 +000047 PIC16Section *ROSection = new PIC16Section(getReadOnlySection());
48 ROSections.push_back(ROSection);
Chris Lattner5fe575f2009-07-27 05:32:16 +000049
50 // FIXME: I don't know what the classification of these sections really is.
51 ExternalVarDecls = new PIC16Section(getNamedSection("ExternalVarDecls",
52 SectionKind::Metadata));
53 ExternalVarDefs = new PIC16Section(getNamedSection("ExternalVarDefs",
54 SectionKind::Metadata));
Sanjiv Guptadd4694b2009-05-28 18:24:11 +000055 // Set it to false because we weed to generate c file name and not bc file
56 // name.
57 HasSingleParameterDotFile = false;
Sanjiv Gupta0e687712008-05-13 09:02:57 +000058}
Sanjiv Guptac8d7bc82009-01-30 04:25:10 +000059
Chris Lattner83757c72009-07-20 17:12:46 +000060const char *PIC16TargetAsmInfo::getRomDirective(unsigned Size) const {
61 switch (Size) {
62 case 8: return RomData8bitsDirective;
63 case 16: return RomData16bitsDirective;
64 case 32: return RomData32bitsDirective;
65 default: return NULL;
66 }
Sanjiv Gupta3b020fe2009-02-02 16:53:06 +000067}
Sanjiv Guptac8d7bc82009-01-30 04:25:10 +000068
Sanjiv Guptac8d7bc82009-01-30 04:25:10 +000069
Chris Lattner83757c72009-07-20 17:12:46 +000070const char *PIC16TargetAsmInfo::
71getDataASDirective(unsigned Size, unsigned AS) const {
Sanjiv Gupta3b020fe2009-02-02 16:53:06 +000072 if (AS == PIC16ISD::ROM_SPACE)
Chris Lattner83757c72009-07-20 17:12:46 +000073 return getRomDirective(Size);
74 return NULL;
Sanjiv Gupta3b020fe2009-02-02 16:53:06 +000075}
Sanjiv Guptac8d7bc82009-01-30 04:25:10 +000076
Sanjiv Guptad8d27f42009-05-06 08:02:01 +000077const Section *
78PIC16TargetAsmInfo::getBSSSectionForGlobal(const GlobalVariable *GV) const {
Chris Lattnera46cb522009-07-21 17:20:18 +000079 assert(GV->hasInitializer() && "This global doesn't need space");
Sanjiv Guptad8d27f42009-05-06 08:02:01 +000080 Constant *C = GV->getInitializer();
Chris Lattnera46cb522009-07-21 17:20:18 +000081 assert(C->isNullValue() && "Unitialized globals has non-zero initializer");
Sanjiv Guptad8d27f42009-05-06 08:02:01 +000082
83 // Find how much space this global needs.
84 const TargetData *TD = TM.getTargetData();
85 const Type *Ty = C->getType();
Duncan Sands777d2302009-05-09 07:06:46 +000086 unsigned ValSize = TD->getTypeAllocSize(Ty);
Sanjiv Guptad8d27f42009-05-06 08:02:01 +000087
88 // Go through all BSS Sections and assign this variable
89 // to the first available section having enough space.
90 PIC16Section *FoundBSS = NULL;
91 for (unsigned i = 0; i < BSSSections.size(); i++) {
92 if (DataBankSize - BSSSections[i]->Size >= ValSize) {
93 FoundBSS = BSSSections[i];
94 break;
95 }
96 }
97
98 // No BSS section spacious enough was found. Crate a new one.
Chris Lattnera46cb522009-07-21 17:20:18 +000099 if (!FoundBSS) {
Sanjiv Gupta211f3622009-05-10 05:23:47 +0000100 std::string name = PAN::getUdataSectionName(BSSSections.size());
Chris Lattner5fe575f2009-07-27 05:32:16 +0000101 const Section *NewSection = getNamedSection(name.c_str(),
102 // FIXME.
103 SectionKind::Metadata);
Sanjiv Guptad8d27f42009-05-06 08:02:01 +0000104
105 FoundBSS = new PIC16Section(NewSection);
106
107 // Add this newly created BSS section to the list of BSSSections.
108 BSSSections.push_back(FoundBSS);
109 }
110
111 // Insert the GV into this BSS.
112 FoundBSS->Items.push_back(GV);
113 FoundBSS->Size += ValSize;
Sanjiv Guptad8d27f42009-05-06 08:02:01 +0000114 return FoundBSS->S_;
115}
116
117const Section *
118PIC16TargetAsmInfo::getIDATASectionForGlobal(const GlobalVariable *GV) const {
Chris Lattnera46cb522009-07-21 17:20:18 +0000119 assert(GV->hasInitializer() && "This global doesn't need space");
Sanjiv Guptad8d27f42009-05-06 08:02:01 +0000120 Constant *C = GV->getInitializer();
Chris Lattnera46cb522009-07-21 17:20:18 +0000121 assert(!C->isNullValue() && "initialized globals has zero initializer");
122 assert(GV->getType()->getAddressSpace() == PIC16ISD::RAM_SPACE &&
123 "can split initialized RAM data only");
Sanjiv Guptad8d27f42009-05-06 08:02:01 +0000124
125 // Find how much space this global needs.
126 const TargetData *TD = TM.getTargetData();
127 const Type *Ty = C->getType();
Duncan Sands777d2302009-05-09 07:06:46 +0000128 unsigned ValSize = TD->getTypeAllocSize(Ty);
Sanjiv Guptad8d27f42009-05-06 08:02:01 +0000129
130 // Go through all IDATA Sections and assign this variable
131 // to the first available section having enough space.
132 PIC16Section *FoundIDATA = NULL;
133 for (unsigned i = 0; i < IDATASections.size(); i++) {
Chris Lattnera46cb522009-07-21 17:20:18 +0000134 if (DataBankSize - IDATASections[i]->Size >= ValSize) {
Sanjiv Guptad8d27f42009-05-06 08:02:01 +0000135 FoundIDATA = IDATASections[i];
136 break;
137 }
138 }
139
140 // No IDATA section spacious enough was found. Crate a new one.
Chris Lattnera46cb522009-07-21 17:20:18 +0000141 if (!FoundIDATA) {
Sanjiv Gupta211f3622009-05-10 05:23:47 +0000142 std::string name = PAN::getIdataSectionName(IDATASections.size());
Chris Lattner5fe575f2009-07-27 05:32:16 +0000143 const Section *NewSection = getNamedSection(name.c_str(),
144 // FIXME.
145 SectionKind::Metadata);
Sanjiv Guptad8d27f42009-05-06 08:02:01 +0000146
147 FoundIDATA = new PIC16Section(NewSection);
148
149 // Add this newly created IDATA section to the list of IDATASections.
150 IDATASections.push_back(FoundIDATA);
151 }
152
153 // Insert the GV into this IDATA.
154 FoundIDATA->Items.push_back(GV);
155 FoundIDATA->Size += ValSize;
Sanjiv Guptad8d27f42009-05-06 08:02:01 +0000156 return FoundIDATA->S_;
157}
158
Sanjiv Gupta2364cfe2009-05-12 17:07:27 +0000159// Get the section for an automatic variable of a function.
160// For PIC16 they are globals only with mangled names.
161const Section *
162PIC16TargetAsmInfo::getSectionForAuto(const GlobalVariable *GV) const {
163
164 const std::string name = PAN::getSectionNameForSym(GV->getName());
165
166 // Go through all Auto Sections and assign this variable
167 // to the appropriate section.
168 PIC16Section *FoundAutoSec = NULL;
169 for (unsigned i = 0; i < AutosSections.size(); i++) {
Chris Lattnera46cb522009-07-21 17:20:18 +0000170 if (AutosSections[i]->S_->getName() == name) {
Sanjiv Gupta2364cfe2009-05-12 17:07:27 +0000171 FoundAutoSec = AutosSections[i];
172 break;
173 }
174 }
175
176 // No Auto section was found. Crate a new one.
Chris Lattnera46cb522009-07-21 17:20:18 +0000177 if (!FoundAutoSec) {
Chris Lattner5fe575f2009-07-27 05:32:16 +0000178 const Section *NewSection = getNamedSection(name.c_str(),
179 // FIXME.
180 SectionKind::Metadata);
Sanjiv Gupta2364cfe2009-05-12 17:07:27 +0000181
182 FoundAutoSec = new PIC16Section(NewSection);
183
184 // Add this newly created autos section to the list of AutosSections.
185 AutosSections.push_back(FoundAutoSec);
186 }
187
188 // Insert the auto into this section.
189 FoundAutoSec->Items.push_back(GV);
190
191 return FoundAutoSec->S_;
192}
193
194
Sanjiv Guptad8d27f42009-05-06 08:02:01 +0000195// Override default implementation to put the true globals into
196// multiple data sections if required.
197const Section*
Chris Lattnerf20f2502009-07-24 18:42:53 +0000198PIC16TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV1,
Chris Lattner460d51e2009-07-25 23:21:55 +0000199 SectionKind Kind) const {
Sanjiv Guptad8d27f42009-05-06 08:02:01 +0000200 // We select the section based on the initializer here, so it really
201 // has to be a GlobalVariable.
Sanjiv Gupta211f3622009-05-10 05:23:47 +0000202 const GlobalVariable *GV = dyn_cast<GlobalVariable>(GV1);
Sanjiv Guptaad6585b2009-05-13 15:13:17 +0000203 if (!GV)
Chris Lattnerf20f2502009-07-24 18:42:53 +0000204 return TargetAsmInfo::SelectSectionForGlobal(GV1, Kind);
Sanjiv Guptad8d27f42009-05-06 08:02:01 +0000205
Chris Lattnerf20f2502009-07-24 18:42:53 +0000206 // Record External Var Decls.
Sanjiv Guptaad6585b2009-05-13 15:13:17 +0000207 if (GV->isDeclaration()) {
208 ExternalVarDecls->Items.push_back(GV);
209 return ExternalVarDecls->S_;
210 }
211
Chris Lattnera46cb522009-07-21 17:20:18 +0000212 assert(GV->hasInitializer() && "A def without initializer?");
Sanjiv Guptaad6585b2009-05-13 15:13:17 +0000213
Sanjiv Gupta211f3622009-05-10 05:23:47 +0000214 // First, if this is an automatic variable for a function, get the section
215 // name for it and return.
Chris Lattner7420ab22009-07-24 18:34:27 +0000216 std::string name = GV->getName();
217 if (PAN::isLocalName(name))
Sanjiv Gupta2364cfe2009-05-12 17:07:27 +0000218 return getSectionForAuto(GV);
Sanjiv Guptad8d27f42009-05-06 08:02:01 +0000219
Sanjiv Guptaad6585b2009-05-13 15:13:17 +0000220 // Record Exteranl Var Defs.
Chris Lattner7420ab22009-07-24 18:34:27 +0000221 if (GV->hasExternalLinkage() || GV->hasCommonLinkage())
Sanjiv Guptaad6585b2009-05-13 15:13:17 +0000222 ExternalVarDefs->Items.push_back(GV);
Sanjiv Guptaad6585b2009-05-13 15:13:17 +0000223
Sanjiv Guptad8d27f42009-05-06 08:02:01 +0000224 // See if this is an uninitialized global.
Sanjiv Gupta211f3622009-05-10 05:23:47 +0000225 const Constant *C = GV->getInitializer();
Sanjiv Guptad8d27f42009-05-06 08:02:01 +0000226 if (C->isNullValue())
227 return getBSSSectionForGlobal(GV);
228
Sanjiv Gupta2364cfe2009-05-12 17:07:27 +0000229 // If this is initialized data in RAM. Put it in the correct IDATA section.
Sanjiv Guptad8d27f42009-05-06 08:02:01 +0000230 if (GV->getType()->getAddressSpace() == PIC16ISD::RAM_SPACE)
231 return getIDATASectionForGlobal(GV);
232
Sanjiv Gupta2364cfe2009-05-12 17:07:27 +0000233 // This is initialized data in rom, put it in the readonly section.
Sanjiv Gupta505996f2009-07-06 10:18:37 +0000234 if (GV->getType()->getAddressSpace() == PIC16ISD::ROM_SPACE)
235 return getROSectionForGlobal(GV);
Sanjiv Gupta2364cfe2009-05-12 17:07:27 +0000236
Sanjiv Guptad8d27f42009-05-06 08:02:01 +0000237 // Else let the default implementation take care of it.
Chris Lattnerf20f2502009-07-24 18:42:53 +0000238 return TargetAsmInfo::SelectSectionForGlobal(GV, Kind);
Sanjiv Guptad8d27f42009-05-06 08:02:01 +0000239}
240
Sanjiv Guptad8d27f42009-05-06 08:02:01 +0000241PIC16TargetAsmInfo::~PIC16TargetAsmInfo() {
Chris Lattnerb3e71892009-07-20 22:23:48 +0000242 for (unsigned i = 0; i < BSSSections.size(); i++)
243 delete BSSSections[i];
244 for (unsigned i = 0; i < IDATASections.size(); i++)
245 delete IDATASections[i];
246 for (unsigned i = 0; i < AutosSections.size(); i++)
247 delete AutosSections[i];
248 for (unsigned i = 0; i < ROSections.size(); i++)
249 delete ROSections[i];
Sanjiv Guptaad6585b2009-05-13 15:13:17 +0000250 delete ExternalVarDecls;
251 delete ExternalVarDefs;
Sanjiv Guptad8d27f42009-05-06 08:02:01 +0000252}
Sanjiv Gupta505996f2009-07-06 10:18:37 +0000253
Chris Lattner7420ab22009-07-24 18:34:27 +0000254
255/// getSpecialCasedSectionGlobals - Allow the target to completely override
256/// section assignment of a global.
257const Section *
258PIC16TargetAsmInfo::getSpecialCasedSectionGlobals(const GlobalValue *GV,
Chris Lattner460d51e2009-07-25 23:21:55 +0000259 SectionKind Kind) const {
Sanjiv Gupta505996f2009-07-06 10:18:37 +0000260 // If GV has a sectin name or section address create that section now.
261 if (GV->hasSection()) {
Chris Lattner7c023d62009-07-24 17:13:27 +0000262 if (const GlobalVariable *GVar = cast<GlobalVariable>(GV)) {
263 std::string SectName = GVar->getSection();
264 // If address for a variable is specified, get the address and create
265 // section.
266 std::string AddrStr = "Address=";
267 if (SectName.compare(0, AddrStr.length(), AddrStr) == 0) {
268 std::string SectAddr = SectName.substr(AddrStr.length());
269 return CreateSectionForGlobal(GVar, SectAddr);
270 }
Chris Lattner74fb5452009-07-26 18:08:15 +0000271
272 // Create the section specified with section attribute.
273 return CreateSectionForGlobal(GVar);
Chris Lattner796131e2009-07-24 04:59:43 +0000274 }
Sanjiv Gupta505996f2009-07-06 10:18:37 +0000275 }
Chris Lattner7420ab22009-07-24 18:34:27 +0000276
277 return 0;
Sanjiv Gupta505996f2009-07-06 10:18:37 +0000278}
279
280// Create a new section for global variable. If Addr is given then create
281// section at that address else create by name.
282const Section *
Chris Lattner7c023d62009-07-24 17:13:27 +0000283PIC16TargetAsmInfo::CreateSectionForGlobal(const GlobalVariable *GV,
284 const std::string &Addr) const {
Sanjiv Gupta505996f2009-07-06 10:18:37 +0000285 // See if this is an uninitialized global.
286 const Constant *C = GV->getInitializer();
287 if (C->isNullValue())
288 return CreateBSSSectionForGlobal(GV, Addr);
289
290 // If this is initialized data in RAM. Put it in the correct IDATA section.
291 if (GV->getType()->getAddressSpace() == PIC16ISD::RAM_SPACE)
292 return CreateIDATASectionForGlobal(GV, Addr);
293
294 // This is initialized data in rom, put it in the readonly section.
295 if (GV->getType()->getAddressSpace() == PIC16ISD::ROM_SPACE)
296 return CreateROSectionForGlobal(GV, Addr);
297
298 // Else let the default implementation take care of it.
299 return TargetAsmInfo::SectionForGlobal(GV);
300}
301
302// Create uninitialized section for a variable.
303const Section *
304PIC16TargetAsmInfo::CreateBSSSectionForGlobal(const GlobalVariable *GV,
305 std::string Addr) const {
Chris Lattnera46cb522009-07-21 17:20:18 +0000306 assert(GV->hasInitializer() && "This global doesn't need space");
307 assert(GV->getInitializer()->isNullValue() &&
308 "Unitialized global has non-zero initializer");
Sanjiv Gupta505996f2009-07-06 10:18:37 +0000309 std::string Name;
310 // If address is given then create a section at that address else create a
311 // section by section name specified in GV.
312 PIC16Section *FoundBSS = NULL;
313 if (Addr.empty()) {
314 Name = GV->getSection() + " UDATA";
315 for (unsigned i = 0; i < BSSSections.size(); i++) {
316 if (BSSSections[i]->S_->getName() == Name) {
317 FoundBSS = BSSSections[i];
318 break;
319 }
320 }
Chris Lattnera46cb522009-07-21 17:20:18 +0000321 } else {
Daniel Dunbarf6ccee52009-07-24 08:24:36 +0000322 std::string Prefix = GV->getNameStr() + "." + Addr + ".";
Sanjiv Gupta505996f2009-07-06 10:18:37 +0000323 Name = PAN::getUdataSectionName(BSSSections.size(), Prefix) + " " + Addr;
324 }
325
326 PIC16Section *NewBSS = FoundBSS;
327 if (NewBSS == NULL) {
Chris Lattner5fe575f2009-07-27 05:32:16 +0000328 const Section *NewSection = getNamedSection(Name.c_str(), SectionKind::BSS);
Sanjiv Gupta505996f2009-07-06 10:18:37 +0000329 NewBSS = new PIC16Section(NewSection);
330 BSSSections.push_back(NewBSS);
331 }
332
333 // Insert the GV into this BSS.
334 NewBSS->Items.push_back(GV);
335
336 // We do not want to put any GV without explicit section into this section
337 // so set its size to DatabankSize.
338 NewBSS->Size = DataBankSize;
339 return NewBSS->S_;
340}
341
342// Get rom section for a variable. Currently there can be only one rom section
343// unless a variable explicitly requests a section.
344const Section *
345PIC16TargetAsmInfo::getROSectionForGlobal(const GlobalVariable *GV) const {
346 ROSections[0]->Items.push_back(GV);
347 return ROSections[0]->S_;
348}
349
350// Create initialized data section for a variable.
351const Section *
352PIC16TargetAsmInfo::CreateIDATASectionForGlobal(const GlobalVariable *GV,
353 std::string Addr) const {
Chris Lattnera46cb522009-07-21 17:20:18 +0000354 assert(GV->hasInitializer() && "This global doesn't need space");
355 assert(!GV->getInitializer()->isNullValue() &&
356 "initialized global has zero initializer");
357 assert(GV->getType()->getAddressSpace() == PIC16ISD::RAM_SPACE &&
358 "can be used for initialized RAM data only");
Sanjiv Gupta505996f2009-07-06 10:18:37 +0000359
360 std::string Name;
361 // If address is given then create a section at that address else create a
362 // section by section name specified in GV.
363 PIC16Section *FoundIDATASec = NULL;
364 if (Addr.empty()) {
365 Name = GV->getSection() + " IDATA";
366 for (unsigned i = 0; i < IDATASections.size(); i++) {
367 if (IDATASections[i]->S_->getName() == Name) {
368 FoundIDATASec = IDATASections[i];
369 break;
370 }
371 }
Chris Lattnera46cb522009-07-21 17:20:18 +0000372 } else {
Daniel Dunbarf6ccee52009-07-24 08:24:36 +0000373 std::string Prefix = GV->getNameStr() + "." + Addr + ".";
Sanjiv Gupta505996f2009-07-06 10:18:37 +0000374 Name = PAN::getIdataSectionName(IDATASections.size(), Prefix) + " " + Addr;
375 }
376
377 PIC16Section *NewIDATASec = FoundIDATASec;
378 if (NewIDATASec == NULL) {
Chris Lattner5fe575f2009-07-27 05:32:16 +0000379 const Section *NewSection = getNamedSection(Name.c_str(),
380 // FIXME:
381 SectionKind::Metadata);
Sanjiv Gupta505996f2009-07-06 10:18:37 +0000382 NewIDATASec = new PIC16Section(NewSection);
383 IDATASections.push_back(NewIDATASec);
384 }
385 // Insert the GV into this IDATA Section.
386 NewIDATASec->Items.push_back(GV);
387 // We do not want to put any GV without explicit section into this section
388 // so set its size to DatabankSize.
389 NewIDATASec->Size = DataBankSize;
390 return NewIDATASec->S_;
391}
392
393// Create a section in rom for a variable.
394const Section *
395PIC16TargetAsmInfo::CreateROSectionForGlobal(const GlobalVariable *GV,
396 std::string Addr) const {
Chris Lattnera46cb522009-07-21 17:20:18 +0000397 assert(GV->getType()->getAddressSpace() == PIC16ISD::ROM_SPACE &&
398 "can be used for ROM data only");
Sanjiv Gupta505996f2009-07-06 10:18:37 +0000399
400 std::string Name;
401 // If address is given then create a section at that address else create a
402 // section by section name specified in GV.
403 PIC16Section *FoundROSec = NULL;
404 if (Addr.empty()) {
405 Name = GV->getSection() + " ROMDATA";
406 for (unsigned i = 1; i < ROSections.size(); i++) {
407 if (ROSections[i]->S_->getName() == Name) {
408 FoundROSec = ROSections[i];
409 break;
410 }
411 }
Chris Lattnera46cb522009-07-21 17:20:18 +0000412 } else {
Daniel Dunbarf6ccee52009-07-24 08:24:36 +0000413 std::string Prefix = GV->getNameStr() + "." + Addr + ".";
Sanjiv Gupta505996f2009-07-06 10:18:37 +0000414 Name = PAN::getRomdataSectionName(ROSections.size(), Prefix) + " " + Addr;
415 }
416
417 PIC16Section *NewRomSec = FoundROSec;
418 if (NewRomSec == NULL) {
Chris Lattner5fe575f2009-07-27 05:32:16 +0000419 const Section *NewSection = getNamedSection(Name.c_str(),
420 SectionKind::ReadOnly);
Sanjiv Gupta505996f2009-07-06 10:18:37 +0000421 NewRomSec = new PIC16Section(NewSection);
422 ROSections.push_back(NewRomSec);
423 }
424
425 // Insert the GV into this ROM Section.
426 NewRomSec->Items.push_back(GV);
427 return NewRomSec->S_;
428}
429