blob: 1aebe09209cc848cea29082e7558bf383d735670 [file] [log] [blame]
Sanjiv Gupta0e687712008-05-13 09:02:57 +00001//===-- PIC16AsmPrinter.cpp - PIC16 LLVM assembly writer ------------------===//
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 a printer that converts from our internal representation
11// of machine-dependent LLVM code to PIC16 assembly language.
12//
13//===----------------------------------------------------------------------===//
14
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000015#include "PIC16AsmPrinter.h"
16#include "PIC16TargetAsmInfo.h"
Bill Wendlingcb819f12009-02-18 23:12:06 +000017#include "llvm/DerivedTypes.h"
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000018#include "llvm/Function.h"
19#include "llvm/Module.h"
Bill Wendlingcb819f12009-02-18 23:12:06 +000020#include "llvm/CodeGen/DwarfWriter.h"
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000021#include "llvm/CodeGen/MachineFrameInfo.h"
Bill Wendlingcb819f12009-02-18 23:12:06 +000022#include "llvm/Support/raw_ostream.h"
23#include "llvm/Support/Mangler.h"
Sanjiv Gupta5274a4a2009-04-02 18:03:10 +000024#include "llvm/CodeGen/DwarfWriter.h"
25#include "llvm/CodeGen/MachineModuleInfo.h"
Sanjiv Gupta0e687712008-05-13 09:02:57 +000026
27using namespace llvm;
28
Sanjiv Gupta0e687712008-05-13 09:02:57 +000029#include "PIC16GenAsmWriter.inc"
Sanjiv Gupta1b046942009-01-13 19:18:47 +000030
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000031bool PIC16AsmPrinter::printMachineInstruction(const MachineInstr *MI) {
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000032 printInstruction(MI);
33 return true;
34}
35
36/// runOnMachineFunction - This uses the printInstruction()
37/// method to print assembly for each instruction.
38///
39bool PIC16AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
Bill Wendling57f0db82009-02-24 08:30:20 +000040 this->MF = &MF;
41
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000042 // This calls the base class function required to be called at beginning
43 // of runOnMachineFunction.
44 SetupMachineFunction(MF);
45
46 // Get the mangled name.
47 const Function *F = MF.getFunction();
48 CurrentFnName = Mang->getValueName(F);
49
50 // Emit the function variables.
51 emitFunctionData(MF);
Sanjiv Gupta211f3622009-05-10 05:23:47 +000052 const char *codeSection = PAN::getCodeSectionName(CurrentFnName).c_str();
53
54 const Section *fCodeSection = TAI->getNamedSection(codeSection,
55 SectionFlags::Code);
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000056 O << "\n";
Sanjiv Gupta211f3622009-05-10 05:23:47 +000057 // Start the Code Section.
Sanjiv Gupta1b046942009-01-13 19:18:47 +000058 SwitchToSection (fCodeSection);
Sanjiv Guptac1fa70c2009-04-08 06:24:04 +000059
60 // Emit the frame address of the function at the beginning of code.
Sanjiv Gupta211f3622009-05-10 05:23:47 +000061 O << "\tretlw low(" << PAN::getFrameLabel(CurrentFnName) << ")\n";
62 O << "\tretlw high(" << PAN::getFrameLabel(CurrentFnName) << ")\n";
Sanjiv Gupta7836fc12009-04-08 05:38:48 +000063
Sanjiv Gupta211f3622009-05-10 05:23:47 +000064 // Emit function start label.
65 O << CurrentFnName << ":\n";
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000066
67 // Print out code for the function.
68 for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
69 I != E; ++I) {
70 // Print a label for the basic block.
71 if (I != MF.begin()) {
72 printBasicBlockLabel(I, true);
73 O << '\n';
74 }
Sanjiv Guptac1fa70c2009-04-08 06:24:04 +000075
76 // For emitting line directives, we need to keep track of the current
77 // source line. When it changes then only emit the line directive.
78 unsigned CurLine = 0;
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000079 for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
80 II != E; ++II) {
Sanjiv Guptac1fa70c2009-04-08 06:24:04 +000081 // Emit the line directive if source line changed.
82 const DebugLoc DL = II->getDebugLoc();
83 if (!DL.isUnknown()) {
84 unsigned line = MF.getDebugLocTuple(DL).Line;
85 if (line != CurLine) {
86 O << "\t.line " << line << "\n";
87 CurLine = line;
88 }
89 }
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000090 // Print the assembly for the instruction.
Sanjiv Guptac1fa70c2009-04-08 06:24:04 +000091 printMachineInstruction(II);
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000092 }
93 }
94 return false; // we didn't modify anything.
95}
96
Sanjiv Gupta0e687712008-05-13 09:02:57 +000097/// createPIC16CodePrinterPass - Returns a pass that prints the PIC16
98/// assembly code for a MachineFunction to the given output stream,
99/// using the given target machine description. This should work
100/// regardless of whether the function is in SSA form.
101///
Owen Andersoncb371882008-08-21 00:14:44 +0000102FunctionPass *llvm::createPIC16CodePrinterPass(raw_ostream &o,
Bill Wendling57f0db82009-02-24 08:30:20 +0000103 PIC16TargetMachine &tm,
Bill Wendling98a366d2009-04-29 23:29:43 +0000104 CodeGenOpt::Level OptLevel,
Bill Wendlingbe8cc2a2009-04-29 00:15:41 +0000105 bool verbose) {
106 return new PIC16AsmPrinter(o, tm, tm.getTargetAsmInfo(), OptLevel, verbose);
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000107}
108
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000109void PIC16AsmPrinter::printOperand(const MachineInstr *MI, int opNum) {
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000110 const MachineOperand &MO = MI->getOperand(opNum);
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000111
Sanjiv Gupta2010b3e2008-05-14 11:31:39 +0000112 switch (MO.getType()) {
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000113 case MachineOperand::MO_Register:
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000114 if (TargetRegisterInfo::isPhysicalRegister(MO.getReg()))
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000115 O << TM.getRegisterInfo()->get(MO.getReg()).AsmName;
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000116 else
117 assert(0 && "not implemented");
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000118 return;
Sanjiv Gupta2010b3e2008-05-14 11:31:39 +0000119
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000120 case MachineOperand::MO_Immediate:
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000121 O << (int)MO.getImm();
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000122 return;
Sanjiv Gupta2010b3e2008-05-14 11:31:39 +0000123
Sanjiv Gupta2bdf4902009-04-20 16:59:35 +0000124 case MachineOperand::MO_GlobalAddress: {
Sanjiv Gupta211f3622009-05-10 05:23:47 +0000125 O << Mang->getValueName(MO.getGlobal());
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000126 break;
Sanjiv Gupta2bdf4902009-04-20 16:59:35 +0000127 }
128 case MachineOperand::MO_ExternalSymbol: {
129 std::string Name = MO.getSymbolName();
Sanjiv Gupta211f3622009-05-10 05:23:47 +0000130 O << MO.getSymbolName();
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000131 break;
Sanjiv Gupta2bdf4902009-04-20 16:59:35 +0000132 }
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000133 case MachineOperand::MO_MachineBasicBlock:
134 printBasicBlockLabel(MO.getMBB());
135 return;
136
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000137 default:
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000138 assert(0 && " Operand type not supported.");
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000139 }
140}
141
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000142void PIC16AsmPrinter::printCCOperand(const MachineInstr *MI, int opNum) {
143 int CC = (int)MI->getOperand(opNum).getImm();
144 O << PIC16CondCodeToString((PIC16CC::CondCodes)CC);
145}
146
147
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000148bool PIC16AsmPrinter::doInitialization (Module &M) {
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000149 bool Result = AsmPrinter::doInitialization(M);
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000150 // FIXME:: This is temporary solution to generate the include file.
151 // The processor should be passed to llc as in input and the header file
152 // should be generated accordingly.
153 O << "\t#include P16F1937.INC\n";
Sanjiv Gupta5274a4a2009-04-02 18:03:10 +0000154 MachineModuleInfo *MMI = getAnalysisIfAvailable<MachineModuleInfo>();
155 assert(MMI);
156 DwarfWriter *DW = getAnalysisIfAvailable<DwarfWriter>();
157 assert(DW && "Dwarf Writer is not available");
158 DW->BeginModule(&M, MMI, O, this, TAI);
159
Sanjiv Gupta8f78fa82008-11-26 10:53:50 +0000160 EmitExternsAndGlobals (M);
Sanjiv Guptad8d27f42009-05-06 08:02:01 +0000161 EmitGlobalData(M);
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000162 EmitRomData(M);
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000163 return Result;
164}
165
Sanjiv Gupta8f78fa82008-11-26 10:53:50 +0000166void PIC16AsmPrinter::EmitExternsAndGlobals (Module &M) {
167 // Emit declarations for external functions.
168 O << "section.0" <<"\n";
169 for (Module::iterator I = M.begin(), E = M.end(); I != E; I++) {
170 std::string Name = Mang->getValueName(I);
Sanjiv Gupta211f3622009-05-10 05:23:47 +0000171 if (Name.compare("@abort") == 0)
Sanjiv Gupta8f78fa82008-11-26 10:53:50 +0000172 continue;
Sanjiv Gupta85be4082009-04-14 02:49:52 +0000173
174 // If it is llvm intrinsic call then don't emit
175 if (Name.find("llvm.") != std::string::npos)
176 continue;
177
Sanjiv Guptaaf3fdb52009-05-10 16:18:39 +0000178 if (! (I->isDeclaration() || I->hasExternalLinkage()))
179 continue;
Sanjiv Gupta211f3622009-05-10 05:23:47 +0000180
181 const char *directive = I->isDeclaration() ? TAI->getExternDirective() :
182 TAI->getGlobalDirective();
183
184 O << directive << Name << "\n";
185 O << directive << PAN::getRetvalLabel(Name) << "\n";
186 O << directive << PAN::getArgsLabel(Name) << "\n";
Sanjiv Gupta8f78fa82008-11-26 10:53:50 +0000187 }
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000188
189 // Emit header file to include declaration of library functions
Sanjiv Gupta211f3622009-05-10 05:23:47 +0000190 // FIXME: find out libcall names.
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000191 O << "\t#include C16IntrinsicCalls.INC\n";
192
Sanjiv Gupta211f3622009-05-10 05:23:47 +0000193 // Emit declarations for external variable declarations and definitions.
Sanjiv Gupta8f78fa82008-11-26 10:53:50 +0000194 for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
195 I != E; I++) {
Sanjiv Gupta2cc75312009-02-10 04:20:26 +0000196 // Any variables reaching here with ".auto." in its name is a local scope
197 // variable and should not be printed in global data section.
Sanjiv Gupta8f78fa82008-11-26 10:53:50 +0000198 std::string Name = Mang->getValueName(I);
Sanjiv Gupta211f3622009-05-10 05:23:47 +0000199 if (PAN::isLocalName(Name))
Sanjiv Gupta2cc75312009-02-10 04:20:26 +0000200 continue;
201
Sanjiv Gupta211f3622009-05-10 05:23:47 +0000202 if (!(I->isDeclaration() || I->hasExternalLinkage() ||
203 I->hasCommonLinkage()))
204 continue;
205
206 const char *directive = I->isDeclaration() ? TAI->getExternDirective() :
207 TAI->getGlobalDirective();
208 O << directive << Name << "\n";
Sanjiv Gupta8f78fa82008-11-26 10:53:50 +0000209 }
210}
Sanjiv Gupta2cc75312009-02-10 04:20:26 +0000211
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000212void PIC16AsmPrinter::EmitRomData (Module &M)
213{
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000214 SwitchToSection(TAI->getReadOnlySection());
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000215 IsRomData = true;
Sanjiv Guptad0765702009-03-12 02:10:45 +0000216 for (Module::global_iterator I = M.global_begin(), E = M.global_end();
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000217 I != E; ++I) {
218 if (!I->hasInitializer()) // External global require no code.
219 continue;
220
221 Constant *C = I->getInitializer();
222 const PointerType *PtrTy = I->getType();
223 int AddrSpace = PtrTy->getAddressSpace();
224 if ((!C->isNullValue()) && (AddrSpace == PIC16ISD::ROM_SPACE)) {
225
226 if (EmitSpecialLLVMGlobal(I))
227 continue;
228
229 // Any variables reaching here with "." in its name is a local scope
230 // variable and should not be printed in global data section.
231 std::string name = Mang->getValueName(I);
Sanjiv Gupta211f3622009-05-10 05:23:47 +0000232 if (PAN::isLocalName(name))
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000233 continue;
234
Sanjiv Guptad0765702009-03-12 02:10:45 +0000235 I->setSection(TAI->getReadOnlySection()->getName());
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000236 O << name;
Sanjiv Guptac8d7bc82009-01-30 04:25:10 +0000237 EmitGlobalConstant(C, AddrSpace);
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000238 O << "\n";
239 }
240 }
241 IsRomData = false;
242}
243
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000244bool PIC16AsmPrinter::doFinalization(Module &M) {
245 O << "\t" << "END\n";
246 bool Result = AsmPrinter::doFinalization(M);
247 return Result;
248}
249
250void PIC16AsmPrinter::emitFunctionData(MachineFunction &MF) {
251 const Function *F = MF.getFunction();
252 std::string FuncName = Mang->getValueName(F);
Sanjiv Guptad0765702009-03-12 02:10:45 +0000253 Module *M = const_cast<Module *>(F->getParent());
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000254 const TargetData *TD = TM.getTargetData();
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000255 unsigned FrameSize = 0;
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000256 // Emit the data section name.
257 O << "\n";
Sanjiv Gupta211f3622009-05-10 05:23:47 +0000258 const char *SectionName = PAN::getFrameSectionName(CurrentFnName).c_str();
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000259
Sanjiv Gupta211f3622009-05-10 05:23:47 +0000260 const Section *fPDataSection = TAI->getNamedSection(SectionName,
Sanjiv Gupta2bdf4902009-04-20 16:59:35 +0000261 SectionFlags::Writeable);
262 SwitchToSection(fPDataSection);
Sanjiv Gupta8f78fa82008-11-26 10:53:50 +0000263
Sanjiv Guptab84d5a42009-04-02 17:42:00 +0000264 // Emit function frame label
Sanjiv Gupta211f3622009-05-10 05:23:47 +0000265 O << PAN::getFrameLabel(CurrentFnName) << ":\n";
Sanjiv Guptab84d5a42009-04-02 17:42:00 +0000266
Sanjiv Gupta8f78fa82008-11-26 10:53:50 +0000267 const Type *RetType = F->getReturnType();
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000268 unsigned RetSize = 0;
269 if (RetType->getTypeID() != Type::VoidTyID)
Duncan Sands777d2302009-05-09 07:06:46 +0000270 RetSize = TD->getTypeAllocSize(RetType);
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000271
Sanjiv Guptab84d5a42009-04-02 17:42:00 +0000272 //Emit function return value space
Sanjiv Gupta211f3622009-05-10 05:23:47 +0000273 // FIXME: Do not emit RetvalLable when retsize is zero. To do this
274 // we will need to avoid printing a global directive for Retval label
275 // in emitExternandGloblas.
Sanjiv Guptab84d5a42009-04-02 17:42:00 +0000276 if(RetSize > 0)
Sanjiv Gupta211f3622009-05-10 05:23:47 +0000277 O << PAN::getRetvalLabel(CurrentFnName) << " RES " << RetSize << "\n";
Sanjiv Guptab84d5a42009-04-02 17:42:00 +0000278 else
Sanjiv Gupta211f3622009-05-10 05:23:47 +0000279 O << PAN::getRetvalLabel(CurrentFnName) << ": \n";
Sanjiv Guptab84d5a42009-04-02 17:42:00 +0000280
281 // Emit variable to hold the space for function arguments
282 unsigned ArgSize = 0;
283 for (Function::const_arg_iterator argi = F->arg_begin(),
284 arge = F->arg_end(); argi != arge ; ++argi) {
285 const Type *Ty = argi->getType();
Duncan Sands777d2302009-05-09 07:06:46 +0000286 ArgSize += TD->getTypeAllocSize(Ty);
Sanjiv Guptab84d5a42009-04-02 17:42:00 +0000287 }
Sanjiv Gupta211f3622009-05-10 05:23:47 +0000288
289 O << PAN::getArgsLabel(CurrentFnName) << " RES " << ArgSize << "\n";
Sanjiv Guptab84d5a42009-04-02 17:42:00 +0000290
Sanjiv Gupta85be4082009-04-14 02:49:52 +0000291 // Emit temporary space
292 int TempSize = PTLI->GetTmpSize();
293 if (TempSize > 0 )
Sanjiv Gupta211f3622009-05-10 05:23:47 +0000294 O << PAN::getTempdataLabel(CurrentFnName) << " RES " << TempSize <<"\n";
Sanjiv Gupta2bdf4902009-04-20 16:59:35 +0000295
296 // Emit the section name for local variables.
297 O << "\n";
Sanjiv Gupta211f3622009-05-10 05:23:47 +0000298 const char* SecNameLocals = PAN::getAutosSectionName(CurrentFnName).c_str() ;
Sanjiv Gupta2bdf4902009-04-20 16:59:35 +0000299
Sanjiv Gupta211f3622009-05-10 05:23:47 +0000300 const Section *fADataSection = TAI->getNamedSection(SecNameLocals,
Sanjiv Gupta2bdf4902009-04-20 16:59:35 +0000301 SectionFlags::Writeable);
302 SwitchToSection(fADataSection);
Sanjiv Gupta85be4082009-04-14 02:49:52 +0000303
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000304 // Emit the function variables.
305
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000306 // In PIC16 all the function arguments and local variables are global.
307 // Therefore to get the variable belonging to this function entire
308 // global list will be traversed and variables belonging to this function
309 // will be emitted in the current data section.
Sanjiv Guptad0765702009-03-12 02:10:45 +0000310 for (Module::global_iterator I = M->global_begin(), E = M->global_end();
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000311 I != E; ++I) {
312 std::string VarName = Mang->getValueName(I);
313
314 // The variables of a function are of form FuncName.* . If this variable
315 // does not belong to this function then continue.
Sanjiv Gupta2cc75312009-02-10 04:20:26 +0000316 // Static local varilabes of a function does not have .auto. in their
317 // name. They are not printed as part of function data but module
318 // level global data.
Sanjiv Gupta211f3622009-05-10 05:23:47 +0000319 if (! PAN::isLocalToFunc(FuncName, VarName))
Sanjiv Guptad0765702009-03-12 02:10:45 +0000320 continue;
Sanjiv Gupta2cc75312009-02-10 04:20:26 +0000321
Sanjiv Gupta211f3622009-05-10 05:23:47 +0000322 I->setSection(TAI->SectionForGlobal(I)->getName());
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000323 Constant *C = I->getInitializer();
Sanjiv Gupta2010b3e2008-05-14 11:31:39 +0000324 const Type *Ty = C->getType();
Duncan Sands777d2302009-05-09 07:06:46 +0000325 unsigned Size = TD->getTypeAllocSize(Ty);
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000326 FrameSize += Size;
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000327 // Emit memory reserve directive.
Sanjiv Gupta211f3622009-05-10 05:23:47 +0000328 O << VarName << " RES " << Size << "\n";
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000329 }
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000330}
Sanjiv Guptad8d27f42009-05-06 08:02:01 +0000331
332void PIC16AsmPrinter::EmitGlobalData (Module &M)
333{
Sanjiv Gupta211f3622009-05-10 05:23:47 +0000334 // Set the section names for all globals.
335 for (Module::global_iterator I = M.global_begin(), E = M.global_end();
336 I != E; ++I) {
337 I->setSection(TAI->SectionForGlobal(I)->getName());
338 }
339
Sanjiv Guptad8d27f42009-05-06 08:02:01 +0000340 const PIC16TargetAsmInfo *PTAI = static_cast<const PIC16TargetAsmInfo *>(TAI);
Sanjiv Guptad8d27f42009-05-06 08:02:01 +0000341 const TargetData *TD = TM.getTargetData();
342
Sanjiv Gupta211f3622009-05-10 05:23:47 +0000343 // Now print all IDATA sections.
344 std::vector <PIC16Section *>IDATASections = PTAI->IDATASections;
Sanjiv Guptad8d27f42009-05-06 08:02:01 +0000345 for (unsigned i = 0; i < IDATASections.size(); i++) {
346 SwitchToSection(IDATASections[i]->S_);
347 std::vector<const GlobalVariable*> Items = IDATASections[i]->Items;
348 for (unsigned j = 0; j < Items.size(); j++) {
349 std::string Name = Mang->getValueName(Items[j]);
350 Constant *C = Items[j]->getInitializer();
351 int AddrSpace = Items[j]->getType()->getAddressSpace();
352 O << Name;
353 EmitGlobalConstant(C, AddrSpace);
354 }
355 }
356
Sanjiv Gupta211f3622009-05-10 05:23:47 +0000357 // Now print all BSS sections.
358 std::vector <PIC16Section *>BSSSections = PTAI->BSSSections;
Sanjiv Guptad8d27f42009-05-06 08:02:01 +0000359 for (unsigned i = 0; i < BSSSections.size(); i++) {
360 SwitchToSection(BSSSections[i]->S_);
361 std::vector<const GlobalVariable*> Items = BSSSections[i]->Items;
362 for (unsigned j = 0; j < Items.size(); j++) {
363 std::string Name = Mang->getValueName(Items[j]);
364 Constant *C = Items[j]->getInitializer();
365 const Type *Ty = C->getType();
Duncan Sands777d2302009-05-09 07:06:46 +0000366 unsigned Size = TD->getTypeAllocSize(Ty);
Sanjiv Guptad8d27f42009-05-06 08:02:01 +0000367
368 O << Name << " " <<"RES"<< " " << Size ;
369 O << "\n";
370 }
371 }
372}
373