blob: 460be5899272f5c54649951ba488e7e72e145992 [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
Sanjiv Guptabfa79b82009-08-15 14:36:48 +0000122 // llvm.dbg.composite* global variable. Since we need to revisit
123 // PIC16DebugInfo implementation anyways after the MDNodes based
124 // framework is done, let us continue with the way it is.
Daniel Dunbarf6ccee52009-07-24 08:24:36 +0000125 std::string UniqueSuffix = "." + Ty.getGV()->getNameStr().substr(18);
Sanjiv Guptabde79422009-06-16 09:45:18 +0000126 TagName += UniqueSuffix;
127 unsigned short size = CTy.getSizeInBits()/8;
128 // 7th and 8th byte represent size.
129 HasAux = true;
130 Aux[6] = size & 0xff;
131 Aux[7] = size >> 8;
132}
133
134/// PopulateEnumTypeInfo - Populate TypeNo for enum from Ty.
135void PIC16DbgInfo::PopulateEnumTypeInfo (DIType Ty, unsigned short &TypeNo) {
136 TypeNo = TypeNo << PIC16Dbg::S_BASIC;
137 TypeNo = TypeNo | PIC16Dbg::T_ENUM;
138}
139
140/// PopulateCompositeTypeInfo - Populate TypeNo, Aux[] and TagName for
141/// composite types from Ty.
142///
143void PIC16DbgInfo::PopulateCompositeTypeInfo (DIType Ty, unsigned short &TypeNo,
144 bool &HasAux, int Aux[],
145 std::string &TagName) {
146 switch (Ty.getTag()) {
147 case dwarf::DW_TAG_array_type: {
148 PopulateArrayTypeInfo (Ty, TypeNo, HasAux, Aux, TagName);
149 break;
150 }
151 case dwarf:: DW_TAG_union_type:
152 case dwarf::DW_TAG_structure_type: {
153 PopulateStructOrUnionTypeInfo (Ty, TypeNo, HasAux, Aux, TagName);
154 break;
155 }
156 case dwarf::DW_TAG_enumeration_type: {
157 PopulateEnumTypeInfo (Ty, TypeNo);
158 break;
159 }
160 default:
161 TypeNo = TypeNo << PIC16Dbg::S_DERIVED;
162 }
163}
164
165/// GetTypeDebugNumber - Get debug type number for given type.
166///
Sanjiv Guptaa57bc3b2009-05-22 13:58:45 +0000167unsigned PIC16DbgInfo::GetTypeDebugNumber(std::string &type) {
168 if (type == "char")
169 return PIC16Dbg::T_CHAR;
170 else if (type == "short")
171 return PIC16Dbg::T_SHORT;
172 else if (type == "int")
173 return PIC16Dbg::T_INT;
174 else if (type == "long")
175 return PIC16Dbg::T_LONG;
176 else if (type == "unsigned char")
177 return PIC16Dbg::T_UCHAR;
178 else if (type == "unsigned short")
179 return PIC16Dbg::T_USHORT;
180 else if (type == "unsigned int")
181 return PIC16Dbg::T_UINT;
182 else if (type == "unsigned long")
183 return PIC16Dbg::T_ULONG;
184 else
185 return 0;
186}
Sanjiv Guptabde79422009-06-16 09:45:18 +0000187
188/// GetStorageClass - Get storage class for give debug variable.
189///
190short PIC16DbgInfo::getStorageClass(DIGlobalVariable DIGV) {
Sanjiv Guptaa57bc3b2009-05-22 13:58:45 +0000191 short ClassNo;
192 if (PAN::isLocalName(DIGV.getGlobal()->getName())) {
193 // Generating C_AUTO here fails due to error in linker. Change it once
194 // linker is fixed.
195 ClassNo = PIC16Dbg::C_STAT;
196 }
197 else if (DIGV.isLocalToUnit())
198 ClassNo = PIC16Dbg::C_STAT;
199 else
200 ClassNo = PIC16Dbg::C_EXT;
201 return ClassNo;
202}
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000203
Sanjiv Guptabde79422009-06-16 09:45:18 +0000204/// BeginModule - Emit necessary debug info to start a Module and do other
205/// required initializations.
206void PIC16DbgInfo::BeginModule(Module &M) {
207 // Emit file directive for module.
Devang Patel22516662009-08-06 20:53:24 +0000208 DebugInfoFinder DbgFinder;
209 DbgFinder.processModule(M);
210 if (DbgFinder.compile_unit_count() != 0) {
Devang Patel92c55112009-07-06 23:28:36 +0000211 // FIXME : What if more then one CUs are present in a module ?
Devang Patel22516662009-08-06 20:53:24 +0000212 GlobalVariable *CU = *DbgFinder.compile_unit_begin();
Sanjiv Guptabde79422009-06-16 09:45:18 +0000213 EmitDebugDirectives = true;
214 SwitchToCU(CU);
215 }
216
217 // Emit debug info for decls of composite types.
Sanjiv Guptadcb6da32009-06-13 17:35:54 +0000218 EmitCompositeTypeDecls(M);
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000219}
220
Sanjiv Guptabde79422009-06-16 09:45:18 +0000221/// Helper to find first valid debug loc for a function.
222///
223static const DebugLoc GetDebugLocForFunction(const MachineFunction &MF) {
224 DebugLoc DL;
225 for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
226 I != E; ++I) {
227 for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
228 II != E; ++II) {
229 DL = II->getDebugLoc();
230 if (!DL.isUnknown())
231 return DL;
232 }
233 }
234 return DL;
235}
236
237/// BeginFunction - Emit necessary debug info to start a function.
238///
239void PIC16DbgInfo::BeginFunction(const MachineFunction &MF) {
240 if (! EmitDebugDirectives) return;
241
242 // Retreive the first valid debug Loc and process it.
243 const DebugLoc &DL = GetDebugLocForFunction(MF);
Sanjiv Gupta394a1a22009-08-07 11:00:02 +0000244 // Emit debug info only if valid debug info is available.
245 if (!DL.isUnknown()) {
246 ChangeDebugLoc(MF, DL, true);
247 EmitFunctBeginDI(MF.getFunction());
248 }
Sanjiv Guptabde79422009-06-16 09:45:18 +0000249 // Set current line to 0 so that.line directive is genearted after .bf.
250 CurLine = 0;
251}
252
253/// ChangeDebugLoc - Take necessary steps when DebugLoc changes.
254/// CurFile and CurLine may change as a result of this.
255///
256void PIC16DbgInfo::ChangeDebugLoc(const MachineFunction &MF,
257 const DebugLoc &DL, bool IsInBeginFunction) {
258 if (! EmitDebugDirectives) return;
259 assert (! DL.isUnknown() && "can't change to invalid debug loc");
260
261 GlobalVariable *CU = MF.getDebugLocTuple(DL).CompileUnit;
262 unsigned line = MF.getDebugLocTuple(DL).Line;
263
264 SwitchToCU(CU);
265 SwitchToLine(line, IsInBeginFunction);
266}
267
268/// SwitchToLine - Emit line directive for a new line.
269///
270void PIC16DbgInfo::SwitchToLine(unsigned Line, bool IsInBeginFunction) {
271 if (CurLine == Line) return;
272 if (!IsInBeginFunction) O << "\n\t.line " << Line << "\n";
273 CurLine = Line;
274}
275
276/// EndFunction - Emit .ef for end of function.
277///
278void PIC16DbgInfo::EndFunction(const MachineFunction &MF) {
279 if (! EmitDebugDirectives) return;
Sanjiv Gupta394a1a22009-08-07 11:00:02 +0000280 const DebugLoc &DL = GetDebugLocForFunction(MF);
281 // Emit debug info only if valid debug info is available.
282 if (!DL.isUnknown())
283 EmitFunctEndDI(MF.getFunction(), CurLine);
Sanjiv Guptabde79422009-06-16 09:45:18 +0000284}
285
286/// EndModule - Emit .eof for end of module.
287///
288void PIC16DbgInfo::EndModule(Module &M) {
289 if (! EmitDebugDirectives) return;
290 EmitVarDebugInfo(M);
291 if (CurFile != "") O << "\n\t.eof";
292}
293
294/// EmitCompositeTypeElements - Emit debug information for members of a
295/// composite type.
296///
297void PIC16DbgInfo::EmitCompositeTypeElements (DICompositeType CTy,
Sanjiv Guptabfa79b82009-08-15 14:36:48 +0000298 std::string SuffixNo) {
Sanjiv Guptabde79422009-06-16 09:45:18 +0000299 unsigned long Value = 0;
300 DIArray Elements = CTy.getTypeArray();
301 for (unsigned i = 0, N = Elements.getNumElements(); i < N; i++) {
302 DIDescriptor Element = Elements.getElement(i);
303 unsigned short TypeNo = 0;
304 bool HasAux = false;
305 int ElementAux[PIC16Dbg::AuxSize] = { 0 };
306 std::string TagName = "";
307 std::string ElementName;
308 GlobalVariable *GV = Element.getGV();
309 DIDerivedType DITy(GV);
310 DITy.getName(ElementName);
311 unsigned short ElementSize = DITy.getSizeInBits()/8;
312 // Get mangleddd name for this structure/union element.
Sanjiv Guptabfa79b82009-08-15 14:36:48 +0000313 std::string MangMemName = ElementName + SuffixNo;
Sanjiv Guptabde79422009-06-16 09:45:18 +0000314 PopulateDebugInfo(DITy, TypeNo, HasAux, ElementAux, TagName);
Daniel Dunbar1c723b72009-06-26 02:03:52 +0000315 short Class = 0;
Sanjiv Guptabde79422009-06-16 09:45:18 +0000316 if( CTy.getTag() == dwarf::DW_TAG_union_type)
317 Class = PIC16Dbg::C_MOU;
318 else if (CTy.getTag() == dwarf::DW_TAG_structure_type)
319 Class = PIC16Dbg::C_MOS;
Devang Patel715c6622009-08-10 22:11:20 +0000320 EmitSymbol(MangMemName.c_str(), Class, TypeNo, Value);
Sanjiv Guptabde79422009-06-16 09:45:18 +0000321 if (CTy.getTag() == dwarf::DW_TAG_structure_type)
322 Value += ElementSize;
323 if (HasAux)
Devang Patel715c6622009-08-10 22:11:20 +0000324 EmitAuxEntry(MangMemName.c_str(), ElementAux, PIC16Dbg::AuxSize, TagName);
Sanjiv Guptabde79422009-06-16 09:45:18 +0000325 }
326}
327
328/// EmitCompositeTypeDecls - Emit composite type declarations like structure
329/// and union declarations.
330///
Sanjiv Guptadcb6da32009-06-13 17:35:54 +0000331void PIC16DbgInfo::EmitCompositeTypeDecls(Module &M) {
Devang Patel715c6622009-08-10 22:11:20 +0000332 DebugInfoFinder DbgFinder;
333 DbgFinder.processModule(M);
Sanjiv Guptabfa79b82009-08-15 14:36:48 +0000334 for (DebugInfoFinder::iterator I = DbgFinder.type_begin(),
335 E = DbgFinder.type_end(); I != E; ++I) {
Devang Patel715c6622009-08-10 22:11:20 +0000336 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);
Sanjiv Guptabfa79b82009-08-15 14:36:48 +0000343 // Get the number after llvm.dbg.composite and make UniqueSuffix from
344 // it.
345 std::string DIVar = CTy.getGV()->getNameStr();
346 std::string UniqueSuffix = "." + DIVar.substr(18);
347 std::string MangledCTyName = Name + UniqueSuffix;
Devang Patel715c6622009-08-10 22:11:20 +0000348 unsigned short size = CTy.getSizeInBits()/8;
349 int Aux[PIC16Dbg::AuxSize] = {0};
350 // 7th and 8th byte represent size of structure/union.
351 Aux[6] = size & 0xff;
352 Aux[7] = size >> 8;
353 // Emit .def for structure/union tag.
354 if( CTy.getTag() == dwarf::DW_TAG_union_type)
355 EmitSymbol(MangledCTyName.c_str(), PIC16Dbg::C_UNTAG);
356 else if (CTy.getTag() == dwarf::DW_TAG_structure_type)
357 EmitSymbol(MangledCTyName.c_str(), PIC16Dbg::C_STRTAG);
358
359 // Emit auxiliary debug information for structure/union tag.
360 EmitAuxEntry(MangledCTyName.c_str(), Aux, PIC16Dbg::AuxSize);
361
362 // Emit members.
Sanjiv Guptabfa79b82009-08-15 14:36:48 +0000363 EmitCompositeTypeElements (CTy, UniqueSuffix);
Devang Patel715c6622009-08-10 22:11:20 +0000364
365 // Emit mangled Symbol for end of structure/union.
Sanjiv Guptabfa79b82009-08-15 14:36:48 +0000366 std::string EOSSymbol = ".eos" + UniqueSuffix;
Devang Patel715c6622009-08-10 22:11:20 +0000367 EmitSymbol(EOSSymbol.c_str(), PIC16Dbg::C_EOS);
368 EmitAuxEntry(EOSSymbol.c_str(), Aux, PIC16Dbg::AuxSize,
369 MangledCTyName.c_str());
Sanjiv Guptadcb6da32009-06-13 17:35:54 +0000370 }
371 }
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000372}
373
Devang Patel715c6622009-08-10 22:11:20 +0000374
Sanjiv Guptabde79422009-06-16 09:45:18 +0000375/// EmitFunctBeginDI - Emit .bf for function.
376///
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000377void PIC16DbgInfo::EmitFunctBeginDI(const Function *F) {
378 std::string FunctName = F->getName();
Sanjiv Guptadcb6da32009-06-13 17:35:54 +0000379 if (EmitDebugDirectives) {
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000380 std::string FunctBeginSym = ".bf." + FunctName;
381 std::string BlockBeginSym = ".bb." + FunctName;
382
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000383 int BFAux[PIC16Dbg::AuxSize] = {0};
Sanjiv Guptabde79422009-06-16 09:45:18 +0000384 BFAux[4] = CurLine;
385 BFAux[5] = CurLine >> 8;
386
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000387 // Emit debug directives for beginning of function.
388 EmitSymbol(FunctBeginSym, PIC16Dbg::C_FCN);
389 EmitAuxEntry(FunctBeginSym, BFAux, PIC16Dbg::AuxSize);
Sanjiv Guptabde79422009-06-16 09:45:18 +0000390
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000391 EmitSymbol(BlockBeginSym, PIC16Dbg::C_BLOCK);
392 EmitAuxEntry(BlockBeginSym, BFAux, PIC16Dbg::AuxSize);
393 }
394}
395
Sanjiv Guptabde79422009-06-16 09:45:18 +0000396/// EmitFunctEndDI - Emit .ef for function end.
397///
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000398void PIC16DbgInfo::EmitFunctEndDI(const Function *F, unsigned Line) {
399 std::string FunctName = F->getName();
Sanjiv Guptadcb6da32009-06-13 17:35:54 +0000400 if (EmitDebugDirectives) {
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000401 std::string FunctEndSym = ".ef." + FunctName;
402 std::string BlockEndSym = ".eb." + FunctName;
403
404 // Emit debug directives for end of function.
405 EmitSymbol(BlockEndSym, PIC16Dbg::C_BLOCK);
406 int EFAux[PIC16Dbg::AuxSize] = {0};
407 // 5th and 6th byte stand for line number.
Sanjiv Guptabde79422009-06-16 09:45:18 +0000408 EFAux[4] = CurLine;
409 EFAux[5] = CurLine >> 8;
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000410 EmitAuxEntry(BlockEndSym, EFAux, PIC16Dbg::AuxSize);
411 EmitSymbol(FunctEndSym, PIC16Dbg::C_FCN);
412 EmitAuxEntry(FunctEndSym, EFAux, PIC16Dbg::AuxSize);
413 }
414}
415
416/// EmitAuxEntry - Emit Auxiliary debug information.
417///
Sanjiv Guptabde79422009-06-16 09:45:18 +0000418void PIC16DbgInfo::EmitAuxEntry(const std::string VarName, int Aux[], int Num,
419 std::string TagName) {
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000420 O << "\n\t.dim " << VarName << ", 1" ;
Sanjiv Guptabde79422009-06-16 09:45:18 +0000421 // TagName is emitted in case of structure/union objects.
422 if (TagName != "")
423 O << ", " << TagName;
424 for (int i = 0; i<Num; i++)
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000425 O << "," << Aux[i];
426}
427
Sanjiv Guptabde79422009-06-16 09:45:18 +0000428/// EmitSymbol - Emit .def for a symbol. Value is offset for the member.
429///
Sanjiv Guptadcb6da32009-06-13 17:35:54 +0000430void PIC16DbgInfo::EmitSymbol(std::string Name, short Class, unsigned short
431 Type, unsigned long Value) {
432 O << "\n\t" << ".def "<< Name << ", type = " << Type << ", class = "
433 << Class;
434 if (Value > 0)
435 O << ", value = " << Value;
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000436}
437
Sanjiv Guptabde79422009-06-16 09:45:18 +0000438/// EmitVarDebugInfo - Emit debug information for all variables.
439///
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000440void PIC16DbgInfo::EmitVarDebugInfo(Module &M) {
Devang Patel22516662009-08-06 20:53:24 +0000441 DebugInfoFinder DbgFinder;
442 DbgFinder.processModule(M);
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000443
Devang Patel22516662009-08-06 20:53:24 +0000444 for (DebugInfoFinder::iterator I = DbgFinder.global_variable_begin(),
445 E = DbgFinder.global_variable_end(); I != E; ++I) {
Devang Patel92c55112009-07-06 23:28:36 +0000446 DIGlobalVariable DIGV(*I);
447 DIType Ty = DIGV.getType();
448 unsigned short TypeNo = 0;
449 bool HasAux = false;
450 int Aux[PIC16Dbg::AuxSize] = { 0 };
451 std::string TagName = "";
Daniel Dunbarf6ccee52009-07-24 08:24:36 +0000452 std::string VarName = TAI->getGlobalPrefix()+DIGV.getGlobal()->getNameStr();
Devang Patel92c55112009-07-06 23:28:36 +0000453 PopulateDebugInfo(Ty, TypeNo, HasAux, Aux, TagName);
454 // Emit debug info only if type information is availaible.
455 if (TypeNo != PIC16Dbg::T_NULL) {
456 O << "\n\t.type " << VarName << ", " << TypeNo;
457 short ClassNo = getStorageClass(DIGV);
458 O << "\n\t.class " << VarName << ", " << ClassNo;
459 if (HasAux)
460 EmitAuxEntry(VarName, Aux, PIC16Dbg::AuxSize, TagName);
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000461 }
462 }
463 O << "\n";
464}
465
Sanjiv Guptabde79422009-06-16 09:45:18 +0000466/// SwitchToCU - Switch to a new compilation unit.
467///
468void PIC16DbgInfo::SwitchToCU(GlobalVariable *CU) {
469 // Get the file path from CU.
470 DICompileUnit cu(CU);
471 std::string DirName, FileName;
472 std::string FilePath = cu.getDirectory(DirName) + "/" +
473 cu.getFilename(FileName);
474
475 // Nothing to do if source file is still same.
476 if ( FilePath == CurFile ) return;
477
478 // Else, close the current one and start a new.
479 if (CurFile != "") O << "\n\t.eof";
480 O << "\n\t.file\t\"" << FilePath << "\"\n" ;
481 CurFile = FilePath;
482 CurLine = 0;
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000483}
Sanjiv Gupta3fc7e532009-06-03 16:27:49 +0000484
Sanjiv Guptabde79422009-06-16 09:45:18 +0000485/// EmitEOF - Emit .eof for end of file.
486///
Sanjiv Gupta3fc7e532009-06-03 16:27:49 +0000487void PIC16DbgInfo::EmitEOF() {
488 if (CurFile != "")
489 O << "\n\t.EOF";
490}
491