blob: 109504ec68ad6d47058354f8df22810f321bda90 [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 Guptad0765702009-03-12 02:10:45 +000031inline static bool isLocalToFunc (std::string &FuncName, std::string &VarName) {
32 if (VarName.find(FuncName + ".auto.") != std::string::npos
33 || VarName.find(FuncName + ".arg.") != std::string::npos)
Sanjiv Gupta1b046942009-01-13 19:18:47 +000034 return true;
Sanjiv Gupta1b046942009-01-13 19:18:47 +000035
Sanjiv Guptad0765702009-03-12 02:10:45 +000036 return false;
37}
38
39inline static bool isLocalName (std::string &Name) {
40 if (Name.find(".auto.") != std::string::npos
41 || Name.find(".arg.") != std::string::npos)
42 return true;
43
Sanjiv Gupta1b046942009-01-13 19:18:47 +000044 return false;
45}
Sanjiv Gupta0e687712008-05-13 09:02:57 +000046
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000047bool PIC16AsmPrinter::printMachineInstruction(const MachineInstr *MI) {
Sanjiv Guptad0765702009-03-12 02:10:45 +000048 std::string NewBank = "";
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000049 unsigned Operands = MI->getNumOperands();
50 if (Operands > 1) {
51 // Global address or external symbol should be second operand from last
52 // if we want to print banksel for it.
Sanjiv Guptad0765702009-03-12 02:10:45 +000053 unsigned BankSelVar = Operands - 2;
54 // In cases where an instruction has a def or use defined in td file,
55 // that def or use becomes a machine instruction operand.
56 // eg. addfw_1 instruction defines STATUS register. So the machine
57 // instruction for it has MO_Register Operand as its last operand.
58 while ((MI->getOperand(BankSelVar + 1).getType() ==
59 MachineOperand::MO_Register) && (BankSelVar > 0))
60 BankSelVar--;
61 const MachineOperand &Op = MI->getOperand(BankSelVar);
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000062 unsigned OpType = Op.getType();
63 if (OpType == MachineOperand::MO_GlobalAddress ||
Sanjiv Guptad0765702009-03-12 02:10:45 +000064 OpType == MachineOperand::MO_ExternalSymbol) {
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000065 if (OpType == MachineOperand::MO_GlobalAddress )
Sanjiv Guptad0765702009-03-12 02:10:45 +000066 NewBank = Op.getGlobal()->getSection();
67 else {
68 // External Symbol is generated for temp data. Temp data in in
69 // fdata.<functionname>.# section.
70 NewBank = "fdata." + CurrentFnName +".#";
71 }
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000072 // Operand after global address or external symbol should be banksel.
73 // Value 1 for this operand means we need to generate banksel else do not
74 // generate banksel.
Sanjiv Guptad0765702009-03-12 02:10:45 +000075 const MachineOperand &BS = MI->getOperand(BankSelVar+1);
76 // If Section names are same then the variables are in same section.
77 // This is not true for external variables as section names for global
78 // variables in all files are same at this time. For eg. initialized
79 // data in put in idata.# section in all files.
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000080 if (((int)BS.getImm() == 1) &&
Sanjiv Guptad0765702009-03-12 02:10:45 +000081 ((Op.isGlobal() && Op.getGlobal()->hasExternalLinkage()) ||
82 (NewBank.compare(CurBank) != 0))) {
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000083 O << "\tbanksel ";
Sanjiv Guptad0765702009-03-12 02:10:45 +000084 printOperand(MI, BankSelVar);
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000085 O << "\n";
Sanjiv Guptad0765702009-03-12 02:10:45 +000086 CurBank = NewBank;
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000087 }
88 }
89 }
90 printInstruction(MI);
91 return true;
92}
93
94/// runOnMachineFunction - This uses the printInstruction()
95/// method to print assembly for each instruction.
96///
97bool PIC16AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
Bill Wendling57f0db82009-02-24 08:30:20 +000098 this->MF = &MF;
99
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000100 // This calls the base class function required to be called at beginning
101 // of runOnMachineFunction.
102 SetupMachineFunction(MF);
103
104 // Get the mangled name.
105 const Function *F = MF.getFunction();
106 CurrentFnName = Mang->getValueName(F);
107
108 // Emit the function variables.
109 emitFunctionData(MF);
110 std::string codeSection;
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000111 codeSection = "code." + CurrentFnName + ".# " + "CODE";
112 const Section *fCodeSection = TAI->getNamedSection(codeSection.c_str(),
113 SectionFlags::Code);
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000114 O << "\n";
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000115 SwitchToSection (fCodeSection);
Sanjiv Gupta7836fc12009-04-08 05:38:48 +0000116 O << CurrentFnName << ":\n";
117 O << " retlw low(" << CurrentFnName << ".frame)\n";
118 O << " retlw high(" << CurrentFnName << ".frame)\n";
119
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000120
121 // Print out code for the function.
122 for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
123 I != E; ++I) {
124 // Print a label for the basic block.
125 if (I != MF.begin()) {
126 printBasicBlockLabel(I, true);
127 O << '\n';
128 }
Sanjiv Guptad0765702009-03-12 02:10:45 +0000129 CurBank = "";
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000130 for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
131 II != E; ++II) {
132 // Print the assembly for the instruction.
133 printMachineInstruction(II);
134 }
135 }
136 return false; // we didn't modify anything.
137}
138
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000139/// createPIC16CodePrinterPass - Returns a pass that prints the PIC16
140/// assembly code for a MachineFunction to the given output stream,
141/// using the given target machine description. This should work
142/// regardless of whether the function is in SSA form.
143///
Owen Andersoncb371882008-08-21 00:14:44 +0000144FunctionPass *llvm::createPIC16CodePrinterPass(raw_ostream &o,
Bill Wendling57f0db82009-02-24 08:30:20 +0000145 PIC16TargetMachine &tm,
Evan Cheng42bf74b2009-03-25 01:47:28 +0000146 bool fast, bool verbose) {
147 return new PIC16AsmPrinter(o, tm, tm.getTargetAsmInfo(), fast, verbose);
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000148}
149
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000150void PIC16AsmPrinter::printOperand(const MachineInstr *MI, int opNum) {
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000151 const MachineOperand &MO = MI->getOperand(opNum);
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000152
Sanjiv Gupta2010b3e2008-05-14 11:31:39 +0000153 switch (MO.getType()) {
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000154 case MachineOperand::MO_Register:
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000155 if (TargetRegisterInfo::isPhysicalRegister(MO.getReg()))
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000156 O << TM.getRegisterInfo()->get(MO.getReg()).AsmName;
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000157 else
158 assert(0 && "not implemented");
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000159 return;
Sanjiv Gupta2010b3e2008-05-14 11:31:39 +0000160
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000161 case MachineOperand::MO_Immediate:
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000162 O << (int)MO.getImm();
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000163 return;
Sanjiv Gupta2010b3e2008-05-14 11:31:39 +0000164
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000165 case MachineOperand::MO_GlobalAddress:
166 O << Mang->getValueName(MO.getGlobal());
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000167 break;
Sanjiv Gupta2010b3e2008-05-14 11:31:39 +0000168
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000169 case MachineOperand::MO_ExternalSymbol:
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000170 O << MO.getSymbolName();
171 break;
Sanjiv Gupta2010b3e2008-05-14 11:31:39 +0000172
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000173 case MachineOperand::MO_MachineBasicBlock:
174 printBasicBlockLabel(MO.getMBB());
175 return;
176
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000177 default:
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000178 assert(0 && " Operand type not supported.");
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000179 }
180}
181
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000182void PIC16AsmPrinter::printCCOperand(const MachineInstr *MI, int opNum) {
183 int CC = (int)MI->getOperand(opNum).getImm();
184 O << PIC16CondCodeToString((PIC16CC::CondCodes)CC);
185}
186
187
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000188bool PIC16AsmPrinter::doInitialization (Module &M) {
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000189 bool Result = AsmPrinter::doInitialization(M);
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000190 // FIXME:: This is temporary solution to generate the include file.
191 // The processor should be passed to llc as in input and the header file
192 // should be generated accordingly.
193 O << "\t#include P16F1937.INC\n";
Sanjiv Gupta5274a4a2009-04-02 18:03:10 +0000194 MachineModuleInfo *MMI = getAnalysisIfAvailable<MachineModuleInfo>();
195 assert(MMI);
196 DwarfWriter *DW = getAnalysisIfAvailable<DwarfWriter>();
197 assert(DW && "Dwarf Writer is not available");
198 DW->BeginModule(&M, MMI, O, this, TAI);
199
Sanjiv Gupta8f78fa82008-11-26 10:53:50 +0000200 EmitExternsAndGlobals (M);
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000201 EmitInitData (M);
202 EmitUnInitData(M);
203 EmitRomData(M);
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000204 return Result;
205}
206
Sanjiv Gupta8f78fa82008-11-26 10:53:50 +0000207void PIC16AsmPrinter::EmitExternsAndGlobals (Module &M) {
208 // Emit declarations for external functions.
209 O << "section.0" <<"\n";
210 for (Module::iterator I = M.begin(), E = M.end(); I != E; I++) {
211 std::string Name = Mang->getValueName(I);
212 if (Name.compare("abort") == 0)
213 continue;
214 if (I->isDeclaration()) {
215 O << "\textern " <<Name << "\n";
216 O << "\textern " << Name << ".retval\n";
217 O << "\textern " << Name << ".args\n";
218 }
219 else if (I->hasExternalLinkage()) {
220 O << "\tglobal " << Name << "\n";
221 O << "\tglobal " << Name << ".retval\n";
222 O << "\tglobal " << Name << ".args\n";
223 }
224 }
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000225
226 // Emit header file to include declaration of library functions
227 O << "\t#include C16IntrinsicCalls.INC\n";
228
Sanjiv Gupta8f78fa82008-11-26 10:53:50 +0000229 // Emit declarations for external globals.
230 for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
231 I != E; I++) {
Sanjiv Gupta2cc75312009-02-10 04:20:26 +0000232 // Any variables reaching here with ".auto." in its name is a local scope
233 // variable and should not be printed in global data section.
Sanjiv Gupta8f78fa82008-11-26 10:53:50 +0000234 std::string Name = Mang->getValueName(I);
Sanjiv Guptad0765702009-03-12 02:10:45 +0000235 if (isLocalName (Name))
Sanjiv Gupta2cc75312009-02-10 04:20:26 +0000236 continue;
237
Sanjiv Gupta8f78fa82008-11-26 10:53:50 +0000238 if (I->isDeclaration())
239 O << "\textern "<< Name << "\n";
Sanjiv Gupta2cc75312009-02-10 04:20:26 +0000240 else if (I->hasCommonLinkage() || I->hasExternalLinkage())
Sanjiv Guptaa2d8b062009-02-06 18:24:59 +0000241 O << "\tglobal "<< Name << "\n";
Sanjiv Gupta8f78fa82008-11-26 10:53:50 +0000242 }
243}
Sanjiv Gupta2cc75312009-02-10 04:20:26 +0000244
Sanjiv Gupta8f78fa82008-11-26 10:53:50 +0000245void PIC16AsmPrinter::EmitInitData (Module &M) {
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000246 SwitchToSection(TAI->getDataSection());
Sanjiv Guptad0765702009-03-12 02:10:45 +0000247 for (Module::global_iterator I = M.global_begin(), E = M.global_end();
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000248 I != E; ++I) {
249 if (!I->hasInitializer()) // External global require no code.
250 continue;
251
252 Constant *C = I->getInitializer();
253 const PointerType *PtrTy = I->getType();
254 int AddrSpace = PtrTy->getAddressSpace();
255
256 if ((!C->isNullValue()) && (AddrSpace == PIC16ISD::RAM_SPACE)) {
257
258 if (EmitSpecialLLVMGlobal(I))
259 continue;
260
261 // Any variables reaching here with "." in its name is a local scope
262 // variable and should not be printed in global data section.
Sanjiv Guptad0765702009-03-12 02:10:45 +0000263 std::string Name = Mang->getValueName(I);
264 if (isLocalName(Name))
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000265 continue;
266
Sanjiv Guptad0765702009-03-12 02:10:45 +0000267 I->setSection(TAI->getDataSection()->getName());
268 O << Name;
Sanjiv Guptac8d7bc82009-01-30 04:25:10 +0000269 EmitGlobalConstant(C, AddrSpace);
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000270 }
271 }
272}
273
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000274void PIC16AsmPrinter::EmitRomData (Module &M)
275{
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000276 SwitchToSection(TAI->getReadOnlySection());
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000277 IsRomData = true;
Sanjiv Guptad0765702009-03-12 02:10:45 +0000278 for (Module::global_iterator I = M.global_begin(), E = M.global_end();
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000279 I != E; ++I) {
280 if (!I->hasInitializer()) // External global require no code.
281 continue;
282
283 Constant *C = I->getInitializer();
284 const PointerType *PtrTy = I->getType();
285 int AddrSpace = PtrTy->getAddressSpace();
286 if ((!C->isNullValue()) && (AddrSpace == PIC16ISD::ROM_SPACE)) {
287
288 if (EmitSpecialLLVMGlobal(I))
289 continue;
290
291 // Any variables reaching here with "." in its name is a local scope
292 // variable and should not be printed in global data section.
293 std::string name = Mang->getValueName(I);
294 if (name.find(".") != std::string::npos)
295 continue;
296
Sanjiv Guptad0765702009-03-12 02:10:45 +0000297 I->setSection(TAI->getReadOnlySection()->getName());
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000298 O << name;
Sanjiv Guptac8d7bc82009-01-30 04:25:10 +0000299 EmitGlobalConstant(C, AddrSpace);
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000300 O << "\n";
301 }
302 }
303 IsRomData = false;
304}
305
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000306void PIC16AsmPrinter::EmitUnInitData (Module &M)
307{
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000308 SwitchToSection(TAI->getBSSSection_());
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000309 const TargetData *TD = TM.getTargetData();
310
Sanjiv Guptad0765702009-03-12 02:10:45 +0000311 for (Module::global_iterator I = M.global_begin(), E = M.global_end();
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000312 I != E; ++I) {
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000313 if (!I->hasInitializer()) // External global require no code.
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000314 continue;
315
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000316 Constant *C = I->getInitializer();
317 if (C->isNullValue()) {
318
319 if (EmitSpecialLLVMGlobal(I))
320 continue;
321
322 // Any variables reaching here with "." in its name is a local scope
323 // variable and should not be printed in global data section.
324 std::string name = Mang->getValueName(I);
325 if (name.find(".") != std::string::npos)
326 continue;
327
Sanjiv Guptad0765702009-03-12 02:10:45 +0000328 I->setSection(TAI->getBSSSection_()->getName());
329
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000330 const Type *Ty = C->getType();
Duncan Sandsceb4d1a2009-01-12 20:38:59 +0000331 unsigned Size = TD->getTypePaddedSize(Ty);
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000332
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000333 O << name << " " <<"RES"<< " " << Size ;
334 O << "\n";
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000335 }
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000336 }
337}
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000338
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000339bool PIC16AsmPrinter::doFinalization(Module &M) {
340 O << "\t" << "END\n";
341 bool Result = AsmPrinter::doFinalization(M);
342 return Result;
343}
344
345void PIC16AsmPrinter::emitFunctionData(MachineFunction &MF) {
346 const Function *F = MF.getFunction();
347 std::string FuncName = Mang->getValueName(F);
Sanjiv Guptad0765702009-03-12 02:10:45 +0000348 Module *M = const_cast<Module *>(F->getParent());
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000349 const TargetData *TD = TM.getTargetData();
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000350 unsigned FrameSize = 0;
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000351 // Emit the data section name.
352 O << "\n";
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000353 std::string SectionName = "fdata." + CurrentFnName + ".# " + "UDATA";
354
355 const Section *fDataSection = TAI->getNamedSection(SectionName.c_str(),
356 SectionFlags::Writeable);
357 SwitchToSection(fDataSection);
Sanjiv Gupta8f78fa82008-11-26 10:53:50 +0000358
Sanjiv Guptab84d5a42009-04-02 17:42:00 +0000359
360 // Emit function frame label
361 O << CurrentFnName << ".frame:\n";
362
Sanjiv Gupta8f78fa82008-11-26 10:53:50 +0000363 const Type *RetType = F->getReturnType();
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000364 unsigned RetSize = 0;
365 if (RetType->getTypeID() != Type::VoidTyID)
366 RetSize = TD->getTypePaddedSize(RetType);
367
Sanjiv Guptab84d5a42009-04-02 17:42:00 +0000368 //Emit function return value space
369 if(RetSize > 0)
370 O << CurrentFnName << ".retval RES " << RetSize << "\n";
371 else
372 O << CurrentFnName << ".retval:\n";
373
374 // Emit variable to hold the space for function arguments
375 unsigned ArgSize = 0;
376 for (Function::const_arg_iterator argi = F->arg_begin(),
377 arge = F->arg_end(); argi != arge ; ++argi) {
378 const Type *Ty = argi->getType();
379 ArgSize += TD->getTypePaddedSize(Ty);
380 }
381 O << CurrentFnName << ".args RES " << ArgSize << "\n";
382
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000383 // Emit the function variables.
384
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000385 // In PIC16 all the function arguments and local variables are global.
386 // Therefore to get the variable belonging to this function entire
387 // global list will be traversed and variables belonging to this function
388 // will be emitted in the current data section.
Sanjiv Guptad0765702009-03-12 02:10:45 +0000389 for (Module::global_iterator I = M->global_begin(), E = M->global_end();
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000390 I != E; ++I) {
391 std::string VarName = Mang->getValueName(I);
392
393 // The variables of a function are of form FuncName.* . If this variable
394 // does not belong to this function then continue.
Sanjiv Gupta2cc75312009-02-10 04:20:26 +0000395 // Static local varilabes of a function does not have .auto. in their
396 // name. They are not printed as part of function data but module
397 // level global data.
Sanjiv Guptad0765702009-03-12 02:10:45 +0000398 if (! isLocalToFunc(FuncName, VarName))
399 continue;
Sanjiv Gupta2cc75312009-02-10 04:20:26 +0000400
Sanjiv Guptad0765702009-03-12 02:10:45 +0000401 I->setSection("fdata." + CurrentFnName + ".#");
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000402 Constant *C = I->getInitializer();
Sanjiv Gupta2010b3e2008-05-14 11:31:39 +0000403 const Type *Ty = C->getType();
Duncan Sandsceb4d1a2009-01-12 20:38:59 +0000404 unsigned Size = TD->getTypePaddedSize(Ty);
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000405 FrameSize += Size;
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000406 // Emit memory reserve directive.
407 O << VarName << " RES " << Size << "\n";
408 }
Sanjiv Gupta2cc75312009-02-10 04:20:26 +0000409
Sanjiv Guptacae1b622009-04-06 10:54:50 +0000410 int TempSize = PTLI->GetTmpSize();
411 if (TempSize > 0 )
412 O << CurrentFnName << ".tmp RES " << TempSize <<"\n";
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000413}