blob: fd1940437fcaa90e12142637ef2d20814e28bf89 [file] [log] [blame]
Sanjiv Guptaa57bc3b2009-05-22 13:58:45 +00001//===-- PIC16DebugInfo.cpp - Implementation for PIC16 Debug Information ======//
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 the helper functions for representing debug information.
11//
12//===----------------------------------------------------------------------===//
13
14#include "PIC16.h"
15#include "PIC16DebugInfo.h"
16#include "llvm/GlobalVariable.h"
Sanjiv Guptabde79422009-06-16 09:45:18 +000017#include "llvm/CodeGen/MachineFunction.h"
Devang Patel1e86a662009-06-19 22:08:58 +000018#include "llvm/Support/DebugLoc.h"
David Greene71847812009-07-14 20:18:05 +000019#include "llvm/Support/FormattedStream.h"
Sanjiv Guptaa57bc3b2009-05-22 13:58:45 +000020
21using namespace llvm;
22
Sanjiv Guptabde79422009-06-16 09:45:18 +000023/// PopulateDebugInfo - Populate the TypeNo, Aux[] and TagName from Ty.
24///
25void PIC16DbgInfo::PopulateDebugInfo (DIType Ty, unsigned short &TypeNo,
26 bool &HasAux, int Aux[],
27 std::string &TagName) {
28 if (Ty.isBasicType(Ty.getTag()))
29 PopulateBasicTypeInfo (Ty, TypeNo);
30 else if (Ty.isDerivedType(Ty.getTag()))
31 PopulateDerivedTypeInfo (Ty, TypeNo, HasAux, Aux, TagName);
32 else if (Ty.isCompositeType(Ty.getTag()))
33 PopulateCompositeTypeInfo (Ty, TypeNo, HasAux, Aux, TagName);
Sanjiv Guptaa57bc3b2009-05-22 13:58:45 +000034 else {
35 TypeNo = PIC16Dbg::T_NULL;
36 HasAux = false;
37 }
38 return;
39}
40
Sanjiv Guptabde79422009-06-16 09:45:18 +000041/// PopulateBasicTypeInfo- Populate TypeNo for basic type from Ty.
42///
43void PIC16DbgInfo::PopulateBasicTypeInfo (DIType Ty, unsigned short &TypeNo) {
44 std::string Name = "";
45 Ty.getName(Name);
46 unsigned short BaseTy = GetTypeDebugNumber(Name);
47 TypeNo = TypeNo << PIC16Dbg::S_BASIC;
48 TypeNo = TypeNo | (0xffff & BaseTy);
49}
Sanjiv Guptaa57bc3b2009-05-22 13:58:45 +000050
Sanjiv Guptabde79422009-06-16 09:45:18 +000051/// PopulateDerivedTypeInfo - Populate TypeNo, Aux[], TagName for derived type
52/// from Ty. Derived types are mostly pointers.
53///
54void PIC16DbgInfo::PopulateDerivedTypeInfo (DIType Ty, unsigned short &TypeNo,
55 bool &HasAux, int Aux[],
56 std::string &TagName) {
57
58 switch(Ty.getTag())
59 {
60 case dwarf::DW_TAG_pointer_type:
61 TypeNo = TypeNo << PIC16Dbg::S_DERIVED;
62 TypeNo = TypeNo | PIC16Dbg::DT_PTR;
63 break;
64 default:
65 TypeNo = TypeNo << PIC16Dbg::S_DERIVED;
66 }
67
68 // We also need to encode the the information about the base type of
69 // pointer in TypeNo.
70 DIType BaseType = DIDerivedType(Ty.getGV()).getTypeDerivedFrom();
71 PopulateDebugInfo(BaseType, TypeNo, HasAux, Aux, TagName);
72}
73
74/// PopulateArrayTypeInfo - Populate TypeNo, Aux[] for array from Ty.
75void PIC16DbgInfo::PopulateArrayTypeInfo (DIType Ty, unsigned short &TypeNo,
76 bool &HasAux, int Aux[],
77 std::string &TagName) {
78
79 DICompositeType CTy = DICompositeType(Ty.getGV());
80 DIArray Elements = CTy.getTypeArray();
81 unsigned short size = 1;
82 unsigned short Dimension[4]={0,0,0,0};
83 for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
84 DIDescriptor Element = Elements.getElement(i);
85 if (Element.getTag() == dwarf::DW_TAG_subrange_type) {
86 TypeNo = TypeNo << PIC16Dbg::S_DERIVED;
87 TypeNo = TypeNo | PIC16Dbg::DT_ARY;
88 DISubrange SubRange = DISubrange(Element.getGV());
89 Dimension[i] = SubRange.getHi() - SubRange.getLo() + 1;
90 // Each dimension is represented by 2 bytes starting at byte 9.
91 Aux[8+i*2+0] = Dimension[i];
92 Aux[8+i*2+1] = Dimension[i] >> 8;
93 size = size * Dimension[i];
94 }
95 }
96 HasAux = true;
97 // In auxillary entry for array, 7th and 8th byte represent array size.
98 Aux[6] = size & 0xff;
99 Aux[7] = size >> 8;
100 DIType BaseType = CTy.getTypeDerivedFrom();
101 PopulateDebugInfo(BaseType, TypeNo, HasAux, Aux, TagName);
102}
103
104/// PopulateStructOrUnionTypeInfo - Populate TypeNo, Aux[] , TagName for
105/// structure or union.
106///
107void PIC16DbgInfo::PopulateStructOrUnionTypeInfo (DIType Ty,
108 unsigned short &TypeNo,
109 bool &HasAux, int Aux[],
110 std::string &TagName) {
111 DICompositeType CTy = DICompositeType(Ty.getGV());
112 TypeNo = TypeNo << PIC16Dbg::S_BASIC;
113 if (Ty.getTag() == dwarf::DW_TAG_structure_type)
114 TypeNo = TypeNo | PIC16Dbg::T_STRUCT;
115 else
116 TypeNo = TypeNo | PIC16Dbg::T_UNION;
117 CTy.getName(TagName);
118 // UniqueSuffix is .number where number is obtained from
119 // llvm.dbg.composite<number>.
Daniel Dunbarf6ccee52009-07-24 08:24:36 +0000120 std::string UniqueSuffix = "." + Ty.getGV()->getNameStr().substr(18);
Sanjiv Guptabde79422009-06-16 09:45:18 +0000121 TagName += UniqueSuffix;
122 unsigned short size = CTy.getSizeInBits()/8;
123 // 7th and 8th byte represent size.
124 HasAux = true;
125 Aux[6] = size & 0xff;
126 Aux[7] = size >> 8;
127}
128
129/// PopulateEnumTypeInfo - Populate TypeNo for enum from Ty.
130void PIC16DbgInfo::PopulateEnumTypeInfo (DIType Ty, unsigned short &TypeNo) {
131 TypeNo = TypeNo << PIC16Dbg::S_BASIC;
132 TypeNo = TypeNo | PIC16Dbg::T_ENUM;
133}
134
135/// PopulateCompositeTypeInfo - Populate TypeNo, Aux[] and TagName for
136/// composite types from Ty.
137///
138void PIC16DbgInfo::PopulateCompositeTypeInfo (DIType Ty, unsigned short &TypeNo,
139 bool &HasAux, int Aux[],
140 std::string &TagName) {
141 switch (Ty.getTag()) {
142 case dwarf::DW_TAG_array_type: {
143 PopulateArrayTypeInfo (Ty, TypeNo, HasAux, Aux, TagName);
144 break;
145 }
146 case dwarf:: DW_TAG_union_type:
147 case dwarf::DW_TAG_structure_type: {
148 PopulateStructOrUnionTypeInfo (Ty, TypeNo, HasAux, Aux, TagName);
149 break;
150 }
151 case dwarf::DW_TAG_enumeration_type: {
152 PopulateEnumTypeInfo (Ty, TypeNo);
153 break;
154 }
155 default:
156 TypeNo = TypeNo << PIC16Dbg::S_DERIVED;
157 }
158}
159
160/// GetTypeDebugNumber - Get debug type number for given type.
161///
Sanjiv Guptaa57bc3b2009-05-22 13:58:45 +0000162unsigned PIC16DbgInfo::GetTypeDebugNumber(std::string &type) {
163 if (type == "char")
164 return PIC16Dbg::T_CHAR;
165 else if (type == "short")
166 return PIC16Dbg::T_SHORT;
167 else if (type == "int")
168 return PIC16Dbg::T_INT;
169 else if (type == "long")
170 return PIC16Dbg::T_LONG;
171 else if (type == "unsigned char")
172 return PIC16Dbg::T_UCHAR;
173 else if (type == "unsigned short")
174 return PIC16Dbg::T_USHORT;
175 else if (type == "unsigned int")
176 return PIC16Dbg::T_UINT;
177 else if (type == "unsigned long")
178 return PIC16Dbg::T_ULONG;
179 else
180 return 0;
181}
Sanjiv Guptabde79422009-06-16 09:45:18 +0000182
183/// GetStorageClass - Get storage class for give debug variable.
184///
185short PIC16DbgInfo::getStorageClass(DIGlobalVariable DIGV) {
Sanjiv Guptaa57bc3b2009-05-22 13:58:45 +0000186 short ClassNo;
187 if (PAN::isLocalName(DIGV.getGlobal()->getName())) {
188 // Generating C_AUTO here fails due to error in linker. Change it once
189 // linker is fixed.
190 ClassNo = PIC16Dbg::C_STAT;
191 }
192 else if (DIGV.isLocalToUnit())
193 ClassNo = PIC16Dbg::C_STAT;
194 else
195 ClassNo = PIC16Dbg::C_EXT;
196 return ClassNo;
197}
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000198
Sanjiv Guptabde79422009-06-16 09:45:18 +0000199/// BeginModule - Emit necessary debug info to start a Module and do other
200/// required initializations.
201void PIC16DbgInfo::BeginModule(Module &M) {
202 // Emit file directive for module.
Devang Patel22516662009-08-06 20:53:24 +0000203 DebugInfoFinder DbgFinder;
204 DbgFinder.processModule(M);
205 if (DbgFinder.compile_unit_count() != 0) {
Devang Patel92c55112009-07-06 23:28:36 +0000206 // FIXME : What if more then one CUs are present in a module ?
Devang Patel22516662009-08-06 20:53:24 +0000207 GlobalVariable *CU = *DbgFinder.compile_unit_begin();
Sanjiv Guptabde79422009-06-16 09:45:18 +0000208 EmitDebugDirectives = true;
209 SwitchToCU(CU);
210 }
211
212 // Emit debug info for decls of composite types.
Sanjiv Guptadcb6da32009-06-13 17:35:54 +0000213 EmitCompositeTypeDecls(M);
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000214}
215
Sanjiv Guptabde79422009-06-16 09:45:18 +0000216/// Helper to find first valid debug loc for a function.
217///
218static const DebugLoc GetDebugLocForFunction(const MachineFunction &MF) {
219 DebugLoc DL;
220 for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
221 I != E; ++I) {
222 for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
223 II != E; ++II) {
224 DL = II->getDebugLoc();
225 if (!DL.isUnknown())
226 return DL;
227 }
228 }
229 return DL;
230}
231
232/// BeginFunction - Emit necessary debug info to start a function.
233///
234void PIC16DbgInfo::BeginFunction(const MachineFunction &MF) {
235 if (! EmitDebugDirectives) return;
236
237 // Retreive the first valid debug Loc and process it.
238 const DebugLoc &DL = GetDebugLocForFunction(MF);
Sanjiv Gupta394a1a22009-08-07 11:00:02 +0000239 // Emit debug info only if valid debug info is available.
240 if (!DL.isUnknown()) {
241 ChangeDebugLoc(MF, DL, true);
242 EmitFunctBeginDI(MF.getFunction());
243 }
Sanjiv Guptabde79422009-06-16 09:45:18 +0000244 // Set current line to 0 so that.line directive is genearted after .bf.
245 CurLine = 0;
246}
247
248/// ChangeDebugLoc - Take necessary steps when DebugLoc changes.
249/// CurFile and CurLine may change as a result of this.
250///
251void PIC16DbgInfo::ChangeDebugLoc(const MachineFunction &MF,
252 const DebugLoc &DL, bool IsInBeginFunction) {
253 if (! EmitDebugDirectives) return;
254 assert (! DL.isUnknown() && "can't change to invalid debug loc");
255
256 GlobalVariable *CU = MF.getDebugLocTuple(DL).CompileUnit;
257 unsigned line = MF.getDebugLocTuple(DL).Line;
258
259 SwitchToCU(CU);
260 SwitchToLine(line, IsInBeginFunction);
261}
262
263/// SwitchToLine - Emit line directive for a new line.
264///
265void PIC16DbgInfo::SwitchToLine(unsigned Line, bool IsInBeginFunction) {
266 if (CurLine == Line) return;
267 if (!IsInBeginFunction) O << "\n\t.line " << Line << "\n";
268 CurLine = Line;
269}
270
271/// EndFunction - Emit .ef for end of function.
272///
273void PIC16DbgInfo::EndFunction(const MachineFunction &MF) {
274 if (! EmitDebugDirectives) return;
Sanjiv Gupta394a1a22009-08-07 11:00:02 +0000275 const DebugLoc &DL = GetDebugLocForFunction(MF);
276 // Emit debug info only if valid debug info is available.
277 if (!DL.isUnknown())
278 EmitFunctEndDI(MF.getFunction(), CurLine);
Sanjiv Guptabde79422009-06-16 09:45:18 +0000279}
280
281/// EndModule - Emit .eof for end of module.
282///
283void PIC16DbgInfo::EndModule(Module &M) {
284 if (! EmitDebugDirectives) return;
285 EmitVarDebugInfo(M);
286 if (CurFile != "") O << "\n\t.eof";
287}
288
289/// EmitCompositeTypeElements - Emit debug information for members of a
290/// composite type.
291///
292void PIC16DbgInfo::EmitCompositeTypeElements (DICompositeType CTy,
293 std::string UniqueSuffix) {
294 unsigned long Value = 0;
295 DIArray Elements = CTy.getTypeArray();
296 for (unsigned i = 0, N = Elements.getNumElements(); i < N; i++) {
297 DIDescriptor Element = Elements.getElement(i);
298 unsigned short TypeNo = 0;
299 bool HasAux = false;
300 int ElementAux[PIC16Dbg::AuxSize] = { 0 };
301 std::string TagName = "";
302 std::string ElementName;
303 GlobalVariable *GV = Element.getGV();
304 DIDerivedType DITy(GV);
305 DITy.getName(ElementName);
306 unsigned short ElementSize = DITy.getSizeInBits()/8;
307 // Get mangleddd name for this structure/union element.
308 std::string MangMemName = ElementName + UniqueSuffix;
309 PopulateDebugInfo(DITy, TypeNo, HasAux, ElementAux, TagName);
Daniel Dunbar1c723b72009-06-26 02:03:52 +0000310 short Class = 0;
Sanjiv Guptabde79422009-06-16 09:45:18 +0000311 if( CTy.getTag() == dwarf::DW_TAG_union_type)
312 Class = PIC16Dbg::C_MOU;
313 else if (CTy.getTag() == dwarf::DW_TAG_structure_type)
314 Class = PIC16Dbg::C_MOS;
315 EmitSymbol(MangMemName, Class, TypeNo, Value);
316 if (CTy.getTag() == dwarf::DW_TAG_structure_type)
317 Value += ElementSize;
318 if (HasAux)
319 EmitAuxEntry(MangMemName, ElementAux, PIC16Dbg::AuxSize, TagName);
320 }
321}
322
323/// EmitCompositeTypeDecls - Emit composite type declarations like structure
324/// and union declarations.
325///
Sanjiv Guptadcb6da32009-06-13 17:35:54 +0000326void PIC16DbgInfo::EmitCompositeTypeDecls(Module &M) {
327 for(iplist<GlobalVariable>::iterator I = M.getGlobalList().begin(),
328 E = M.getGlobalList().end(); I != E; I++) {
329 // Structures and union declaration's debug info has llvm.dbg.composite
330 // in its name.
Devang Patel8d6162a2009-07-06 23:11:08 +0000331 // FIXME: Checking and relying on llvm.dbg.composite name is not a good idea.
Daniel Dunbar3d5126f2009-07-22 21:33:09 +0000332 if(I->getNameStr().find("llvm.dbg.composite") != std::string::npos) {
Sanjiv Guptadcb6da32009-06-13 17:35:54 +0000333 GlobalVariable *GV = cast<GlobalVariable >(I);
334 DICompositeType CTy(GV);
335 if (CTy.getTag() == dwarf::DW_TAG_union_type ||
336 CTy.getTag() == dwarf::DW_TAG_structure_type ) {
337 std::string name;
338 CTy.getName(name);
339 std::string DIVar = I->getName();
340 // Get the number after llvm.dbg.composite and make UniqueSuffix from
341 // it.
342 std::string UniqueSuffix = "." + DIVar.substr(18);
343 std::string MangledCTyName = name + UniqueSuffix;
344 unsigned short size = CTy.getSizeInBits()/8;
345 int Aux[PIC16Dbg::AuxSize] = {0};
346 // 7th and 8th byte represent size of structure/union.
347 Aux[6] = size & 0xff;
348 Aux[7] = size >> 8;
349 // Emit .def for structure/union tag.
350 if( CTy.getTag() == dwarf::DW_TAG_union_type)
351 EmitSymbol(MangledCTyName, PIC16Dbg::C_UNTAG);
352 else if (CTy.getTag() == dwarf::DW_TAG_structure_type)
353 EmitSymbol(MangledCTyName, PIC16Dbg::C_STRTAG);
354
355 // Emit auxiliary debug information for structure/union tag.
356 EmitAuxEntry(MangledCTyName, Aux, PIC16Dbg::AuxSize);
Sanjiv Guptabde79422009-06-16 09:45:18 +0000357
358 // Emit members.
359 EmitCompositeTypeElements (CTy, UniqueSuffix);
360
Sanjiv Guptadcb6da32009-06-13 17:35:54 +0000361 // Emit mangled Symbol for end of structure/union.
362 std::string EOSSymbol = ".eos" + UniqueSuffix;
363 EmitSymbol(EOSSymbol, PIC16Dbg::C_EOS);
364 EmitAuxEntry(EOSSymbol, Aux, PIC16Dbg::AuxSize, MangledCTyName);
365 }
366 }
367 }
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000368}
369
Sanjiv Guptabde79422009-06-16 09:45:18 +0000370/// EmitFunctBeginDI - Emit .bf for function.
371///
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000372void PIC16DbgInfo::EmitFunctBeginDI(const Function *F) {
373 std::string FunctName = F->getName();
Sanjiv Guptadcb6da32009-06-13 17:35:54 +0000374 if (EmitDebugDirectives) {
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000375 std::string FunctBeginSym = ".bf." + FunctName;
376 std::string BlockBeginSym = ".bb." + FunctName;
377
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000378 int BFAux[PIC16Dbg::AuxSize] = {0};
Sanjiv Guptabde79422009-06-16 09:45:18 +0000379 BFAux[4] = CurLine;
380 BFAux[5] = CurLine >> 8;
381
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000382 // Emit debug directives for beginning of function.
383 EmitSymbol(FunctBeginSym, PIC16Dbg::C_FCN);
384 EmitAuxEntry(FunctBeginSym, BFAux, PIC16Dbg::AuxSize);
Sanjiv Guptabde79422009-06-16 09:45:18 +0000385
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000386 EmitSymbol(BlockBeginSym, PIC16Dbg::C_BLOCK);
387 EmitAuxEntry(BlockBeginSym, BFAux, PIC16Dbg::AuxSize);
388 }
389}
390
Sanjiv Guptabde79422009-06-16 09:45:18 +0000391/// EmitFunctEndDI - Emit .ef for function end.
392///
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000393void PIC16DbgInfo::EmitFunctEndDI(const Function *F, unsigned Line) {
394 std::string FunctName = F->getName();
Sanjiv Guptadcb6da32009-06-13 17:35:54 +0000395 if (EmitDebugDirectives) {
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000396 std::string FunctEndSym = ".ef." + FunctName;
397 std::string BlockEndSym = ".eb." + FunctName;
398
399 // Emit debug directives for end of function.
400 EmitSymbol(BlockEndSym, PIC16Dbg::C_BLOCK);
401 int EFAux[PIC16Dbg::AuxSize] = {0};
402 // 5th and 6th byte stand for line number.
Sanjiv Guptabde79422009-06-16 09:45:18 +0000403 EFAux[4] = CurLine;
404 EFAux[5] = CurLine >> 8;
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000405 EmitAuxEntry(BlockEndSym, EFAux, PIC16Dbg::AuxSize);
406 EmitSymbol(FunctEndSym, PIC16Dbg::C_FCN);
407 EmitAuxEntry(FunctEndSym, EFAux, PIC16Dbg::AuxSize);
408 }
409}
410
411/// EmitAuxEntry - Emit Auxiliary debug information.
412///
Sanjiv Guptabde79422009-06-16 09:45:18 +0000413void PIC16DbgInfo::EmitAuxEntry(const std::string VarName, int Aux[], int Num,
414 std::string TagName) {
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000415 O << "\n\t.dim " << VarName << ", 1" ;
Sanjiv Guptabde79422009-06-16 09:45:18 +0000416 // TagName is emitted in case of structure/union objects.
417 if (TagName != "")
418 O << ", " << TagName;
419 for (int i = 0; i<Num; i++)
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000420 O << "," << Aux[i];
421}
422
Sanjiv Guptabde79422009-06-16 09:45:18 +0000423/// EmitSymbol - Emit .def for a symbol. Value is offset for the member.
424///
Sanjiv Guptadcb6da32009-06-13 17:35:54 +0000425void PIC16DbgInfo::EmitSymbol(std::string Name, short Class, unsigned short
426 Type, unsigned long Value) {
427 O << "\n\t" << ".def "<< Name << ", type = " << Type << ", class = "
428 << Class;
429 if (Value > 0)
430 O << ", value = " << Value;
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000431}
432
Sanjiv Guptabde79422009-06-16 09:45:18 +0000433/// EmitVarDebugInfo - Emit debug information for all variables.
434///
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000435void PIC16DbgInfo::EmitVarDebugInfo(Module &M) {
Devang Patel22516662009-08-06 20:53:24 +0000436 DebugInfoFinder DbgFinder;
437 DbgFinder.processModule(M);
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000438
Devang Patel22516662009-08-06 20:53:24 +0000439 for (DebugInfoFinder::iterator I = DbgFinder.global_variable_begin(),
440 E = DbgFinder.global_variable_end(); I != E; ++I) {
Devang Patel92c55112009-07-06 23:28:36 +0000441 DIGlobalVariable DIGV(*I);
442 DIType Ty = DIGV.getType();
443 unsigned short TypeNo = 0;
444 bool HasAux = false;
445 int Aux[PIC16Dbg::AuxSize] = { 0 };
446 std::string TagName = "";
Daniel Dunbarf6ccee52009-07-24 08:24:36 +0000447 std::string VarName = TAI->getGlobalPrefix()+DIGV.getGlobal()->getNameStr();
Devang Patel92c55112009-07-06 23:28:36 +0000448 PopulateDebugInfo(Ty, TypeNo, HasAux, Aux, TagName);
449 // Emit debug info only if type information is availaible.
450 if (TypeNo != PIC16Dbg::T_NULL) {
451 O << "\n\t.type " << VarName << ", " << TypeNo;
452 short ClassNo = getStorageClass(DIGV);
453 O << "\n\t.class " << VarName << ", " << ClassNo;
454 if (HasAux)
455 EmitAuxEntry(VarName, Aux, PIC16Dbg::AuxSize, TagName);
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000456 }
457 }
458 O << "\n";
459}
460
Sanjiv Guptabde79422009-06-16 09:45:18 +0000461/// SwitchToCU - Switch to a new compilation unit.
462///
463void PIC16DbgInfo::SwitchToCU(GlobalVariable *CU) {
464 // Get the file path from CU.
465 DICompileUnit cu(CU);
466 std::string DirName, FileName;
467 std::string FilePath = cu.getDirectory(DirName) + "/" +
468 cu.getFilename(FileName);
469
470 // Nothing to do if source file is still same.
471 if ( FilePath == CurFile ) return;
472
473 // Else, close the current one and start a new.
474 if (CurFile != "") O << "\n\t.eof";
475 O << "\n\t.file\t\"" << FilePath << "\"\n" ;
476 CurFile = FilePath;
477 CurLine = 0;
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000478}
Sanjiv Gupta3fc7e532009-06-03 16:27:49 +0000479
Sanjiv Guptabde79422009-06-16 09:45:18 +0000480/// EmitEOF - Emit .eof for end of file.
481///
Sanjiv Gupta3fc7e532009-06-03 16:27:49 +0000482void PIC16DbgInfo::EmitEOF() {
483 if (CurFile != "")
484 O << "\n\t.EOF";
485}
486