blob: 3f719b99ff70c4c621981f72155717ed58aeaa7a [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
Sanjiv Guptaac2620e2009-10-15 19:26:25 +000015#include "PIC16ABINames.h"
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +000016#include "PIC16AsmPrinter.h"
Sanjiv Guptaac2620e2009-10-15 19:26:25 +000017#include "PIC16Section.h"
Chris Lattner621c44d2009-08-22 20:48:53 +000018#include "PIC16MCAsmInfo.h"
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +000019#include "llvm/DerivedTypes.h"
20#include "llvm/Function.h"
21#include "llvm/Module.h"
22#include "llvm/CodeGen/DwarfWriter.h"
23#include "llvm/CodeGen/MachineFrameInfo.h"
24#include "llvm/CodeGen/DwarfWriter.h"
25#include "llvm/CodeGen/MachineModuleInfo.h"
Chris Lattner73266f92009-08-19 05:49:37 +000026#include "llvm/MC/MCStreamer.h"
Chris Lattnerc6f802d2009-09-13 17:14:04 +000027#include "llvm/MC/MCSymbol.h"
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +000028#include "llvm/Target/TargetRegistry.h"
29#include "llvm/Target/TargetLoweringObjectFile.h"
30#include "llvm/Support/ErrorHandling.h"
31#include "llvm/Support/FormattedStream.h"
32#include "llvm/Support/Mangler.h"
33#include <cstring>
34using namespace llvm;
35
36#include "PIC16GenAsmWriter.inc"
37
38PIC16AsmPrinter::PIC16AsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
Chris Lattner621c44d2009-08-22 20:48:53 +000039 const MCAsmInfo *T, bool V)
Chris Lattner181c7cb2009-08-22 20:56:12 +000040: AsmPrinter(O, TM, T, V), DbgInfo(O, T) {
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +000041 PTLI = static_cast<PIC16TargetLowering*>(TM.getTargetLowering());
Chris Lattnera5ef4d32009-08-22 21:43:10 +000042 PMAI = static_cast<const PIC16MCAsmInfo*>(T);
Sanjiv Guptaac2620e2009-10-15 19:26:25 +000043 PTOF = (PIC16TargetObjectFile *)&PTLI->getObjFileLowering();
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +000044}
45
46bool PIC16AsmPrinter::printMachineInstruction(const MachineInstr *MI) {
Devang Patel5450fc12009-10-06 02:19:11 +000047 processDebugLoc(MI, true);
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +000048 printInstruction(MI);
Chris Lattner32d4cc72009-09-09 23:14:36 +000049 if (VerboseAsm && !MI->getDebugLoc().isUnknown())
50 EmitComments(*MI);
51 O << '\n';
Devang Patel5450fc12009-10-06 02:19:11 +000052 processDebugLoc(MI, false);
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +000053 return true;
54}
55
56/// runOnMachineFunction - This emits the frame section, autos section and
57/// assembly for each instruction. Also takes care of function begin debug
58/// directive and file begin debug directive (if required) for the function.
59///
60bool PIC16AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
61 this->MF = &MF;
62
63 // This calls the base class function required to be called at beginning
64 // of runOnMachineFunction.
65 SetupMachineFunction(MF);
66
67 // Get the mangled name.
68 const Function *F = MF.getFunction();
69 CurrentFnName = Mang->getMangledName(F);
70
71 // Emit the function frame (args and temps).
72 EmitFunctionFrame(MF);
73
74 DbgInfo.BeginFunction(MF);
75
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +000076 // Now emit the instructions of function in its code section.
Sanjiv Guptaac2620e2009-10-15 19:26:25 +000077 const MCSection *fCodeSection
78 = getObjFileLowering().SectionForCode(CurrentFnName);
79
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +000080 // Start the Code Section.
81 O << "\n";
Chris Lattner73266f92009-08-19 05:49:37 +000082 OutStreamer.SwitchSection(fCodeSection);
Chris Lattner7f504882009-08-21 23:12:15 +000083
84 // Emit the frame address of the function at the beginning of code.
85 O << "\tretlw low(" << PAN::getFrameLabel(CurrentFnName) << ")\n";
86 O << "\tretlw high(" << PAN::getFrameLabel(CurrentFnName) << ")\n";
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +000087
88 // Emit function start label.
89 O << CurrentFnName << ":\n";
Chris Lattner7f504882009-08-21 23:12:15 +000090
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +000091 DebugLoc CurDL;
92 O << "\n";
93 // Print out code for the function.
94 for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
95 I != E; ++I) {
96
97 // Print a label for the basic block.
98 if (I != MF.begin()) {
Chris Lattnerda5fb6d2009-09-14 03:15:54 +000099 EmitBasicBlockStart(I);
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000100 }
101
102 // Print a basic block.
103 for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
104 II != E; ++II) {
105
106 // Emit the line directive if source line changed.
107 const DebugLoc DL = II->getDebugLoc();
108 if (!DL.isUnknown() && DL != CurDL) {
109 DbgInfo.ChangeDebugLoc(MF, DL);
110 CurDL = DL;
111 }
112
113 // Print the assembly for the instruction.
114 printMachineInstruction(II);
115 }
116 }
117
118 // Emit function end debug directives.
119 DbgInfo.EndFunction(MF);
120
121 return false; // we didn't modify anything.
122}
123
124
125// printOperand - print operand of insn.
126void PIC16AsmPrinter::printOperand(const MachineInstr *MI, int opNum) {
127 const MachineOperand &MO = MI->getOperand(opNum);
128
129 switch (MO.getType()) {
130 case MachineOperand::MO_Register:
Chris Lattnerf0a25de2009-09-13 20:31:40 +0000131 O << getRegisterName(MO.getReg());
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000132 return;
133
134 case MachineOperand::MO_Immediate:
135 O << (int)MO.getImm();
136 return;
137
138 case MachineOperand::MO_GlobalAddress: {
139 std::string Sname = Mang->getMangledName(MO.getGlobal());
140 // FIXME: currently we do not have a memcpy def coming in the module
141 // by any chance, as we do not link in those as .bc lib. So these calls
142 // are always external and it is safe to emit an extern.
143 if (PAN::isMemIntrinsic(Sname)) {
144 LibcallDecls.push_back(createESName(Sname));
145 }
Chris Lattner7f504882009-08-21 23:12:15 +0000146
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000147 O << Sname;
148 break;
149 }
150 case MachineOperand::MO_ExternalSymbol: {
151 const char *Sname = MO.getSymbolName();
152
153 // If its a libcall name, record it to decls section.
154 if (PAN::getSymbolTag(Sname) == PAN::LIBCALL) {
Chris Lattner7f504882009-08-21 23:12:15 +0000155 LibcallDecls.push_back(Sname);
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000156 }
157
158 // Record a call to intrinsic to print the extern declaration for it.
159 std::string Sym = Sname;
160 if (PAN::isMemIntrinsic(Sym)) {
161 Sym = PAN::addPrefix(Sym);
162 LibcallDecls.push_back(createESName(Sym));
163 }
Chris Lattner7f504882009-08-21 23:12:15 +0000164
165 O << Sym;
166 break;
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000167 }
168 case MachineOperand::MO_MachineBasicBlock:
Chris Lattnerc6f802d2009-09-13 17:14:04 +0000169 GetMBBSymbol(MO.getMBB()->getNumber())->print(O, MAI);
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000170 return;
171
172 default:
173 llvm_unreachable(" Operand type not supported.");
174 }
175}
176
177/// printCCOperand - Print the cond code operand.
178///
179void PIC16AsmPrinter::printCCOperand(const MachineInstr *MI, int opNum) {
180 int CC = (int)MI->getOperand(opNum).getImm();
181 O << PIC16CondCodeToString((PIC16CC::CondCodes)CC);
182}
183
184// This function is used to sort the decls list.
185// should return true if s1 should come before s2.
186static bool is_before(const char *s1, const char *s2) {
187 return strcmp(s1, s2) <= 0;
188}
189
190// This is used by list::unique below.
191// unique will filter out duplicates if it knows them.
192static bool is_duplicate(const char *s1, const char *s2) {
193 return !strcmp(s1, s2);
194}
195
196/// printLibcallDecls - print the extern declarations for compiler
197/// intrinsics.
198///
199void PIC16AsmPrinter::printLibcallDecls() {
200 // If no libcalls used, return.
201 if (LibcallDecls.empty()) return;
202
Chris Lattnera5ef4d32009-08-22 21:43:10 +0000203 O << MAI->getCommentString() << "External decls for libcalls - BEGIN." <<"\n";
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000204 // Remove duplicate entries.
205 LibcallDecls.sort(is_before);
206 LibcallDecls.unique(is_duplicate);
207
208 for (std::list<const char*>::const_iterator I = LibcallDecls.begin();
209 I != LibcallDecls.end(); I++) {
Chris Lattnera5ef4d32009-08-22 21:43:10 +0000210 O << MAI->getExternDirective() << *I << "\n";
211 O << MAI->getExternDirective() << PAN::getArgsLabel(*I) << "\n";
212 O << MAI->getExternDirective() << PAN::getRetvalLabel(*I) << "\n";
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000213 }
Chris Lattnera5ef4d32009-08-22 21:43:10 +0000214 O << MAI->getCommentString() << "External decls for libcalls - END." <<"\n";
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000215}
216
Bob Wilson4901f432009-09-30 21:44:42 +0000217/// doInitialization - Perform Module level initializations here.
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000218/// One task that we do here is to sectionize all global variables.
219/// The MemSelOptimizer pass depends on the sectionizing.
220///
221bool PIC16AsmPrinter::doInitialization(Module &M) {
222 bool Result = AsmPrinter::doInitialization(M);
223
224 // FIXME:: This is temporary solution to generate the include file.
225 // The processor should be passed to llc as in input and the header file
226 // should be generated accordingly.
227 O << "\n\t#include P16F1937.INC\n";
228
229 // Set the section names for all globals.
230 for (Module::global_iterator I = M.global_begin(), E = M.global_end();
Sanjiv Guptaac2620e2009-10-15 19:26:25 +0000231 I != E; ++I) {
232
233 // Record External Var Decls.
234 if (I->isDeclaration()) {
235 ExternalVarDecls.push_back(I);
236 continue;
237 }
238
239 // Record Exteranl Var Defs.
240 if (I->hasExternalLinkage() || I->hasCommonLinkage()) {
241 ExternalVarDefs.push_back(I);
242 }
243
244 // Sectionify actual data.
245 if (!I->hasAvailableExternallyLinkage()) {
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000246 const MCSection *S = getObjFileLowering().SectionForGlobal(I, Mang, TM);
247
Sanjiv Guptaac2620e2009-10-15 19:26:25 +0000248 I->setSection(((const PIC16Section *)S)->getName());
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000249 }
Sanjiv Guptaac2620e2009-10-15 19:26:25 +0000250 }
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000251
252 DbgInfo.BeginModule(M);
253 EmitFunctionDecls(M);
254 EmitUndefinedVars(M);
255 EmitDefinedVars(M);
256 EmitIData(M);
257 EmitUData(M);
Sanjiv Guptaac2620e2009-10-15 19:26:25 +0000258 EmitAllAutos(M);
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000259 EmitRomData(M);
Sanjiv Guptaac2620e2009-10-15 19:26:25 +0000260 EmitUserSections(M);
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000261 return Result;
262}
263
264/// Emit extern decls for functions imported from other modules, and emit
265/// global declarations for function defined in this module and which are
266/// available to other modules.
267///
268void PIC16AsmPrinter::EmitFunctionDecls(Module &M) {
269 // Emit declarations for external functions.
Chris Lattnera5ef4d32009-08-22 21:43:10 +0000270 O <<"\n"<<MAI->getCommentString() << "Function Declarations - BEGIN." <<"\n";
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000271 for (Module::iterator I = M.begin(), E = M.end(); I != E; I++) {
272 if (I->isIntrinsic())
273 continue;
274
275 std::string Name = Mang->getMangledName(I);
276 if (Name.compare("@abort") == 0)
277 continue;
278
279 if (!I->isDeclaration() && !I->hasExternalLinkage())
280 continue;
281
282 // Do not emit memcpy, memset, and memmove here.
283 // Calls to these routines can be generated in two ways,
284 // 1. User calling the standard lib function
285 // 2. Codegen generating these calls for llvm intrinsics.
286 // In the first case a prototype is alread availale, while in
287 // second case the call is via and externalsym and the prototype is missing.
288 // So declarations for these are currently always getting printing by
289 // tracking both kind of references in printInstrunction.
290 if (I->isDeclaration() && PAN::isMemIntrinsic(Name)) continue;
291
Chris Lattnera5ef4d32009-08-22 21:43:10 +0000292 const char *directive = I->isDeclaration() ? MAI->getExternDirective() :
293 MAI->getGlobalDirective();
Chris Lattner7f504882009-08-21 23:12:15 +0000294
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000295 O << directive << Name << "\n";
296 O << directive << PAN::getRetvalLabel(Name) << "\n";
297 O << directive << PAN::getArgsLabel(Name) << "\n";
298 }
299
Chris Lattnera5ef4d32009-08-22 21:43:10 +0000300 O << MAI->getCommentString() << "Function Declarations - END." <<"\n";
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000301}
302
303// Emit variables imported from other Modules.
304void PIC16AsmPrinter::EmitUndefinedVars(Module &M) {
Sanjiv Guptaac2620e2009-10-15 19:26:25 +0000305 std::vector<const GlobalVariable*> Items = ExternalVarDecls;
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000306 if (!Items.size()) return;
307
Chris Lattnera5ef4d32009-08-22 21:43:10 +0000308 O << "\n" << MAI->getCommentString() << "Imported Variables - BEGIN" << "\n";
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000309 for (unsigned j = 0; j < Items.size(); j++) {
Chris Lattnera5ef4d32009-08-22 21:43:10 +0000310 O << MAI->getExternDirective() << Mang->getMangledName(Items[j]) << "\n";
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000311 }
Chris Lattnera5ef4d32009-08-22 21:43:10 +0000312 O << MAI->getCommentString() << "Imported Variables - END" << "\n";
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000313}
314
315// Emit variables defined in this module and are available to other modules.
316void PIC16AsmPrinter::EmitDefinedVars(Module &M) {
Sanjiv Guptaac2620e2009-10-15 19:26:25 +0000317 std::vector<const GlobalVariable*> Items = ExternalVarDefs;
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000318 if (!Items.size()) return;
319
Chris Lattnera5ef4d32009-08-22 21:43:10 +0000320 O << "\n" << MAI->getCommentString() << "Exported Variables - BEGIN" << "\n";
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000321 for (unsigned j = 0; j < Items.size(); j++) {
Chris Lattnera5ef4d32009-08-22 21:43:10 +0000322 O << MAI->getGlobalDirective() << Mang->getMangledName(Items[j]) << "\n";
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000323 }
Chris Lattnera5ef4d32009-08-22 21:43:10 +0000324 O << MAI->getCommentString() << "Exported Variables - END" << "\n";
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000325}
326
327// Emit initialized data placed in ROM.
328void PIC16AsmPrinter::EmitRomData(Module &M) {
Sanjiv Gupta018db662009-10-16 08:58:34 +0000329 EmitSingleSection(PTOF->ROMDATASection());
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000330}
331
332bool PIC16AsmPrinter::doFinalization(Module &M) {
333 printLibcallDecls();
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000334 DbgInfo.EndModule(M);
335 O << "\n\t" << "END\n";
336 return AsmPrinter::doFinalization(M);
337}
338
339void PIC16AsmPrinter::EmitFunctionFrame(MachineFunction &MF) {
340 const Function *F = MF.getFunction();
341 std::string FuncName = Mang->getMangledName(F);
342 const TargetData *TD = TM.getTargetData();
343 // Emit the data section name.
344 O << "\n";
Chris Lattner08e63732009-08-21 23:08:09 +0000345
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000346 const MCSection *fPDataSection =
Sanjiv Guptaac2620e2009-10-15 19:26:25 +0000347 getObjFileLowering().SectionForFrame(CurrentFnName);
Chris Lattner73266f92009-08-19 05:49:37 +0000348 OutStreamer.SwitchSection(fPDataSection);
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000349
350 // Emit function frame label
351 O << PAN::getFrameLabel(CurrentFnName) << ":\n";
352
353 const Type *RetType = F->getReturnType();
354 unsigned RetSize = 0;
355 if (RetType->getTypeID() != Type::VoidTyID)
356 RetSize = TD->getTypeAllocSize(RetType);
357
358 //Emit function return value space
359 // FIXME: Do not emit RetvalLable when retsize is zero. To do this
360 // we will need to avoid printing a global directive for Retval label
361 // in emitExternandGloblas.
362 if(RetSize > 0)
363 O << PAN::getRetvalLabel(CurrentFnName) << " RES " << RetSize << "\n";
364 else
365 O << PAN::getRetvalLabel(CurrentFnName) << ": \n";
366
367 // Emit variable to hold the space for function arguments
368 unsigned ArgSize = 0;
369 for (Function::const_arg_iterator argi = F->arg_begin(),
370 arge = F->arg_end(); argi != arge ; ++argi) {
371 const Type *Ty = argi->getType();
372 ArgSize += TD->getTypeAllocSize(Ty);
373 }
374
375 O << PAN::getArgsLabel(CurrentFnName) << " RES " << ArgSize << "\n";
376
377 // Emit temporary space
378 int TempSize = PTLI->GetTmpSize();
379 if (TempSize > 0)
380 O << PAN::getTempdataLabel(CurrentFnName) << " RES " << TempSize << '\n';
381}
382
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000383
Sanjiv Guptaac2620e2009-10-15 19:26:25 +0000384void PIC16AsmPrinter::EmitInitializedDataSection(const PIC16Section *S) {
385 /// Emit Section header.
386 OutStreamer.SwitchSection(S);
387
388 std::vector<const GlobalVariable*> Items = S->Items;
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000389 for (unsigned j = 0; j < Items.size(); j++) {
390 std::string Name = Mang->getMangledName(Items[j]);
391 Constant *C = Items[j]->getInitializer();
392 int AddrSpace = Items[j]->getType()->getAddressSpace();
393 O << Name;
394 EmitGlobalConstant(C, AddrSpace);
Sanjiv Guptaac2620e2009-10-15 19:26:25 +0000395 }
Sanjiv Gupta1c138172009-10-15 10:10:43 +0000396}
397
Sanjiv Gupta018db662009-10-16 08:58:34 +0000398// Print all IDATA sections.
Sanjiv Guptaac2620e2009-10-15 19:26:25 +0000399void PIC16AsmPrinter::EmitIData(Module &M) {
Sanjiv Gupta018db662009-10-16 08:58:34 +0000400 EmitSectionList (M, PTOF->IDATASections());
Sanjiv Guptaac2620e2009-10-15 19:26:25 +0000401}
402
Sanjiv Gupta018db662009-10-16 08:58:34 +0000403void PIC16AsmPrinter::
404EmitUninitializedDataSection(const PIC16Section *S) {
Sanjiv Guptaac2620e2009-10-15 19:26:25 +0000405 const TargetData *TD = TM.getTargetData();
406 OutStreamer.SwitchSection(S);
407 std::vector<const GlobalVariable*> Items = S->Items;
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000408 for (unsigned j = 0; j < Items.size(); j++) {
409 std::string Name = Mang->getMangledName(Items[j]);
410 Constant *C = Items[j]->getInitializer();
411 const Type *Ty = C->getType();
412 unsigned Size = TD->getTypeAllocSize(Ty);
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000413 O << Name << " RES " << Size << "\n";
414 }
Sanjiv Guptaac2620e2009-10-15 19:26:25 +0000415}
416
Sanjiv Gupta018db662009-10-16 08:58:34 +0000417// Print all UDATA sections.
Sanjiv Guptaac2620e2009-10-15 19:26:25 +0000418void PIC16AsmPrinter::EmitUData(Module &M) {
Sanjiv Gupta018db662009-10-16 08:58:34 +0000419 EmitSectionList (M, PTOF->UDATASections());
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000420}
421
Sanjiv Gupta018db662009-10-16 08:58:34 +0000422// Print all USER sections.
Sanjiv Guptaac2620e2009-10-15 19:26:25 +0000423void PIC16AsmPrinter::EmitUserSections(Module &M) {
Sanjiv Gupta018db662009-10-16 08:58:34 +0000424 EmitSectionList (M, PTOF->USERSections());
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000425}
426
Sanjiv Gupta018db662009-10-16 08:58:34 +0000427// Print all AUTO sections.
Sanjiv Guptaac2620e2009-10-15 19:26:25 +0000428void PIC16AsmPrinter::EmitAllAutos(Module &M) {
Sanjiv Gupta018db662009-10-16 08:58:34 +0000429 EmitSectionList (M, PTOF->AUTOSections());
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000430}
431
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000432extern "C" void LLVMInitializePIC16AsmPrinter() {
433 RegisterAsmPrinter<PIC16AsmPrinter> X(ThePIC16Target);
434}
435
Sanjiv Gupta018db662009-10-16 08:58:34 +0000436// Emit one data section using correct section emitter based on section type.
437void PIC16AsmPrinter::EmitSingleSection(const PIC16Section *S) {
438 if (S == NULL) return;
439
440 switch (S->getType()) {
441 default: llvm_unreachable ("unknow user section type");
442 case UDATA:
443 case UDATA_SHR:
444 case UDATA_OVR:
445 EmitUninitializedDataSection(S);
446 break;
447 case IDATA:
448 case ROMDATA:
449 EmitInitializedDataSection(S);
450 break;
451 }
452}
453
454// Emit a list of sections.
455void PIC16AsmPrinter::
456EmitSectionList(Module &M, const std::vector<PIC16Section *> &SList) {
457 for (unsigned i = 0; i < SList.size(); i++) {
458 // Exclude llvm specific metadata sections.
459 if (SList[i]->getName().find("llvm.") != std::string::npos)
460 continue;
461 O << "\n";
462 EmitSingleSection(SList[i]);
463 }
464}
Sanjiv Gupta8aae07e2009-08-13 16:37:05 +0000465