blob: 3e8ac016edcd079a600e7f90f573d263665cb366 [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 Gupta0608b492009-05-11 06:01:38 +000090
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000091 // Print the assembly for the instruction.
Sanjiv Guptac1fa70c2009-04-08 06:24:04 +000092 printMachineInstruction(II);
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000093 }
94 }
95 return false; // we didn't modify anything.
96}
97
Sanjiv Gupta0e687712008-05-13 09:02:57 +000098/// createPIC16CodePrinterPass - Returns a pass that prints the PIC16
99/// assembly code for a MachineFunction to the given output stream,
100/// using the given target machine description. This should work
101/// regardless of whether the function is in SSA form.
102///
Owen Andersoncb371882008-08-21 00:14:44 +0000103FunctionPass *llvm::createPIC16CodePrinterPass(raw_ostream &o,
Bill Wendling57f0db82009-02-24 08:30:20 +0000104 PIC16TargetMachine &tm,
Bill Wendling98a366d2009-04-29 23:29:43 +0000105 CodeGenOpt::Level OptLevel,
Bill Wendlingbe8cc2a2009-04-29 00:15:41 +0000106 bool verbose) {
107 return new PIC16AsmPrinter(o, tm, tm.getTargetAsmInfo(), OptLevel, verbose);
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000108}
109
Sanjiv Gupta0608b492009-05-11 06:01:38 +0000110
111// printOperand - print operand of insn.
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000112void PIC16AsmPrinter::printOperand(const MachineInstr *MI, int opNum) {
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000113 const MachineOperand &MO = MI->getOperand(opNum);
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000114
Sanjiv Gupta2010b3e2008-05-14 11:31:39 +0000115 switch (MO.getType()) {
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000116 case MachineOperand::MO_Register:
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000117 if (TargetRegisterInfo::isPhysicalRegister(MO.getReg()))
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000118 O << TM.getRegisterInfo()->get(MO.getReg()).AsmName;
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000119 else
120 assert(0 && "not implemented");
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000121 return;
Sanjiv Gupta2010b3e2008-05-14 11:31:39 +0000122
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000123 case MachineOperand::MO_Immediate:
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000124 O << (int)MO.getImm();
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000125 return;
Sanjiv Gupta2010b3e2008-05-14 11:31:39 +0000126
Sanjiv Gupta2bdf4902009-04-20 16:59:35 +0000127 case MachineOperand::MO_GlobalAddress: {
Sanjiv Gupta211f3622009-05-10 05:23:47 +0000128 O << Mang->getValueName(MO.getGlobal());
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000129 break;
Sanjiv Gupta2bdf4902009-04-20 16:59:35 +0000130 }
131 case MachineOperand::MO_ExternalSymbol: {
Sanjiv Gupta0608b492009-05-11 06:01:38 +0000132 const char *Sname = MO.getSymbolName();
133
134 // If its a libcall name, record it to decls section.
135 if (PAN::getSymbolTag(Sname) == PAN::LIBCALL) {
Sanjiv Guptaad6585b2009-05-13 15:13:17 +0000136 LibcallDecls.push_back(Sname);
Sanjiv Gupta0608b492009-05-11 06:01:38 +0000137 }
138
139 O << Sname;
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000140 break;
Sanjiv Gupta2bdf4902009-04-20 16:59:35 +0000141 }
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000142 case MachineOperand::MO_MachineBasicBlock:
143 printBasicBlockLabel(MO.getMBB());
144 return;
145
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000146 default:
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000147 assert(0 && " Operand type not supported.");
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000148 }
149}
150
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000151void PIC16AsmPrinter::printCCOperand(const MachineInstr *MI, int opNum) {
152 int CC = (int)MI->getOperand(opNum).getImm();
153 O << PIC16CondCodeToString((PIC16CC::CondCodes)CC);
154}
155
Sanjiv Guptaad6585b2009-05-13 15:13:17 +0000156void PIC16AsmPrinter::printLibcallDecls(void) {
Sanjiv Gupta0608b492009-05-11 06:01:38 +0000157 // If no libcalls used, return.
Sanjiv Guptaad6585b2009-05-13 15:13:17 +0000158 if (LibcallDecls.empty()) return;
Sanjiv Gupta0608b492009-05-11 06:01:38 +0000159
Sanjiv Gupta42918572009-05-12 06:52:41 +0000160 O << TAI->getCommentString() << "External decls for libcalls - BEGIN." <<"\n";
Sanjiv Gupta0608b492009-05-11 06:01:38 +0000161 // Remove duplicate entries.
Sanjiv Guptaad6585b2009-05-13 15:13:17 +0000162 LibcallDecls.sort();
163 LibcallDecls.unique();
164 for (std::list<const char*>::const_iterator I = LibcallDecls.begin();
165 I != LibcallDecls.end(); I++) {
Sanjiv Gupta0608b492009-05-11 06:01:38 +0000166 O << TAI->getExternDirective() << *I << "\n";
Sanjiv Guptae0b4b0e2009-05-11 08:52:04 +0000167 O << TAI->getExternDirective() << PAN::getArgsLabel(*I) << "\n";
168 O << TAI->getExternDirective() << PAN::getRetvalLabel(*I) << "\n";
Sanjiv Gupta0608b492009-05-11 06:01:38 +0000169 }
Sanjiv Gupta42918572009-05-12 06:52:41 +0000170 O << TAI->getCommentString() << "External decls for libcalls - END." <<"\n";
Sanjiv Gupta0608b492009-05-11 06:01:38 +0000171}
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000172
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000173bool PIC16AsmPrinter::doInitialization (Module &M) {
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000174 bool Result = AsmPrinter::doInitialization(M);
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000175 // FIXME:: This is temporary solution to generate the include file.
176 // The processor should be passed to llc as in input and the header file
177 // should be generated accordingly.
178 O << "\t#include P16F1937.INC\n";
Sanjiv Gupta5274a4a2009-04-02 18:03:10 +0000179 MachineModuleInfo *MMI = getAnalysisIfAvailable<MachineModuleInfo>();
180 assert(MMI);
181 DwarfWriter *DW = getAnalysisIfAvailable<DwarfWriter>();
182 assert(DW && "Dwarf Writer is not available");
183 DW->BeginModule(&M, MMI, O, this, TAI);
184
Sanjiv Gupta2364cfe2009-05-12 17:07:27 +0000185 // Set the section names for all globals.
186 for (Module::global_iterator I = M.global_begin(), E = M.global_end();
187 I != E; ++I) {
188 I->setSection(TAI->SectionForGlobal(I)->getName());
189 }
190
Sanjiv Guptaad6585b2009-05-13 15:13:17 +0000191 EmitFunctionDecls(M);
192 EmitUndefinedVars(M);
193 EmitDefinedVars(M);
Sanjiv Gupta2364cfe2009-05-12 17:07:27 +0000194 EmitIData(M);
195 EmitUData(M);
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000196 EmitRomData(M);
Sanjiv Guptaad6585b2009-05-13 15:13:17 +0000197 EmitAutos(M);
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000198 return Result;
199}
200
Sanjiv Guptaad6585b2009-05-13 15:13:17 +0000201// Emit extern decls for functions imported from other modules, and emit
202// global declarations for function defined in this module and which are
203// available to other modules.
204void PIC16AsmPrinter::EmitFunctionDecls (Module &M) {
Sanjiv Gupta8f78fa82008-11-26 10:53:50 +0000205 // Emit declarations for external functions.
Sanjiv Guptaad6585b2009-05-13 15:13:17 +0000206 O << TAI->getCommentString() << "Function Declarations - BEGIN." <<"\n";
Sanjiv Gupta8f78fa82008-11-26 10:53:50 +0000207 for (Module::iterator I = M.begin(), E = M.end(); I != E; I++) {
208 std::string Name = Mang->getValueName(I);
Sanjiv Gupta211f3622009-05-10 05:23:47 +0000209 if (Name.compare("@abort") == 0)
Sanjiv Gupta8f78fa82008-11-26 10:53:50 +0000210 continue;
Sanjiv Gupta85be4082009-04-14 02:49:52 +0000211
212 // If it is llvm intrinsic call then don't emit
213 if (Name.find("llvm.") != std::string::npos)
214 continue;
215
Sanjiv Guptaaf3fdb52009-05-10 16:18:39 +0000216 if (! (I->isDeclaration() || I->hasExternalLinkage()))
217 continue;
Sanjiv Gupta211f3622009-05-10 05:23:47 +0000218
219 const char *directive = I->isDeclaration() ? TAI->getExternDirective() :
220 TAI->getGlobalDirective();
221
222 O << directive << Name << "\n";
223 O << directive << PAN::getRetvalLabel(Name) << "\n";
224 O << directive << PAN::getArgsLabel(Name) << "\n";
Sanjiv Gupta8f78fa82008-11-26 10:53:50 +0000225 }
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000226
Sanjiv Guptaad6585b2009-05-13 15:13:17 +0000227 O << TAI->getCommentString() << "Function Declarations - END." <<"\n";
Sanjiv Gupta8f78fa82008-11-26 10:53:50 +0000228}
Sanjiv Gupta2cc75312009-02-10 04:20:26 +0000229
Sanjiv Guptaad6585b2009-05-13 15:13:17 +0000230// Emit variables imported from other Modules.
231void PIC16AsmPrinter::EmitUndefinedVars (Module &M)
232{
233 std::vector<const GlobalVariable*> Items = PTAI->ExternalVarDecls->Items;
234 if (! Items.size()) return;
235
236 O << "\n" << TAI->getCommentString() << "Imported Variables - BEGIN" << "\n";
237 for (unsigned j = 0; j < Items.size(); j++) {
238 O << TAI->getExternDirective() << Mang->getValueName(Items[j]) << "\n";
239 }
240 O << TAI->getCommentString() << "Imported Variables - END" << "\n";
241}
242
243// Emit variables defined in this module and are available to other modules.
244void PIC16AsmPrinter::EmitDefinedVars (Module &M)
245{
246 std::vector<const GlobalVariable*> Items = PTAI->ExternalVarDefs->Items;
247 if (! Items.size()) return;
248
249 O << "\n" << TAI->getCommentString() << "Exported Variables - BEGIN" << "\n";
250 for (unsigned j = 0; j < Items.size(); j++) {
251 O << TAI->getGlobalDirective() << Mang->getValueName(Items[j]) << "\n";
252 }
253 O << TAI->getCommentString() << "Exported Variables - END" << "\n";
254}
255
256// Emit initialized data placed in ROM.
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000257void PIC16AsmPrinter::EmitRomData (Module &M)
258{
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000259
Sanjiv Gupta2364cfe2009-05-12 17:07:27 +0000260 std::vector<const GlobalVariable*> Items = PTAI->ROSection->Items;
261 if (! Items.size()) return;
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000262
Sanjiv Gupta2364cfe2009-05-12 17:07:27 +0000263 // Print ROData ection.
264 O << "\n";
265 SwitchToSection(PTAI->ROSection->S_);
266 for (unsigned j = 0; j < Items.size(); j++) {
267 O << Mang->getValueName(Items[j]);
268 Constant *C = Items[j]->getInitializer();
269 int AddrSpace = Items[j]->getType()->getAddressSpace();
270 EmitGlobalConstant(C, AddrSpace);
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000271 }
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000272}
273
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000274bool PIC16AsmPrinter::doFinalization(Module &M) {
Sanjiv Guptaad6585b2009-05-13 15:13:17 +0000275 printLibcallDecls();
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000276 O << "\t" << "END\n";
277 bool Result = AsmPrinter::doFinalization(M);
278 return Result;
279}
280
281void PIC16AsmPrinter::emitFunctionData(MachineFunction &MF) {
282 const Function *F = MF.getFunction();
283 std::string FuncName = Mang->getValueName(F);
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000284 const TargetData *TD = TM.getTargetData();
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000285 // Emit the data section name.
286 O << "\n";
Sanjiv Gupta211f3622009-05-10 05:23:47 +0000287 const char *SectionName = PAN::getFrameSectionName(CurrentFnName).c_str();
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000288
Sanjiv Gupta211f3622009-05-10 05:23:47 +0000289 const Section *fPDataSection = TAI->getNamedSection(SectionName,
Sanjiv Gupta2bdf4902009-04-20 16:59:35 +0000290 SectionFlags::Writeable);
291 SwitchToSection(fPDataSection);
Sanjiv Gupta8f78fa82008-11-26 10:53:50 +0000292
Sanjiv Guptab84d5a42009-04-02 17:42:00 +0000293 // Emit function frame label
Sanjiv Gupta211f3622009-05-10 05:23:47 +0000294 O << PAN::getFrameLabel(CurrentFnName) << ":\n";
Sanjiv Guptab84d5a42009-04-02 17:42:00 +0000295
Sanjiv Gupta8f78fa82008-11-26 10:53:50 +0000296 const Type *RetType = F->getReturnType();
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000297 unsigned RetSize = 0;
298 if (RetType->getTypeID() != Type::VoidTyID)
Duncan Sands777d2302009-05-09 07:06:46 +0000299 RetSize = TD->getTypeAllocSize(RetType);
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000300
Sanjiv Guptab84d5a42009-04-02 17:42:00 +0000301 //Emit function return value space
Sanjiv Gupta211f3622009-05-10 05:23:47 +0000302 // FIXME: Do not emit RetvalLable when retsize is zero. To do this
303 // we will need to avoid printing a global directive for Retval label
304 // in emitExternandGloblas.
Sanjiv Guptab84d5a42009-04-02 17:42:00 +0000305 if(RetSize > 0)
Sanjiv Gupta211f3622009-05-10 05:23:47 +0000306 O << PAN::getRetvalLabel(CurrentFnName) << " RES " << RetSize << "\n";
Sanjiv Guptab84d5a42009-04-02 17:42:00 +0000307 else
Sanjiv Gupta211f3622009-05-10 05:23:47 +0000308 O << PAN::getRetvalLabel(CurrentFnName) << ": \n";
Sanjiv Guptab84d5a42009-04-02 17:42:00 +0000309
310 // Emit variable to hold the space for function arguments
311 unsigned ArgSize = 0;
312 for (Function::const_arg_iterator argi = F->arg_begin(),
313 arge = F->arg_end(); argi != arge ; ++argi) {
314 const Type *Ty = argi->getType();
Duncan Sands777d2302009-05-09 07:06:46 +0000315 ArgSize += TD->getTypeAllocSize(Ty);
Sanjiv Guptab84d5a42009-04-02 17:42:00 +0000316 }
Sanjiv Gupta211f3622009-05-10 05:23:47 +0000317
318 O << PAN::getArgsLabel(CurrentFnName) << " RES " << ArgSize << "\n";
Sanjiv Guptab84d5a42009-04-02 17:42:00 +0000319
Sanjiv Gupta85be4082009-04-14 02:49:52 +0000320 // Emit temporary space
321 int TempSize = PTLI->GetTmpSize();
322 if (TempSize > 0 )
Sanjiv Gupta211f3622009-05-10 05:23:47 +0000323 O << PAN::getTempdataLabel(CurrentFnName) << " RES " << TempSize <<"\n";
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000324}
Sanjiv Guptad8d27f42009-05-06 08:02:01 +0000325
Sanjiv Gupta2364cfe2009-05-12 17:07:27 +0000326void PIC16AsmPrinter::EmitIData (Module &M) {
Sanjiv Guptad8d27f42009-05-06 08:02:01 +0000327
Sanjiv Gupta2364cfe2009-05-12 17:07:27 +0000328 // Print all IDATA sections.
Sanjiv Gupta211f3622009-05-10 05:23:47 +0000329 std::vector <PIC16Section *>IDATASections = PTAI->IDATASections;
Sanjiv Guptad8d27f42009-05-06 08:02:01 +0000330 for (unsigned i = 0; i < IDATASections.size(); i++) {
Sanjiv Gupta2364cfe2009-05-12 17:07:27 +0000331 O << "\n";
Sanjiv Guptad8d27f42009-05-06 08:02:01 +0000332 SwitchToSection(IDATASections[i]->S_);
333 std::vector<const GlobalVariable*> Items = IDATASections[i]->Items;
334 for (unsigned j = 0; j < Items.size(); j++) {
335 std::string Name = Mang->getValueName(Items[j]);
336 Constant *C = Items[j]->getInitializer();
337 int AddrSpace = Items[j]->getType()->getAddressSpace();
338 O << Name;
339 EmitGlobalConstant(C, AddrSpace);
340 }
341 }
Sanjiv Gupta2364cfe2009-05-12 17:07:27 +0000342}
Sanjiv Guptad8d27f42009-05-06 08:02:01 +0000343
Sanjiv Gupta2364cfe2009-05-12 17:07:27 +0000344void PIC16AsmPrinter::EmitUData (Module &M) {
Sanjiv Gupta2364cfe2009-05-12 17:07:27 +0000345 const TargetData *TD = TM.getTargetData();
346
347 // Print all BSS sections.
Sanjiv Gupta211f3622009-05-10 05:23:47 +0000348 std::vector <PIC16Section *>BSSSections = PTAI->BSSSections;
Sanjiv Guptad8d27f42009-05-06 08:02:01 +0000349 for (unsigned i = 0; i < BSSSections.size(); i++) {
Sanjiv Gupta2364cfe2009-05-12 17:07:27 +0000350 O << "\n";
Sanjiv Guptad8d27f42009-05-06 08:02:01 +0000351 SwitchToSection(BSSSections[i]->S_);
352 std::vector<const GlobalVariable*> Items = BSSSections[i]->Items;
353 for (unsigned j = 0; j < Items.size(); j++) {
354 std::string Name = Mang->getValueName(Items[j]);
355 Constant *C = Items[j]->getInitializer();
356 const Type *Ty = C->getType();
Duncan Sands777d2302009-05-09 07:06:46 +0000357 unsigned Size = TD->getTypeAllocSize(Ty);
Sanjiv Guptad8d27f42009-05-06 08:02:01 +0000358
359 O << Name << " " <<"RES"<< " " << Size ;
360 O << "\n";
361 }
362 }
363}
364
Sanjiv Gupta2364cfe2009-05-12 17:07:27 +0000365void PIC16AsmPrinter::EmitAutos (Module &M)
366{
367 // Section names for all globals are already set.
368
Sanjiv Gupta2364cfe2009-05-12 17:07:27 +0000369 const TargetData *TD = TM.getTargetData();
370
371 // Now print all Autos sections.
372 std::vector <PIC16Section *>AutosSections = PTAI->AutosSections;
373 for (unsigned i = 0; i < AutosSections.size(); i++) {
374 O << "\n";
375 SwitchToSection(AutosSections[i]->S_);
376 std::vector<const GlobalVariable*> Items = AutosSections[i]->Items;
377 for (unsigned j = 0; j < Items.size(); j++) {
378 std::string VarName = Mang->getValueName(Items[j]);
379 Constant *C = Items[j]->getInitializer();
380 const Type *Ty = C->getType();
381 unsigned Size = TD->getTypeAllocSize(Ty);
382 // Emit memory reserve directive.
383 O << VarName << " RES " << Size << "\n";
384 }
385 }
386}