blob: cdd211b939ffa89a01d43ae82b3db5d26be7ebe6 [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 Gupta0e687712008-05-13 09:02:57 +000024
25using namespace llvm;
26
Sanjiv Gupta0e687712008-05-13 09:02:57 +000027#include "PIC16GenAsmWriter.inc"
Sanjiv Gupta1b046942009-01-13 19:18:47 +000028
Sanjiv Guptad0765702009-03-12 02:10:45 +000029inline static bool isLocalToFunc (std::string &FuncName, std::string &VarName) {
30 if (VarName.find(FuncName + ".auto.") != std::string::npos
31 || VarName.find(FuncName + ".arg.") != std::string::npos)
Sanjiv Gupta1b046942009-01-13 19:18:47 +000032 return true;
Sanjiv Gupta1b046942009-01-13 19:18:47 +000033
Sanjiv Guptad0765702009-03-12 02:10:45 +000034 return false;
35}
36
37inline static bool isLocalName (std::string &Name) {
38 if (Name.find(".auto.") != std::string::npos
39 || Name.find(".arg.") != std::string::npos)
40 return true;
41
Sanjiv Gupta1b046942009-01-13 19:18:47 +000042 return false;
43}
Sanjiv Gupta0e687712008-05-13 09:02:57 +000044
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000045bool PIC16AsmPrinter::printMachineInstruction(const MachineInstr *MI) {
Sanjiv Guptad0765702009-03-12 02:10:45 +000046 std::string NewBank = "";
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000047 unsigned Operands = MI->getNumOperands();
48 if (Operands > 1) {
49 // Global address or external symbol should be second operand from last
50 // if we want to print banksel for it.
Sanjiv Guptad0765702009-03-12 02:10:45 +000051 unsigned BankSelVar = Operands - 2;
52 // In cases where an instruction has a def or use defined in td file,
53 // that def or use becomes a machine instruction operand.
54 // eg. addfw_1 instruction defines STATUS register. So the machine
55 // instruction for it has MO_Register Operand as its last operand.
56 while ((MI->getOperand(BankSelVar + 1).getType() ==
57 MachineOperand::MO_Register) && (BankSelVar > 0))
58 BankSelVar--;
59 const MachineOperand &Op = MI->getOperand(BankSelVar);
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000060 unsigned OpType = Op.getType();
61 if (OpType == MachineOperand::MO_GlobalAddress ||
Sanjiv Guptad0765702009-03-12 02:10:45 +000062 OpType == MachineOperand::MO_ExternalSymbol) {
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000063 if (OpType == MachineOperand::MO_GlobalAddress )
Sanjiv Guptad0765702009-03-12 02:10:45 +000064 NewBank = Op.getGlobal()->getSection();
65 else {
66 // External Symbol is generated for temp data. Temp data in in
67 // fdata.<functionname>.# section.
68 NewBank = "fdata." + CurrentFnName +".#";
69 }
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000070 // Operand after global address or external symbol should be banksel.
71 // Value 1 for this operand means we need to generate banksel else do not
72 // generate banksel.
Sanjiv Guptad0765702009-03-12 02:10:45 +000073 const MachineOperand &BS = MI->getOperand(BankSelVar+1);
74 // If Section names are same then the variables are in same section.
75 // This is not true for external variables as section names for global
76 // variables in all files are same at this time. For eg. initialized
77 // data in put in idata.# section in all files.
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000078 if (((int)BS.getImm() == 1) &&
Sanjiv Guptad0765702009-03-12 02:10:45 +000079 ((Op.isGlobal() && Op.getGlobal()->hasExternalLinkage()) ||
80 (NewBank.compare(CurBank) != 0))) {
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000081 O << "\tbanksel ";
Sanjiv Guptad0765702009-03-12 02:10:45 +000082 printOperand(MI, BankSelVar);
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000083 O << "\n";
Sanjiv Guptad0765702009-03-12 02:10:45 +000084 CurBank = NewBank;
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000085 }
86 }
87 }
88 printInstruction(MI);
89 return true;
90}
91
92/// runOnMachineFunction - This uses the printInstruction()
93/// method to print assembly for each instruction.
94///
95bool PIC16AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
Bill Wendling57f0db82009-02-24 08:30:20 +000096 this->MF = &MF;
97
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000098 // This calls the base class function required to be called at beginning
99 // of runOnMachineFunction.
100 SetupMachineFunction(MF);
101
102 // Get the mangled name.
103 const Function *F = MF.getFunction();
104 CurrentFnName = Mang->getValueName(F);
105
106 // Emit the function variables.
107 emitFunctionData(MF);
108 std::string codeSection;
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000109 codeSection = "code." + CurrentFnName + ".# " + "CODE";
110 const Section *fCodeSection = TAI->getNamedSection(codeSection.c_str(),
111 SectionFlags::Code);
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000112 O << "\n";
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000113 SwitchToSection (fCodeSection);
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000114
115 // Print out code for the function.
116 for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
117 I != E; ++I) {
118 // Print a label for the basic block.
119 if (I != MF.begin()) {
120 printBasicBlockLabel(I, true);
121 O << '\n';
122 }
123 else
Sanjiv Gupta8f78fa82008-11-26 10:53:50 +0000124 O << CurrentFnName << ":\n";
Sanjiv Guptad0765702009-03-12 02:10:45 +0000125 CurBank = "";
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000126 for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
127 II != E; ++II) {
128 // Print the assembly for the instruction.
129 printMachineInstruction(II);
130 }
131 }
132 return false; // we didn't modify anything.
133}
134
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000135/// createPIC16CodePrinterPass - Returns a pass that prints the PIC16
136/// assembly code for a MachineFunction to the given output stream,
137/// using the given target machine description. This should work
138/// regardless of whether the function is in SSA form.
139///
Owen Andersoncb371882008-08-21 00:14:44 +0000140FunctionPass *llvm::createPIC16CodePrinterPass(raw_ostream &o,
Bill Wendling57f0db82009-02-24 08:30:20 +0000141 PIC16TargetMachine &tm,
142 bool fast) {
143 return new PIC16AsmPrinter(o, tm, tm.getTargetAsmInfo(), fast);
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000144}
145
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000146void PIC16AsmPrinter::printOperand(const MachineInstr *MI, int opNum) {
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000147 const MachineOperand &MO = MI->getOperand(opNum);
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000148
Sanjiv Gupta2010b3e2008-05-14 11:31:39 +0000149 switch (MO.getType()) {
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000150 case MachineOperand::MO_Register:
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000151 if (TargetRegisterInfo::isPhysicalRegister(MO.getReg()))
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000152 O << TM.getRegisterInfo()->get(MO.getReg()).AsmName;
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000153 else
154 assert(0 && "not implemented");
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000155 return;
Sanjiv Gupta2010b3e2008-05-14 11:31:39 +0000156
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000157 case MachineOperand::MO_Immediate:
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000158 O << (int)MO.getImm();
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000159 return;
Sanjiv Gupta2010b3e2008-05-14 11:31:39 +0000160
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000161 case MachineOperand::MO_GlobalAddress:
162 O << Mang->getValueName(MO.getGlobal());
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000163 break;
Sanjiv Gupta2010b3e2008-05-14 11:31:39 +0000164
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000165 case MachineOperand::MO_ExternalSymbol:
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000166 O << MO.getSymbolName();
167 break;
Sanjiv Gupta2010b3e2008-05-14 11:31:39 +0000168
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000169 case MachineOperand::MO_MachineBasicBlock:
170 printBasicBlockLabel(MO.getMBB());
171 return;
172
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000173 default:
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000174 assert(0 && " Operand type not supported.");
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000175 }
176}
177
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000178void PIC16AsmPrinter::printCCOperand(const MachineInstr *MI, int opNum) {
179 int CC = (int)MI->getOperand(opNum).getImm();
180 O << PIC16CondCodeToString((PIC16CC::CondCodes)CC);
181}
182
183
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000184bool PIC16AsmPrinter::doInitialization (Module &M) {
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000185 bool Result = AsmPrinter::doInitialization(M);
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000186 // FIXME:: This is temporary solution to generate the include file.
187 // The processor should be passed to llc as in input and the header file
188 // should be generated accordingly.
189 O << "\t#include P16F1937.INC\n";
Sanjiv Gupta8f78fa82008-11-26 10:53:50 +0000190 EmitExternsAndGlobals (M);
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000191 EmitInitData (M);
192 EmitUnInitData(M);
193 EmitRomData(M);
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000194 return Result;
195}
196
Sanjiv Gupta8f78fa82008-11-26 10:53:50 +0000197void PIC16AsmPrinter::EmitExternsAndGlobals (Module &M) {
198 // Emit declarations for external functions.
199 O << "section.0" <<"\n";
200 for (Module::iterator I = M.begin(), E = M.end(); I != E; I++) {
201 std::string Name = Mang->getValueName(I);
202 if (Name.compare("abort") == 0)
203 continue;
204 if (I->isDeclaration()) {
205 O << "\textern " <<Name << "\n";
206 O << "\textern " << Name << ".retval\n";
207 O << "\textern " << Name << ".args\n";
208 }
209 else if (I->hasExternalLinkage()) {
210 O << "\tglobal " << Name << "\n";
211 O << "\tglobal " << Name << ".retval\n";
212 O << "\tglobal " << Name << ".args\n";
213 }
214 }
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000215
216 // Emit header file to include declaration of library functions
217 O << "\t#include C16IntrinsicCalls.INC\n";
218
Sanjiv Gupta8f78fa82008-11-26 10:53:50 +0000219 // Emit declarations for external globals.
220 for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
221 I != E; I++) {
Sanjiv Gupta2cc75312009-02-10 04:20:26 +0000222 // Any variables reaching here with ".auto." in its name is a local scope
223 // variable and should not be printed in global data section.
Sanjiv Gupta8f78fa82008-11-26 10:53:50 +0000224 std::string Name = Mang->getValueName(I);
Sanjiv Guptad0765702009-03-12 02:10:45 +0000225 if (isLocalName (Name))
Sanjiv Gupta2cc75312009-02-10 04:20:26 +0000226 continue;
227
Sanjiv Gupta8f78fa82008-11-26 10:53:50 +0000228 if (I->isDeclaration())
229 O << "\textern "<< Name << "\n";
Sanjiv Gupta2cc75312009-02-10 04:20:26 +0000230 else if (I->hasCommonLinkage() || I->hasExternalLinkage())
Sanjiv Guptaa2d8b062009-02-06 18:24:59 +0000231 O << "\tglobal "<< Name << "\n";
Sanjiv Gupta8f78fa82008-11-26 10:53:50 +0000232 }
233}
Sanjiv Gupta2cc75312009-02-10 04:20:26 +0000234
Sanjiv Gupta8f78fa82008-11-26 10:53:50 +0000235void PIC16AsmPrinter::EmitInitData (Module &M) {
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000236 SwitchToSection(TAI->getDataSection());
Sanjiv Guptad0765702009-03-12 02:10:45 +0000237 for (Module::global_iterator I = M.global_begin(), E = M.global_end();
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000238 I != E; ++I) {
239 if (!I->hasInitializer()) // External global require no code.
240 continue;
241
242 Constant *C = I->getInitializer();
243 const PointerType *PtrTy = I->getType();
244 int AddrSpace = PtrTy->getAddressSpace();
245
246 if ((!C->isNullValue()) && (AddrSpace == PIC16ISD::RAM_SPACE)) {
247
248 if (EmitSpecialLLVMGlobal(I))
249 continue;
250
251 // Any variables reaching here with "." in its name is a local scope
252 // variable and should not be printed in global data section.
Sanjiv Guptad0765702009-03-12 02:10:45 +0000253 std::string Name = Mang->getValueName(I);
254 if (isLocalName(Name))
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000255 continue;
256
Sanjiv Guptad0765702009-03-12 02:10:45 +0000257 I->setSection(TAI->getDataSection()->getName());
258 O << Name;
Sanjiv Guptac8d7bc82009-01-30 04:25:10 +0000259 EmitGlobalConstant(C, AddrSpace);
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000260 }
261 }
262}
263
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000264void PIC16AsmPrinter::EmitRomData (Module &M)
265{
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000266 SwitchToSection(TAI->getReadOnlySection());
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000267 IsRomData = true;
Sanjiv Guptad0765702009-03-12 02:10:45 +0000268 for (Module::global_iterator I = M.global_begin(), E = M.global_end();
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000269 I != E; ++I) {
270 if (!I->hasInitializer()) // External global require no code.
271 continue;
272
273 Constant *C = I->getInitializer();
274 const PointerType *PtrTy = I->getType();
275 int AddrSpace = PtrTy->getAddressSpace();
276 if ((!C->isNullValue()) && (AddrSpace == PIC16ISD::ROM_SPACE)) {
277
278 if (EmitSpecialLLVMGlobal(I))
279 continue;
280
281 // Any variables reaching here with "." in its name is a local scope
282 // variable and should not be printed in global data section.
283 std::string name = Mang->getValueName(I);
284 if (name.find(".") != std::string::npos)
285 continue;
286
Sanjiv Guptad0765702009-03-12 02:10:45 +0000287 I->setSection(TAI->getReadOnlySection()->getName());
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000288 O << name;
Sanjiv Guptac8d7bc82009-01-30 04:25:10 +0000289 EmitGlobalConstant(C, AddrSpace);
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000290 O << "\n";
291 }
292 }
293 IsRomData = false;
294}
295
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000296void PIC16AsmPrinter::EmitUnInitData (Module &M)
297{
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000298 SwitchToSection(TAI->getBSSSection_());
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000299 const TargetData *TD = TM.getTargetData();
300
Sanjiv Guptad0765702009-03-12 02:10:45 +0000301 for (Module::global_iterator I = M.global_begin(), E = M.global_end();
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000302 I != E; ++I) {
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000303 if (!I->hasInitializer()) // External global require no code.
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000304 continue;
305
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000306 Constant *C = I->getInitializer();
307 if (C->isNullValue()) {
308
309 if (EmitSpecialLLVMGlobal(I))
310 continue;
311
312 // Any variables reaching here with "." in its name is a local scope
313 // variable and should not be printed in global data section.
314 std::string name = Mang->getValueName(I);
315 if (name.find(".") != std::string::npos)
316 continue;
317
Sanjiv Guptad0765702009-03-12 02:10:45 +0000318 I->setSection(TAI->getBSSSection_()->getName());
319
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000320 const Type *Ty = C->getType();
Duncan Sandsceb4d1a2009-01-12 20:38:59 +0000321 unsigned Size = TD->getTypePaddedSize(Ty);
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000322
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000323 O << name << " " <<"RES"<< " " << Size ;
324 O << "\n";
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000325 }
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000326 }
327}
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000328
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000329bool PIC16AsmPrinter::doFinalization(Module &M) {
330 O << "\t" << "END\n";
331 bool Result = AsmPrinter::doFinalization(M);
332 return Result;
333}
334
335void PIC16AsmPrinter::emitFunctionData(MachineFunction &MF) {
336 const Function *F = MF.getFunction();
337 std::string FuncName = Mang->getValueName(F);
Sanjiv Guptad0765702009-03-12 02:10:45 +0000338 Module *M = const_cast<Module *>(F->getParent());
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000339 const TargetData *TD = TM.getTargetData();
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000340 unsigned FrameSize = 0;
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000341 // Emit the data section name.
342 O << "\n";
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000343 std::string SectionName = "fdata." + CurrentFnName + ".# " + "UDATA";
344
345 const Section *fDataSection = TAI->getNamedSection(SectionName.c_str(),
346 SectionFlags::Writeable);
347 SwitchToSection(fDataSection);
Sanjiv Gupta8f78fa82008-11-26 10:53:50 +0000348
349 //Emit function return value.
350 O << CurrentFnName << ".retval:\n";
351 const Type *RetType = F->getReturnType();
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000352 unsigned RetSize = 0;
353 if (RetType->getTypeID() != Type::VoidTyID)
354 RetSize = TD->getTypePaddedSize(RetType);
355
Sanjiv Gupta8f78fa82008-11-26 10:53:50 +0000356 // Emit function arguments.
357 O << CurrentFnName << ".args:\n";
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000358 // Emit the function variables.
359
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000360 // In PIC16 all the function arguments and local variables are global.
361 // Therefore to get the variable belonging to this function entire
362 // global list will be traversed and variables belonging to this function
363 // will be emitted in the current data section.
Sanjiv Guptad0765702009-03-12 02:10:45 +0000364 for (Module::global_iterator I = M->global_begin(), E = M->global_end();
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000365 I != E; ++I) {
366 std::string VarName = Mang->getValueName(I);
367
368 // The variables of a function are of form FuncName.* . If this variable
369 // does not belong to this function then continue.
Sanjiv Gupta2cc75312009-02-10 04:20:26 +0000370 // Static local varilabes of a function does not have .auto. in their
371 // name. They are not printed as part of function data but module
372 // level global data.
Sanjiv Guptad0765702009-03-12 02:10:45 +0000373 if (! isLocalToFunc(FuncName, VarName))
374 continue;
Sanjiv Gupta2cc75312009-02-10 04:20:26 +0000375
Sanjiv Guptad0765702009-03-12 02:10:45 +0000376 I->setSection("fdata." + CurrentFnName + ".#");
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000377 Constant *C = I->getInitializer();
Sanjiv Gupta2010b3e2008-05-14 11:31:39 +0000378 const Type *Ty = C->getType();
Duncan Sandsceb4d1a2009-01-12 20:38:59 +0000379 unsigned Size = TD->getTypePaddedSize(Ty);
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000380 FrameSize += Size;
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000381 // Emit memory reserve directive.
382 O << VarName << " RES " << Size << "\n";
383 }
Sanjiv Gupta2cc75312009-02-10 04:20:26 +0000384
385 // Return value can not overlap with temp data, becasue a temp slot
386 // may be read/written after a return value is calculated and saved
387 // within the function.
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000388 if (RetSize > FrameSize)
Sanjiv Gupta2cc75312009-02-10 04:20:26 +0000389 O << CurrentFnName << ".dummy" << " RES " << (RetSize - FrameSize) << "\n";
390
391 emitFunctionTempData(MF, FrameSize);
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000392}
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000393
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000394void PIC16AsmPrinter::emitFunctionTempData(MachineFunction &MF,
395 unsigned &FrameSize) {
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000396 // Emit temporary variables.
397 MachineFrameInfo *FrameInfo = MF.getFrameInfo();
398 if (FrameInfo->hasStackObjects()) {
399 int indexBegin = FrameInfo->getObjectIndexBegin();
400 int indexEnd = FrameInfo->getObjectIndexEnd();
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000401
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000402 if (indexBegin < indexEnd) {
403 FrameSize += indexEnd - indexBegin;
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000404 O << CurrentFnName << ".tmp RES"<< " "
405 <<indexEnd - indexBegin <<"\n";
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000406 }
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000407 /*
408 while (indexBegin < indexEnd) {
409 O << CurrentFnName << "_tmp_" << indexBegin << " " << "RES"<< " "
410 << 1 << "\n" ;
411 indexBegin++;
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000412 }
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000413 */
414 }
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000415}