blob: 3f415afc10902b67f93d624da5ca7dfb2f8e893e [file] [log] [blame]
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +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
15#include "PIC16AsmPrinter.h"
Daniel Dunbar0522c9e2009-10-15 15:02:14 +000016#include "MCSectionPIC16.h"
Chris Lattner621c44d2009-08-22 20:48:53 +000017#include "PIC16MCAsmInfo.h"
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +000018#include "llvm/DerivedTypes.h"
19#include "llvm/Function.h"
20#include "llvm/Module.h"
21#include "llvm/CodeGen/DwarfWriter.h"
22#include "llvm/CodeGen/MachineFrameInfo.h"
23#include "llvm/CodeGen/DwarfWriter.h"
24#include "llvm/CodeGen/MachineModuleInfo.h"
Chris Lattner73266f92009-08-19 05:49:37 +000025#include "llvm/MC/MCStreamer.h"
Chris Lattnerc6f802d2009-09-13 17:14:04 +000026#include "llvm/MC/MCSymbol.h"
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +000027#include "llvm/Target/TargetRegistry.h"
28#include "llvm/Target/TargetLoweringObjectFile.h"
29#include "llvm/Support/ErrorHandling.h"
30#include "llvm/Support/FormattedStream.h"
31#include "llvm/Support/Mangler.h"
32#include <cstring>
33using namespace llvm;
34
35#include "PIC16GenAsmWriter.inc"
36
37PIC16AsmPrinter::PIC16AsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
Chris Lattner621c44d2009-08-22 20:48:53 +000038 const MCAsmInfo *T, bool V)
Chris Lattner181c7cb2009-08-22 20:56:12 +000039: AsmPrinter(O, TM, T, V), DbgInfo(O, T) {
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +000040 PTLI = static_cast<PIC16TargetLowering*>(TM.getTargetLowering());
Chris Lattnera5ef4d32009-08-22 21:43:10 +000041 PMAI = static_cast<const PIC16MCAsmInfo*>(T);
Daniel Dunbar0522c9e2009-10-15 15:02:14 +000042 PTOF = (PIC16TargetObjectFile*)&PTLI->getObjFileLowering();
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +000043}
44
45bool PIC16AsmPrinter::printMachineInstruction(const MachineInstr *MI) {
Devang Patel5450fc12009-10-06 02:19:11 +000046 processDebugLoc(MI, true);
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +000047 printInstruction(MI);
Chris Lattner32d4cc72009-09-09 23:14:36 +000048 if (VerboseAsm && !MI->getDebugLoc().isUnknown())
49 EmitComments(*MI);
50 O << '\n';
Devang Patel5450fc12009-10-06 02:19:11 +000051 processDebugLoc(MI, false);
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +000052 return true;
53}
54
55/// runOnMachineFunction - This emits the frame section, autos section and
56/// assembly for each instruction. Also takes care of function begin debug
57/// directive and file begin debug directive (if required) for the function.
58///
59bool PIC16AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
60 this->MF = &MF;
61
62 // This calls the base class function required to be called at beginning
63 // of runOnMachineFunction.
64 SetupMachineFunction(MF);
65
66 // Get the mangled name.
67 const Function *F = MF.getFunction();
68 CurrentFnName = Mang->getMangledName(F);
69
70 // Emit the function frame (args and temps).
71 EmitFunctionFrame(MF);
72
73 DbgInfo.BeginFunction(MF);
74
75 // Emit the autos section of function.
Daniel Dunbar0522c9e2009-10-15 15:02:14 +000076 EmitAutos(CurrentFnName);
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +000077
78 // Now emit the instructions of function in its code section.
Daniel Dunbar0522c9e2009-10-15 15:02:14 +000079 const MCSection *fCodeSection =
80 getObjFileLowering().getSectionForFunction(CurrentFnName);
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +000081 // Start the Code Section.
82 O << "\n";
Chris Lattner73266f92009-08-19 05:49:37 +000083 OutStreamer.SwitchSection(fCodeSection);
Chris Lattner7f504882009-08-21 23:12:15 +000084
85 // Emit the frame address of the function at the beginning of code.
86 O << "\tretlw low(" << PAN::getFrameLabel(CurrentFnName) << ")\n";
87 O << "\tretlw high(" << PAN::getFrameLabel(CurrentFnName) << ")\n";
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +000088
89 // Emit function start label.
90 O << CurrentFnName << ":\n";
Chris Lattner7f504882009-08-21 23:12:15 +000091
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +000092 DebugLoc CurDL;
93 O << "\n";
94 // Print out code for the function.
95 for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
96 I != E; ++I) {
97
98 // Print a label for the basic block.
99 if (I != MF.begin()) {
Chris Lattnerda5fb6d2009-09-14 03:15:54 +0000100 EmitBasicBlockStart(I);
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000101 }
102
103 // Print a basic block.
104 for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
105 II != E; ++II) {
106
107 // Emit the line directive if source line changed.
108 const DebugLoc DL = II->getDebugLoc();
109 if (!DL.isUnknown() && DL != CurDL) {
110 DbgInfo.ChangeDebugLoc(MF, DL);
111 CurDL = DL;
112 }
113
114 // Print the assembly for the instruction.
115 printMachineInstruction(II);
116 }
117 }
118
119 // Emit function end debug directives.
120 DbgInfo.EndFunction(MF);
121
122 return false; // we didn't modify anything.
123}
124
125
126// printOperand - print operand of insn.
127void PIC16AsmPrinter::printOperand(const MachineInstr *MI, int opNum) {
128 const MachineOperand &MO = MI->getOperand(opNum);
129
130 switch (MO.getType()) {
131 case MachineOperand::MO_Register:
Chris Lattnerf0a25de2009-09-13 20:31:40 +0000132 O << getRegisterName(MO.getReg());
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000133 return;
134
135 case MachineOperand::MO_Immediate:
136 O << (int)MO.getImm();
137 return;
138
139 case MachineOperand::MO_GlobalAddress: {
140 std::string Sname = Mang->getMangledName(MO.getGlobal());
141 // FIXME: currently we do not have a memcpy def coming in the module
142 // by any chance, as we do not link in those as .bc lib. So these calls
143 // are always external and it is safe to emit an extern.
144 if (PAN::isMemIntrinsic(Sname)) {
145 LibcallDecls.push_back(createESName(Sname));
146 }
Chris Lattner7f504882009-08-21 23:12:15 +0000147
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000148 O << Sname;
149 break;
150 }
151 case MachineOperand::MO_ExternalSymbol: {
152 const char *Sname = MO.getSymbolName();
153
154 // If its a libcall name, record it to decls section.
155 if (PAN::getSymbolTag(Sname) == PAN::LIBCALL) {
Chris Lattner7f504882009-08-21 23:12:15 +0000156 LibcallDecls.push_back(Sname);
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000157 }
158
159 // Record a call to intrinsic to print the extern declaration for it.
160 std::string Sym = Sname;
161 if (PAN::isMemIntrinsic(Sym)) {
162 Sym = PAN::addPrefix(Sym);
163 LibcallDecls.push_back(createESName(Sym));
164 }
Chris Lattner7f504882009-08-21 23:12:15 +0000165
166 O << Sym;
167 break;
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000168 }
169 case MachineOperand::MO_MachineBasicBlock:
Chris Lattnerc6f802d2009-09-13 17:14:04 +0000170 GetMBBSymbol(MO.getMBB()->getNumber())->print(O, MAI);
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000171 return;
172
173 default:
174 llvm_unreachable(" Operand type not supported.");
175 }
176}
177
178/// printCCOperand - Print the cond code operand.
179///
180void PIC16AsmPrinter::printCCOperand(const MachineInstr *MI, int opNum) {
181 int CC = (int)MI->getOperand(opNum).getImm();
182 O << PIC16CondCodeToString((PIC16CC::CondCodes)CC);
183}
184
185// This function is used to sort the decls list.
186// should return true if s1 should come before s2.
187static bool is_before(const char *s1, const char *s2) {
188 return strcmp(s1, s2) <= 0;
189}
190
191// This is used by list::unique below.
192// unique will filter out duplicates if it knows them.
193static bool is_duplicate(const char *s1, const char *s2) {
194 return !strcmp(s1, s2);
195}
196
197/// printLibcallDecls - print the extern declarations for compiler
198/// intrinsics.
199///
200void PIC16AsmPrinter::printLibcallDecls() {
201 // If no libcalls used, return.
202 if (LibcallDecls.empty()) return;
203
Chris Lattnera5ef4d32009-08-22 21:43:10 +0000204 O << MAI->getCommentString() << "External decls for libcalls - BEGIN." <<"\n";
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000205 // Remove duplicate entries.
206 LibcallDecls.sort(is_before);
207 LibcallDecls.unique(is_duplicate);
208
209 for (std::list<const char*>::const_iterator I = LibcallDecls.begin();
210 I != LibcallDecls.end(); I++) {
Chris Lattnera5ef4d32009-08-22 21:43:10 +0000211 O << MAI->getExternDirective() << *I << "\n";
212 O << MAI->getExternDirective() << PAN::getArgsLabel(*I) << "\n";
213 O << MAI->getExternDirective() << PAN::getRetvalLabel(*I) << "\n";
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000214 }
Chris Lattnera5ef4d32009-08-22 21:43:10 +0000215 O << MAI->getCommentString() << "External decls for libcalls - END." <<"\n";
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000216}
217
Bob Wilson4901f432009-09-30 21:44:42 +0000218/// doInitialization - Perform Module level initializations here.
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000219/// One task that we do here is to sectionize all global variables.
220/// The MemSelOptimizer pass depends on the sectionizing.
221///
222bool PIC16AsmPrinter::doInitialization(Module &M) {
223 bool Result = AsmPrinter::doInitialization(M);
224
225 // FIXME:: This is temporary solution to generate the include file.
226 // The processor should be passed to llc as in input and the header file
227 // should be generated accordingly.
228 O << "\n\t#include P16F1937.INC\n";
229
230 // Set the section names for all globals.
231 for (Module::global_iterator I = M.global_begin(), E = M.global_end();
Daniel Dunbar0522c9e2009-10-15 15:02:14 +0000232 I != E; ++I)
233 if (!I->isDeclaration() && !I->hasAvailableExternallyLinkage()) {
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000234 const MCSection *S = getObjFileLowering().SectionForGlobal(I, Mang, TM);
235
Daniel Dunbar0522c9e2009-10-15 15:02:14 +0000236 I->setSection(((const MCSectionPIC16*)S)->getName());
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000237 }
238
239 DbgInfo.BeginModule(M);
240 EmitFunctionDecls(M);
241 EmitUndefinedVars(M);
242 EmitDefinedVars(M);
243 EmitIData(M);
244 EmitUData(M);
245 EmitRomData(M);
246 return Result;
247}
248
249/// Emit extern decls for functions imported from other modules, and emit
250/// global declarations for function defined in this module and which are
251/// available to other modules.
252///
253void PIC16AsmPrinter::EmitFunctionDecls(Module &M) {
254 // Emit declarations for external functions.
Chris Lattnera5ef4d32009-08-22 21:43:10 +0000255 O <<"\n"<<MAI->getCommentString() << "Function Declarations - BEGIN." <<"\n";
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000256 for (Module::iterator I = M.begin(), E = M.end(); I != E; I++) {
257 if (I->isIntrinsic())
258 continue;
259
260 std::string Name = Mang->getMangledName(I);
261 if (Name.compare("@abort") == 0)
262 continue;
263
264 if (!I->isDeclaration() && !I->hasExternalLinkage())
265 continue;
266
267 // Do not emit memcpy, memset, and memmove here.
268 // Calls to these routines can be generated in two ways,
269 // 1. User calling the standard lib function
270 // 2. Codegen generating these calls for llvm intrinsics.
271 // In the first case a prototype is alread availale, while in
272 // second case the call is via and externalsym and the prototype is missing.
273 // So declarations for these are currently always getting printing by
274 // tracking both kind of references in printInstrunction.
275 if (I->isDeclaration() && PAN::isMemIntrinsic(Name)) continue;
276
Chris Lattnera5ef4d32009-08-22 21:43:10 +0000277 const char *directive = I->isDeclaration() ? MAI->getExternDirective() :
278 MAI->getGlobalDirective();
Chris Lattner7f504882009-08-21 23:12:15 +0000279
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000280 O << directive << Name << "\n";
281 O << directive << PAN::getRetvalLabel(Name) << "\n";
282 O << directive << PAN::getArgsLabel(Name) << "\n";
283 }
284
Chris Lattnera5ef4d32009-08-22 21:43:10 +0000285 O << MAI->getCommentString() << "Function Declarations - END." <<"\n";
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000286}
287
288// Emit variables imported from other Modules.
289void PIC16AsmPrinter::EmitUndefinedVars(Module &M) {
Daniel Dunbar0522c9e2009-10-15 15:02:14 +0000290 std::vector<const GlobalVariable*> Items = PTOF->ExternalVarDecls->Items;
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000291 if (!Items.size()) return;
292
Chris Lattnera5ef4d32009-08-22 21:43:10 +0000293 O << "\n" << MAI->getCommentString() << "Imported Variables - BEGIN" << "\n";
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000294 for (unsigned j = 0; j < Items.size(); j++) {
Chris Lattnera5ef4d32009-08-22 21:43:10 +0000295 O << MAI->getExternDirective() << Mang->getMangledName(Items[j]) << "\n";
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000296 }
Chris Lattnera5ef4d32009-08-22 21:43:10 +0000297 O << MAI->getCommentString() << "Imported Variables - END" << "\n";
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000298}
299
300// Emit variables defined in this module and are available to other modules.
301void PIC16AsmPrinter::EmitDefinedVars(Module &M) {
Daniel Dunbar0522c9e2009-10-15 15:02:14 +0000302 std::vector<const GlobalVariable*> Items = PTOF->ExternalVarDefs->Items;
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000303 if (!Items.size()) return;
304
Chris Lattnera5ef4d32009-08-22 21:43:10 +0000305 O << "\n" << MAI->getCommentString() << "Exported Variables - BEGIN" << "\n";
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000306 for (unsigned j = 0; j < Items.size(); j++) {
Chris Lattnera5ef4d32009-08-22 21:43:10 +0000307 O << MAI->getGlobalDirective() << Mang->getMangledName(Items[j]) << "\n";
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000308 }
Chris Lattnera5ef4d32009-08-22 21:43:10 +0000309 O << MAI->getCommentString() << "Exported Variables - END" << "\n";
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000310}
311
312// Emit initialized data placed in ROM.
313void PIC16AsmPrinter::EmitRomData(Module &M) {
314 // Print ROM Data section.
Daniel Dunbar0522c9e2009-10-15 15:02:14 +0000315 const std::vector<PIC16Section*> &ROSections = PTOF->ROSections;
316 for (unsigned i = 0; i < ROSections.size(); i++) {
317 const std::vector<const GlobalVariable*> &Items = ROSections[i]->Items;
318 if (!Items.size()) continue;
319 O << "\n";
320 OutStreamer.SwitchSection(PTOF->ROSections[i]->S_);
321 for (unsigned j = 0; j < Items.size(); j++) {
322 O << Mang->getMangledName(Items[j]);
323 Constant *C = Items[j]->getInitializer();
324 int AddrSpace = Items[j]->getType()->getAddressSpace();
325 EmitGlobalConstant(C, AddrSpace);
326 }
327 }
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000328}
329
330bool PIC16AsmPrinter::doFinalization(Module &M) {
331 printLibcallDecls();
Daniel Dunbar0522c9e2009-10-15 15:02:14 +0000332 EmitRemainingAutos();
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000333 DbgInfo.EndModule(M);
334 O << "\n\t" << "END\n";
335 return AsmPrinter::doFinalization(M);
336}
337
338void PIC16AsmPrinter::EmitFunctionFrame(MachineFunction &MF) {
339 const Function *F = MF.getFunction();
340 std::string FuncName = Mang->getMangledName(F);
341 const TargetData *TD = TM.getTargetData();
342 // Emit the data section name.
343 O << "\n";
Chris Lattner08e63732009-08-21 23:08:09 +0000344
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000345 const MCSection *fPDataSection =
Daniel Dunbar0522c9e2009-10-15 15:02:14 +0000346 getObjFileLowering().getSectionForFunctionFrame(CurrentFnName);
Chris Lattner73266f92009-08-19 05:49:37 +0000347 OutStreamer.SwitchSection(fPDataSection);
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000348
349 // Emit function frame label
350 O << PAN::getFrameLabel(CurrentFnName) << ":\n";
351
352 const Type *RetType = F->getReturnType();
353 unsigned RetSize = 0;
354 if (RetType->getTypeID() != Type::VoidTyID)
355 RetSize = TD->getTypeAllocSize(RetType);
356
357 //Emit function return value space
358 // FIXME: Do not emit RetvalLable when retsize is zero. To do this
359 // we will need to avoid printing a global directive for Retval label
360 // in emitExternandGloblas.
361 if(RetSize > 0)
362 O << PAN::getRetvalLabel(CurrentFnName) << " RES " << RetSize << "\n";
363 else
364 O << PAN::getRetvalLabel(CurrentFnName) << ": \n";
365
366 // Emit variable to hold the space for function arguments
367 unsigned ArgSize = 0;
368 for (Function::const_arg_iterator argi = F->arg_begin(),
369 arge = F->arg_end(); argi != arge ; ++argi) {
370 const Type *Ty = argi->getType();
371 ArgSize += TD->getTypeAllocSize(Ty);
372 }
373
374 O << PAN::getArgsLabel(CurrentFnName) << " RES " << ArgSize << "\n";
375
376 // Emit temporary space
377 int TempSize = PTLI->GetTmpSize();
378 if (TempSize > 0)
379 O << PAN::getTempdataLabel(CurrentFnName) << " RES " << TempSize << '\n';
380}
381
Daniel Dunbar0522c9e2009-10-15 15:02:14 +0000382void PIC16AsmPrinter::EmitIData(Module &M) {
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000383
Daniel Dunbar0522c9e2009-10-15 15:02:14 +0000384 // Print all IDATA sections.
385 const std::vector<PIC16Section*> &IDATASections = PTOF->IDATASections;
386 for (unsigned i = 0; i < IDATASections.size(); i++) {
387 O << "\n";
388 if (IDATASections[i]->S_->getName().find("llvm.") != std::string::npos)
389 continue;
390 OutStreamer.SwitchSection(IDATASections[i]->S_);
391 std::vector<const GlobalVariable*> Items = IDATASections[i]->Items;
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000392 for (unsigned j = 0; j < Items.size(); j++) {
393 std::string Name = Mang->getMangledName(Items[j]);
394 Constant *C = Items[j]->getInitializer();
395 int AddrSpace = Items[j]->getType()->getAddressSpace();
396 O << Name;
397 EmitGlobalConstant(C, AddrSpace);
Sanjiv Gupta1c138172009-10-15 10:10:43 +0000398 }
Daniel Dunbar0522c9e2009-10-15 15:02:14 +0000399 }
Sanjiv Gupta1c138172009-10-15 10:10:43 +0000400}
401
Daniel Dunbar0522c9e2009-10-15 15:02:14 +0000402void PIC16AsmPrinter::EmitUData(Module &M) {
403 const TargetData *TD = TM.getTargetData();
404
405 // Print all BSS sections.
406 const std::vector<PIC16Section*> &BSSSections = PTOF->BSSSections;
407 for (unsigned i = 0; i < BSSSections.size(); i++) {
408 O << "\n";
409 OutStreamer.SwitchSection(BSSSections[i]->S_);
410 std::vector<const GlobalVariable*> Items = BSSSections[i]->Items;
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000411 for (unsigned j = 0; j < Items.size(); j++) {
412 std::string Name = Mang->getMangledName(Items[j]);
413 Constant *C = Items[j]->getInitializer();
414 const Type *Ty = C->getType();
415 unsigned Size = TD->getTypeAllocSize(Ty);
Daniel Dunbar0522c9e2009-10-15 15:02:14 +0000416
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000417 O << Name << " RES " << Size << "\n";
418 }
419 }
420}
421
Daniel Dunbar0522c9e2009-10-15 15:02:14 +0000422void PIC16AsmPrinter::EmitAutos(std::string FunctName) {
423 // Section names for all globals are already set.
424 const TargetData *TD = TM.getTargetData();
425
426 // Now print Autos section for this function.
427 std::string SectionName = PAN::getAutosSectionName(FunctName);
428 const std::vector<PIC16Section*> &AutosSections = PTOF->AutosSections;
429 for (unsigned i = 0; i < AutosSections.size(); i++) {
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000430 O << "\n";
Daniel Dunbar0522c9e2009-10-15 15:02:14 +0000431 if (AutosSections[i]->S_->getName() == SectionName) {
432 // Set the printing status to true
433 AutosSections[i]->setPrintedStatus(true);
434 OutStreamer.SwitchSection(AutosSections[i]->S_);
435 const std::vector<const GlobalVariable*> &Items = AutosSections[i]->Items;
436 for (unsigned j = 0; j < Items.size(); j++) {
437 std::string VarName = Mang->getMangledName(Items[j]);
438 Constant *C = Items[j]->getInitializer();
439 const Type *Ty = C->getType();
440 unsigned Size = TD->getTypeAllocSize(Ty);
441 // Emit memory reserve directive.
442 O << VarName << " RES " << Size << "\n";
443 }
444 break;
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000445 }
446 }
447}
448
Daniel Dunbar0522c9e2009-10-15 15:02:14 +0000449// Print autos that were not printed during the code printing of functions.
450// As the functions might themselves would have got deleted by the optimizer.
451void PIC16AsmPrinter::EmitRemainingAutos() {
452 const TargetData *TD = TM.getTargetData();
453
454 // Now print Autos section for this function.
455 std::vector <PIC16Section *>AutosSections = PTOF->AutosSections;
456 for (unsigned i = 0; i < AutosSections.size(); i++) {
457
458 // if the section is already printed then don't print again
459 if (AutosSections[i]->isPrinted())
460 continue;
461
462 // Set status as printed
463 AutosSections[i]->setPrintedStatus(true);
464
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000465 O << "\n";
Daniel Dunbar0522c9e2009-10-15 15:02:14 +0000466 OutStreamer.SwitchSection(AutosSections[i]->S_);
467 const std::vector<const GlobalVariable*> &Items = AutosSections[i]->Items;
468 for (unsigned j = 0; j < Items.size(); j++) {
469 std::string VarName = Mang->getMangledName(Items[j]);
470 Constant *C = Items[j]->getInitializer();
471 const Type *Ty = C->getType();
472 unsigned Size = TD->getTypeAllocSize(Ty);
473 // Emit memory reserve directive.
474 O << VarName << " RES " << Size << "\n";
475 }
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000476 }
477}
478
Daniel Dunbar0522c9e2009-10-15 15:02:14 +0000479
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000480extern "C" void LLVMInitializePIC16AsmPrinter() {
481 RegisterAsmPrinter<PIC16AsmPrinter> X(ThePIC16Target);
482}
483
484