blob: 52a13ba8f065528b0ad383d78cae7163405fd203 [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"
Devang Patel715c6622009-08-10 22:11:20 +000020#include "llvm/ADT/SmallString.h"
Sanjiv Guptaa57bc3b2009-05-22 13:58:45 +000021
22using namespace llvm;
23
Sanjiv Guptabde79422009-06-16 09:45:18 +000024/// PopulateDebugInfo - Populate the TypeNo, Aux[] and TagName from Ty.
25///
26void PIC16DbgInfo::PopulateDebugInfo (DIType Ty, unsigned short &TypeNo,
27 bool &HasAux, int Aux[],
28 std::string &TagName) {
29 if (Ty.isBasicType(Ty.getTag()))
30 PopulateBasicTypeInfo (Ty, TypeNo);
31 else if (Ty.isDerivedType(Ty.getTag()))
32 PopulateDerivedTypeInfo (Ty, TypeNo, HasAux, Aux, TagName);
33 else if (Ty.isCompositeType(Ty.getTag()))
34 PopulateCompositeTypeInfo (Ty, TypeNo, HasAux, Aux, TagName);
Sanjiv Guptaa57bc3b2009-05-22 13:58:45 +000035 else {
36 TypeNo = PIC16Dbg::T_NULL;
37 HasAux = false;
38 }
39 return;
40}
41
Sanjiv Guptabde79422009-06-16 09:45:18 +000042/// PopulateBasicTypeInfo- Populate TypeNo for basic type from Ty.
43///
44void PIC16DbgInfo::PopulateBasicTypeInfo (DIType Ty, unsigned short &TypeNo) {
45 std::string Name = "";
46 Ty.getName(Name);
47 unsigned short BaseTy = GetTypeDebugNumber(Name);
48 TypeNo = TypeNo << PIC16Dbg::S_BASIC;
49 TypeNo = TypeNo | (0xffff & BaseTy);
50}
Sanjiv Guptaa57bc3b2009-05-22 13:58:45 +000051
Sanjiv Guptabde79422009-06-16 09:45:18 +000052/// PopulateDerivedTypeInfo - Populate TypeNo, Aux[], TagName for derived type
53/// from Ty. Derived types are mostly pointers.
54///
55void PIC16DbgInfo::PopulateDerivedTypeInfo (DIType Ty, unsigned short &TypeNo,
56 bool &HasAux, int Aux[],
57 std::string &TagName) {
58
59 switch(Ty.getTag())
60 {
61 case dwarf::DW_TAG_pointer_type:
62 TypeNo = TypeNo << PIC16Dbg::S_DERIVED;
63 TypeNo = TypeNo | PIC16Dbg::DT_PTR;
64 break;
65 default:
66 TypeNo = TypeNo << PIC16Dbg::S_DERIVED;
67 }
68
69 // We also need to encode the the information about the base type of
70 // pointer in TypeNo.
71 DIType BaseType = DIDerivedType(Ty.getGV()).getTypeDerivedFrom();
72 PopulateDebugInfo(BaseType, TypeNo, HasAux, Aux, TagName);
73}
74
75/// PopulateArrayTypeInfo - Populate TypeNo, Aux[] for array from Ty.
76void PIC16DbgInfo::PopulateArrayTypeInfo (DIType Ty, unsigned short &TypeNo,
77 bool &HasAux, int Aux[],
78 std::string &TagName) {
79
80 DICompositeType CTy = DICompositeType(Ty.getGV());
81 DIArray Elements = CTy.getTypeArray();
82 unsigned short size = 1;
83 unsigned short Dimension[4]={0,0,0,0};
84 for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
85 DIDescriptor Element = Elements.getElement(i);
86 if (Element.getTag() == dwarf::DW_TAG_subrange_type) {
87 TypeNo = TypeNo << PIC16Dbg::S_DERIVED;
88 TypeNo = TypeNo | PIC16Dbg::DT_ARY;
89 DISubrange SubRange = DISubrange(Element.getGV());
90 Dimension[i] = SubRange.getHi() - SubRange.getLo() + 1;
91 // Each dimension is represented by 2 bytes starting at byte 9.
92 Aux[8+i*2+0] = Dimension[i];
93 Aux[8+i*2+1] = Dimension[i] >> 8;
94 size = size * Dimension[i];
95 }
96 }
97 HasAux = true;
98 // In auxillary entry for array, 7th and 8th byte represent array size.
99 Aux[6] = size & 0xff;
100 Aux[7] = size >> 8;
101 DIType BaseType = CTy.getTypeDerivedFrom();
102 PopulateDebugInfo(BaseType, TypeNo, HasAux, Aux, TagName);
103}
104
105/// PopulateStructOrUnionTypeInfo - Populate TypeNo, Aux[] , TagName for
106/// structure or union.
107///
108void PIC16DbgInfo::PopulateStructOrUnionTypeInfo (DIType Ty,
109 unsigned short &TypeNo,
110 bool &HasAux, int Aux[],
111 std::string &TagName) {
112 DICompositeType CTy = DICompositeType(Ty.getGV());
113 TypeNo = TypeNo << PIC16Dbg::S_BASIC;
114 if (Ty.getTag() == dwarf::DW_TAG_structure_type)
115 TypeNo = TypeNo | PIC16Dbg::T_STRUCT;
116 else
117 TypeNo = TypeNo | PIC16Dbg::T_UNION;
118 CTy.getName(TagName);
119 // UniqueSuffix is .number where number is obtained from
120 // llvm.dbg.composite<number>.
Devang Patel715c6622009-08-10 22:11:20 +0000121 // FIXME: This will break when composite type is not represented by
122 // llvm.dbg.composite* global variable. This is not supported.
Daniel Dunbarf6ccee52009-07-24 08:24:36 +0000123 std::string UniqueSuffix = "." + Ty.getGV()->getNameStr().substr(18);
Sanjiv Guptabde79422009-06-16 09:45:18 +0000124 TagName += UniqueSuffix;
125 unsigned short size = CTy.getSizeInBits()/8;
126 // 7th and 8th byte represent size.
127 HasAux = true;
128 Aux[6] = size & 0xff;
129 Aux[7] = size >> 8;
130}
131
132/// PopulateEnumTypeInfo - Populate TypeNo for enum from Ty.
133void PIC16DbgInfo::PopulateEnumTypeInfo (DIType Ty, unsigned short &TypeNo) {
134 TypeNo = TypeNo << PIC16Dbg::S_BASIC;
135 TypeNo = TypeNo | PIC16Dbg::T_ENUM;
136}
137
138/// PopulateCompositeTypeInfo - Populate TypeNo, Aux[] and TagName for
139/// composite types from Ty.
140///
141void PIC16DbgInfo::PopulateCompositeTypeInfo (DIType Ty, unsigned short &TypeNo,
142 bool &HasAux, int Aux[],
143 std::string &TagName) {
144 switch (Ty.getTag()) {
145 case dwarf::DW_TAG_array_type: {
146 PopulateArrayTypeInfo (Ty, TypeNo, HasAux, Aux, TagName);
147 break;
148 }
149 case dwarf:: DW_TAG_union_type:
150 case dwarf::DW_TAG_structure_type: {
151 PopulateStructOrUnionTypeInfo (Ty, TypeNo, HasAux, Aux, TagName);
152 break;
153 }
154 case dwarf::DW_TAG_enumeration_type: {
155 PopulateEnumTypeInfo (Ty, TypeNo);
156 break;
157 }
158 default:
159 TypeNo = TypeNo << PIC16Dbg::S_DERIVED;
160 }
161}
162
163/// GetTypeDebugNumber - Get debug type number for given type.
164///
Sanjiv Guptaa57bc3b2009-05-22 13:58:45 +0000165unsigned PIC16DbgInfo::GetTypeDebugNumber(std::string &type) {
166 if (type == "char")
167 return PIC16Dbg::T_CHAR;
168 else if (type == "short")
169 return PIC16Dbg::T_SHORT;
170 else if (type == "int")
171 return PIC16Dbg::T_INT;
172 else if (type == "long")
173 return PIC16Dbg::T_LONG;
174 else if (type == "unsigned char")
175 return PIC16Dbg::T_UCHAR;
176 else if (type == "unsigned short")
177 return PIC16Dbg::T_USHORT;
178 else if (type == "unsigned int")
179 return PIC16Dbg::T_UINT;
180 else if (type == "unsigned long")
181 return PIC16Dbg::T_ULONG;
182 else
183 return 0;
184}
Sanjiv Guptabde79422009-06-16 09:45:18 +0000185
186/// GetStorageClass - Get storage class for give debug variable.
187///
188short PIC16DbgInfo::getStorageClass(DIGlobalVariable DIGV) {
Sanjiv Guptaa57bc3b2009-05-22 13:58:45 +0000189 short ClassNo;
190 if (PAN::isLocalName(DIGV.getGlobal()->getName())) {
191 // Generating C_AUTO here fails due to error in linker. Change it once
192 // linker is fixed.
193 ClassNo = PIC16Dbg::C_STAT;
194 }
195 else if (DIGV.isLocalToUnit())
196 ClassNo = PIC16Dbg::C_STAT;
197 else
198 ClassNo = PIC16Dbg::C_EXT;
199 return ClassNo;
200}
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000201
Sanjiv Guptabde79422009-06-16 09:45:18 +0000202/// BeginModule - Emit necessary debug info to start a Module and do other
203/// required initializations.
204void PIC16DbgInfo::BeginModule(Module &M) {
205 // Emit file directive for module.
Devang Patel22516662009-08-06 20:53:24 +0000206 DebugInfoFinder DbgFinder;
207 DbgFinder.processModule(M);
208 if (DbgFinder.compile_unit_count() != 0) {
Devang Patel92c55112009-07-06 23:28:36 +0000209 // FIXME : What if more then one CUs are present in a module ?
Devang Patel22516662009-08-06 20:53:24 +0000210 GlobalVariable *CU = *DbgFinder.compile_unit_begin();
Sanjiv Guptabde79422009-06-16 09:45:18 +0000211 EmitDebugDirectives = true;
212 SwitchToCU(CU);
213 }
214
215 // Emit debug info for decls of composite types.
Sanjiv Guptadcb6da32009-06-13 17:35:54 +0000216 EmitCompositeTypeDecls(M);
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000217}
218
Sanjiv Guptabde79422009-06-16 09:45:18 +0000219/// Helper to find first valid debug loc for a function.
220///
221static const DebugLoc GetDebugLocForFunction(const MachineFunction &MF) {
222 DebugLoc DL;
223 for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
224 I != E; ++I) {
225 for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
226 II != E; ++II) {
227 DL = II->getDebugLoc();
228 if (!DL.isUnknown())
229 return DL;
230 }
231 }
232 return DL;
233}
234
235/// BeginFunction - Emit necessary debug info to start a function.
236///
237void PIC16DbgInfo::BeginFunction(const MachineFunction &MF) {
238 if (! EmitDebugDirectives) return;
239
240 // Retreive the first valid debug Loc and process it.
241 const DebugLoc &DL = GetDebugLocForFunction(MF);
Sanjiv Gupta394a1a22009-08-07 11:00:02 +0000242 // Emit debug info only if valid debug info is available.
243 if (!DL.isUnknown()) {
244 ChangeDebugLoc(MF, DL, true);
245 EmitFunctBeginDI(MF.getFunction());
246 }
Sanjiv Guptabde79422009-06-16 09:45:18 +0000247 // Set current line to 0 so that.line directive is genearted after .bf.
248 CurLine = 0;
249}
250
251/// ChangeDebugLoc - Take necessary steps when DebugLoc changes.
252/// CurFile and CurLine may change as a result of this.
253///
254void PIC16DbgInfo::ChangeDebugLoc(const MachineFunction &MF,
255 const DebugLoc &DL, bool IsInBeginFunction) {
256 if (! EmitDebugDirectives) return;
257 assert (! DL.isUnknown() && "can't change to invalid debug loc");
258
259 GlobalVariable *CU = MF.getDebugLocTuple(DL).CompileUnit;
260 unsigned line = MF.getDebugLocTuple(DL).Line;
261
262 SwitchToCU(CU);
263 SwitchToLine(line, IsInBeginFunction);
264}
265
266/// SwitchToLine - Emit line directive for a new line.
267///
268void PIC16DbgInfo::SwitchToLine(unsigned Line, bool IsInBeginFunction) {
269 if (CurLine == Line) return;
270 if (!IsInBeginFunction) O << "\n\t.line " << Line << "\n";
271 CurLine = Line;
272}
273
274/// EndFunction - Emit .ef for end of function.
275///
276void PIC16DbgInfo::EndFunction(const MachineFunction &MF) {
277 if (! EmitDebugDirectives) return;
Sanjiv Gupta394a1a22009-08-07 11:00:02 +0000278 const DebugLoc &DL = GetDebugLocForFunction(MF);
279 // Emit debug info only if valid debug info is available.
280 if (!DL.isUnknown())
281 EmitFunctEndDI(MF.getFunction(), CurLine);
Sanjiv Guptabde79422009-06-16 09:45:18 +0000282}
283
284/// EndModule - Emit .eof for end of module.
285///
286void PIC16DbgInfo::EndModule(Module &M) {
287 if (! EmitDebugDirectives) return;
288 EmitVarDebugInfo(M);
289 if (CurFile != "") O << "\n\t.eof";
290}
291
292/// EmitCompositeTypeElements - Emit debug information for members of a
293/// composite type.
294///
295void PIC16DbgInfo::EmitCompositeTypeElements (DICompositeType CTy,
Devang Patel715c6622009-08-10 22:11:20 +0000296 unsigned SuffixNo) {
Sanjiv Guptabde79422009-06-16 09:45:18 +0000297 unsigned long Value = 0;
298 DIArray Elements = CTy.getTypeArray();
299 for (unsigned i = 0, N = Elements.getNumElements(); i < N; i++) {
300 DIDescriptor Element = Elements.getElement(i);
301 unsigned short TypeNo = 0;
302 bool HasAux = false;
303 int ElementAux[PIC16Dbg::AuxSize] = { 0 };
304 std::string TagName = "";
305 std::string ElementName;
306 GlobalVariable *GV = Element.getGV();
307 DIDerivedType DITy(GV);
308 DITy.getName(ElementName);
309 unsigned short ElementSize = DITy.getSizeInBits()/8;
310 // Get mangleddd name for this structure/union element.
Devang Patel715c6622009-08-10 22:11:20 +0000311 SmallString<128> MangMemName(ElementName.begin(), ElementName.end());
312 MangMemName.append_uint_32(SuffixNo);
Sanjiv Guptabde79422009-06-16 09:45:18 +0000313 PopulateDebugInfo(DITy, TypeNo, HasAux, ElementAux, TagName);
Daniel Dunbar1c723b72009-06-26 02:03:52 +0000314 short Class = 0;
Sanjiv Guptabde79422009-06-16 09:45:18 +0000315 if( CTy.getTag() == dwarf::DW_TAG_union_type)
316 Class = PIC16Dbg::C_MOU;
317 else if (CTy.getTag() == dwarf::DW_TAG_structure_type)
318 Class = PIC16Dbg::C_MOS;
Devang Patel715c6622009-08-10 22:11:20 +0000319 EmitSymbol(MangMemName.c_str(), Class, TypeNo, Value);
Sanjiv Guptabde79422009-06-16 09:45:18 +0000320 if (CTy.getTag() == dwarf::DW_TAG_structure_type)
321 Value += ElementSize;
322 if (HasAux)
Devang Patel715c6622009-08-10 22:11:20 +0000323 EmitAuxEntry(MangMemName.c_str(), ElementAux, PIC16Dbg::AuxSize, TagName);
Sanjiv Guptabde79422009-06-16 09:45:18 +0000324 }
325}
326
327/// EmitCompositeTypeDecls - Emit composite type declarations like structure
328/// and union declarations.
329///
Sanjiv Guptadcb6da32009-06-13 17:35:54 +0000330void PIC16DbgInfo::EmitCompositeTypeDecls(Module &M) {
Devang Patel715c6622009-08-10 22:11:20 +0000331 DebugInfoFinder DbgFinder;
332 DbgFinder.processModule(M);
333 unsigned SuffixNo = 0;
334 for (DebugInfoFinder::iterator I = DbgFinder.global_variable_begin(),
335 E = DbgFinder.global_variable_end(); I != E; ++I) {
336 DICompositeType CTy(*I);
337 if (CTy.isNull())
338 continue;
339 if (CTy.getTag() == dwarf::DW_TAG_union_type ||
340 CTy.getTag() == dwarf::DW_TAG_structure_type ) {
341 std::string Name;
342 CTy.getName(Name);
343 SmallString<128> MangledCTyName(Name.begin(), Name.end());
344 MangledCTyName.append_uint_32(++SuffixNo);
345 unsigned short size = CTy.getSizeInBits()/8;
346 int Aux[PIC16Dbg::AuxSize] = {0};
347 // 7th and 8th byte represent size of structure/union.
348 Aux[6] = size & 0xff;
349 Aux[7] = size >> 8;
350 // Emit .def for structure/union tag.
351 if( CTy.getTag() == dwarf::DW_TAG_union_type)
352 EmitSymbol(MangledCTyName.c_str(), PIC16Dbg::C_UNTAG);
353 else if (CTy.getTag() == dwarf::DW_TAG_structure_type)
354 EmitSymbol(MangledCTyName.c_str(), PIC16Dbg::C_STRTAG);
355
356 // Emit auxiliary debug information for structure/union tag.
357 EmitAuxEntry(MangledCTyName.c_str(), Aux, PIC16Dbg::AuxSize);
358
359 // Emit members.
360 EmitCompositeTypeElements (CTy, SuffixNo);
361
362 // Emit mangled Symbol for end of structure/union.
363 SmallString<128> EOSSymbol(Name.begin(), Name.end());
364 EOSSymbol += ".eos";
365 EOSSymbol.append_uint_32(SuffixNo);
366 EmitSymbol(EOSSymbol.c_str(), PIC16Dbg::C_EOS);
367 EmitAuxEntry(EOSSymbol.c_str(), Aux, PIC16Dbg::AuxSize,
368 MangledCTyName.c_str());
Sanjiv Guptadcb6da32009-06-13 17:35:54 +0000369 }
370 }
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000371}
372
Devang Patel715c6622009-08-10 22:11:20 +0000373
Sanjiv Guptabde79422009-06-16 09:45:18 +0000374/// EmitFunctBeginDI - Emit .bf for function.
375///
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000376void PIC16DbgInfo::EmitFunctBeginDI(const Function *F) {
377 std::string FunctName = F->getName();
Sanjiv Guptadcb6da32009-06-13 17:35:54 +0000378 if (EmitDebugDirectives) {
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000379 std::string FunctBeginSym = ".bf." + FunctName;
380 std::string BlockBeginSym = ".bb." + FunctName;
381
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000382 int BFAux[PIC16Dbg::AuxSize] = {0};
Sanjiv Guptabde79422009-06-16 09:45:18 +0000383 BFAux[4] = CurLine;
384 BFAux[5] = CurLine >> 8;
385
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000386 // Emit debug directives for beginning of function.
387 EmitSymbol(FunctBeginSym, PIC16Dbg::C_FCN);
388 EmitAuxEntry(FunctBeginSym, BFAux, PIC16Dbg::AuxSize);
Sanjiv Guptabde79422009-06-16 09:45:18 +0000389
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000390 EmitSymbol(BlockBeginSym, PIC16Dbg::C_BLOCK);
391 EmitAuxEntry(BlockBeginSym, BFAux, PIC16Dbg::AuxSize);
392 }
393}
394
Sanjiv Guptabde79422009-06-16 09:45:18 +0000395/// EmitFunctEndDI - Emit .ef for function end.
396///
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000397void PIC16DbgInfo::EmitFunctEndDI(const Function *F, unsigned Line) {
398 std::string FunctName = F->getName();
Sanjiv Guptadcb6da32009-06-13 17:35:54 +0000399 if (EmitDebugDirectives) {
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000400 std::string FunctEndSym = ".ef." + FunctName;
401 std::string BlockEndSym = ".eb." + FunctName;
402
403 // Emit debug directives for end of function.
404 EmitSymbol(BlockEndSym, PIC16Dbg::C_BLOCK);
405 int EFAux[PIC16Dbg::AuxSize] = {0};
406 // 5th and 6th byte stand for line number.
Sanjiv Guptabde79422009-06-16 09:45:18 +0000407 EFAux[4] = CurLine;
408 EFAux[5] = CurLine >> 8;
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000409 EmitAuxEntry(BlockEndSym, EFAux, PIC16Dbg::AuxSize);
410 EmitSymbol(FunctEndSym, PIC16Dbg::C_FCN);
411 EmitAuxEntry(FunctEndSym, EFAux, PIC16Dbg::AuxSize);
412 }
413}
414
415/// EmitAuxEntry - Emit Auxiliary debug information.
416///
Sanjiv Guptabde79422009-06-16 09:45:18 +0000417void PIC16DbgInfo::EmitAuxEntry(const std::string VarName, int Aux[], int Num,
418 std::string TagName) {
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000419 O << "\n\t.dim " << VarName << ", 1" ;
Sanjiv Guptabde79422009-06-16 09:45:18 +0000420 // TagName is emitted in case of structure/union objects.
421 if (TagName != "")
422 O << ", " << TagName;
423 for (int i = 0; i<Num; i++)
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000424 O << "," << Aux[i];
425}
426
Sanjiv Guptabde79422009-06-16 09:45:18 +0000427/// EmitSymbol - Emit .def for a symbol. Value is offset for the member.
428///
Sanjiv Guptadcb6da32009-06-13 17:35:54 +0000429void PIC16DbgInfo::EmitSymbol(std::string Name, short Class, unsigned short
430 Type, unsigned long Value) {
431 O << "\n\t" << ".def "<< Name << ", type = " << Type << ", class = "
432 << Class;
433 if (Value > 0)
434 O << ", value = " << Value;
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000435}
436
Sanjiv Guptabde79422009-06-16 09:45:18 +0000437/// EmitVarDebugInfo - Emit debug information for all variables.
438///
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000439void PIC16DbgInfo::EmitVarDebugInfo(Module &M) {
Devang Patel22516662009-08-06 20:53:24 +0000440 DebugInfoFinder DbgFinder;
441 DbgFinder.processModule(M);
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000442
Devang Patel22516662009-08-06 20:53:24 +0000443 for (DebugInfoFinder::iterator I = DbgFinder.global_variable_begin(),
444 E = DbgFinder.global_variable_end(); I != E; ++I) {
Devang Patel92c55112009-07-06 23:28:36 +0000445 DIGlobalVariable DIGV(*I);
446 DIType Ty = DIGV.getType();
447 unsigned short TypeNo = 0;
448 bool HasAux = false;
449 int Aux[PIC16Dbg::AuxSize] = { 0 };
450 std::string TagName = "";
Daniel Dunbarf6ccee52009-07-24 08:24:36 +0000451 std::string VarName = TAI->getGlobalPrefix()+DIGV.getGlobal()->getNameStr();
Devang Patel92c55112009-07-06 23:28:36 +0000452 PopulateDebugInfo(Ty, TypeNo, HasAux, Aux, TagName);
453 // Emit debug info only if type information is availaible.
454 if (TypeNo != PIC16Dbg::T_NULL) {
455 O << "\n\t.type " << VarName << ", " << TypeNo;
456 short ClassNo = getStorageClass(DIGV);
457 O << "\n\t.class " << VarName << ", " << ClassNo;
458 if (HasAux)
459 EmitAuxEntry(VarName, Aux, PIC16Dbg::AuxSize, TagName);
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000460 }
461 }
462 O << "\n";
463}
464
Sanjiv Guptabde79422009-06-16 09:45:18 +0000465/// SwitchToCU - Switch to a new compilation unit.
466///
467void PIC16DbgInfo::SwitchToCU(GlobalVariable *CU) {
468 // Get the file path from CU.
469 DICompileUnit cu(CU);
470 std::string DirName, FileName;
471 std::string FilePath = cu.getDirectory(DirName) + "/" +
472 cu.getFilename(FileName);
473
474 // Nothing to do if source file is still same.
475 if ( FilePath == CurFile ) return;
476
477 // Else, close the current one and start a new.
478 if (CurFile != "") O << "\n\t.eof";
479 O << "\n\t.file\t\"" << FilePath << "\"\n" ;
480 CurFile = FilePath;
481 CurLine = 0;
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000482}
Sanjiv Gupta3fc7e532009-06-03 16:27:49 +0000483
Sanjiv Guptabde79422009-06-16 09:45:18 +0000484/// EmitEOF - Emit .eof for end of file.
485///
Sanjiv Gupta3fc7e532009-06-03 16:27:49 +0000486void PIC16DbgInfo::EmitEOF() {
487 if (CurFile != "")
488 O << "\n\t.EOF";
489}
490