blob: 75c9556340ce679acde35abc558a783272e6ab2a [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"
Chris Lattnere4d110b2009-08-22 20:56:12 +000018#include "llvm/MC/MCAsmInfo.h"
Devang Patel1e86a662009-06-19 22:08:58 +000019#include "llvm/Support/DebugLoc.h"
David Greene71847812009-07-14 20:18:05 +000020#include "llvm/Support/FormattedStream.h"
Devang Patel715c6622009-08-10 22:11:20 +000021#include "llvm/ADT/SmallString.h"
Sanjiv Guptaa57bc3b2009-05-22 13:58:45 +000022
23using namespace llvm;
24
Sanjiv Guptabde79422009-06-16 09:45:18 +000025/// PopulateDebugInfo - Populate the TypeNo, Aux[] and TagName from Ty.
26///
27void PIC16DbgInfo::PopulateDebugInfo (DIType Ty, unsigned short &TypeNo,
28 bool &HasAux, int Aux[],
29 std::string &TagName) {
30 if (Ty.isBasicType(Ty.getTag()))
31 PopulateBasicTypeInfo (Ty, TypeNo);
32 else if (Ty.isDerivedType(Ty.getTag()))
33 PopulateDerivedTypeInfo (Ty, TypeNo, HasAux, Aux, TagName);
34 else if (Ty.isCompositeType(Ty.getTag()))
35 PopulateCompositeTypeInfo (Ty, TypeNo, HasAux, Aux, TagName);
Sanjiv Guptaa57bc3b2009-05-22 13:58:45 +000036 else {
37 TypeNo = PIC16Dbg::T_NULL;
38 HasAux = false;
39 }
40 return;
41}
42
Sanjiv Guptabde79422009-06-16 09:45:18 +000043/// PopulateBasicTypeInfo- Populate TypeNo for basic type from Ty.
44///
45void PIC16DbgInfo::PopulateBasicTypeInfo (DIType Ty, unsigned short &TypeNo) {
46 std::string Name = "";
47 Ty.getName(Name);
48 unsigned short BaseTy = GetTypeDebugNumber(Name);
49 TypeNo = TypeNo << PIC16Dbg::S_BASIC;
50 TypeNo = TypeNo | (0xffff & BaseTy);
51}
Sanjiv Guptaa57bc3b2009-05-22 13:58:45 +000052
Sanjiv Guptabde79422009-06-16 09:45:18 +000053/// PopulateDerivedTypeInfo - Populate TypeNo, Aux[], TagName for derived type
54/// from Ty. Derived types are mostly pointers.
55///
56void PIC16DbgInfo::PopulateDerivedTypeInfo (DIType Ty, unsigned short &TypeNo,
57 bool &HasAux, int Aux[],
58 std::string &TagName) {
59
60 switch(Ty.getTag())
61 {
62 case dwarf::DW_TAG_pointer_type:
63 TypeNo = TypeNo << PIC16Dbg::S_DERIVED;
64 TypeNo = TypeNo | PIC16Dbg::DT_PTR;
65 break;
66 default:
67 TypeNo = TypeNo << PIC16Dbg::S_DERIVED;
68 }
69
70 // We also need to encode the the information about the base type of
71 // pointer in TypeNo.
72 DIType BaseType = DIDerivedType(Ty.getGV()).getTypeDerivedFrom();
73 PopulateDebugInfo(BaseType, TypeNo, HasAux, Aux, TagName);
74}
75
76/// PopulateArrayTypeInfo - Populate TypeNo, Aux[] for array from Ty.
77void PIC16DbgInfo::PopulateArrayTypeInfo (DIType Ty, unsigned short &TypeNo,
78 bool &HasAux, int Aux[],
79 std::string &TagName) {
80
81 DICompositeType CTy = DICompositeType(Ty.getGV());
82 DIArray Elements = CTy.getTypeArray();
83 unsigned short size = 1;
84 unsigned short Dimension[4]={0,0,0,0};
85 for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
86 DIDescriptor Element = Elements.getElement(i);
87 if (Element.getTag() == dwarf::DW_TAG_subrange_type) {
88 TypeNo = TypeNo << PIC16Dbg::S_DERIVED;
89 TypeNo = TypeNo | PIC16Dbg::DT_ARY;
90 DISubrange SubRange = DISubrange(Element.getGV());
91 Dimension[i] = SubRange.getHi() - SubRange.getLo() + 1;
92 // Each dimension is represented by 2 bytes starting at byte 9.
93 Aux[8+i*2+0] = Dimension[i];
94 Aux[8+i*2+1] = Dimension[i] >> 8;
95 size = size * Dimension[i];
96 }
97 }
98 HasAux = true;
99 // In auxillary entry for array, 7th and 8th byte represent array size.
100 Aux[6] = size & 0xff;
101 Aux[7] = size >> 8;
102 DIType BaseType = CTy.getTypeDerivedFrom();
103 PopulateDebugInfo(BaseType, TypeNo, HasAux, Aux, TagName);
104}
105
106/// PopulateStructOrUnionTypeInfo - Populate TypeNo, Aux[] , TagName for
107/// structure or union.
108///
109void PIC16DbgInfo::PopulateStructOrUnionTypeInfo (DIType Ty,
110 unsigned short &TypeNo,
111 bool &HasAux, int Aux[],
112 std::string &TagName) {
113 DICompositeType CTy = DICompositeType(Ty.getGV());
114 TypeNo = TypeNo << PIC16Dbg::S_BASIC;
115 if (Ty.getTag() == dwarf::DW_TAG_structure_type)
116 TypeNo = TypeNo | PIC16Dbg::T_STRUCT;
117 else
118 TypeNo = TypeNo | PIC16Dbg::T_UNION;
119 CTy.getName(TagName);
120 // UniqueSuffix is .number where number is obtained from
121 // llvm.dbg.composite<number>.
Devang Patel715c6622009-08-10 22:11:20 +0000122 // FIXME: This will break when composite type is not represented by
Sanjiv Guptabfa79b82009-08-15 14:36:48 +0000123 // llvm.dbg.composite* global variable. Since we need to revisit
124 // PIC16DebugInfo implementation anyways after the MDNodes based
125 // framework is done, let us continue with the way it is.
Daniel Dunbarf6ccee52009-07-24 08:24:36 +0000126 std::string UniqueSuffix = "." + Ty.getGV()->getNameStr().substr(18);
Sanjiv Guptabde79422009-06-16 09:45:18 +0000127 TagName += UniqueSuffix;
128 unsigned short size = CTy.getSizeInBits()/8;
129 // 7th and 8th byte represent size.
130 HasAux = true;
131 Aux[6] = size & 0xff;
132 Aux[7] = size >> 8;
133}
134
135/// PopulateEnumTypeInfo - Populate TypeNo for enum from Ty.
136void PIC16DbgInfo::PopulateEnumTypeInfo (DIType Ty, unsigned short &TypeNo) {
137 TypeNo = TypeNo << PIC16Dbg::S_BASIC;
138 TypeNo = TypeNo | PIC16Dbg::T_ENUM;
139}
140
141/// PopulateCompositeTypeInfo - Populate TypeNo, Aux[] and TagName for
142/// composite types from Ty.
143///
144void PIC16DbgInfo::PopulateCompositeTypeInfo (DIType Ty, unsigned short &TypeNo,
145 bool &HasAux, int Aux[],
146 std::string &TagName) {
147 switch (Ty.getTag()) {
148 case dwarf::DW_TAG_array_type: {
149 PopulateArrayTypeInfo (Ty, TypeNo, HasAux, Aux, TagName);
150 break;
151 }
152 case dwarf:: DW_TAG_union_type:
153 case dwarf::DW_TAG_structure_type: {
154 PopulateStructOrUnionTypeInfo (Ty, TypeNo, HasAux, Aux, TagName);
155 break;
156 }
157 case dwarf::DW_TAG_enumeration_type: {
158 PopulateEnumTypeInfo (Ty, TypeNo);
159 break;
160 }
161 default:
162 TypeNo = TypeNo << PIC16Dbg::S_DERIVED;
163 }
164}
165
166/// GetTypeDebugNumber - Get debug type number for given type.
167///
Sanjiv Guptaa57bc3b2009-05-22 13:58:45 +0000168unsigned PIC16DbgInfo::GetTypeDebugNumber(std::string &type) {
169 if (type == "char")
170 return PIC16Dbg::T_CHAR;
171 else if (type == "short")
172 return PIC16Dbg::T_SHORT;
173 else if (type == "int")
174 return PIC16Dbg::T_INT;
175 else if (type == "long")
176 return PIC16Dbg::T_LONG;
177 else if (type == "unsigned char")
178 return PIC16Dbg::T_UCHAR;
179 else if (type == "unsigned short")
180 return PIC16Dbg::T_USHORT;
181 else if (type == "unsigned int")
182 return PIC16Dbg::T_UINT;
183 else if (type == "unsigned long")
184 return PIC16Dbg::T_ULONG;
185 else
186 return 0;
187}
Sanjiv Guptabde79422009-06-16 09:45:18 +0000188
189/// GetStorageClass - Get storage class for give debug variable.
190///
191short PIC16DbgInfo::getStorageClass(DIGlobalVariable DIGV) {
Sanjiv Guptaa57bc3b2009-05-22 13:58:45 +0000192 short ClassNo;
193 if (PAN::isLocalName(DIGV.getGlobal()->getName())) {
194 // Generating C_AUTO here fails due to error in linker. Change it once
195 // linker is fixed.
196 ClassNo = PIC16Dbg::C_STAT;
197 }
198 else if (DIGV.isLocalToUnit())
199 ClassNo = PIC16Dbg::C_STAT;
200 else
201 ClassNo = PIC16Dbg::C_EXT;
202 return ClassNo;
203}
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000204
Sanjiv Guptabde79422009-06-16 09:45:18 +0000205/// BeginModule - Emit necessary debug info to start a Module and do other
206/// required initializations.
207void PIC16DbgInfo::BeginModule(Module &M) {
208 // Emit file directive for module.
Devang Patel22516662009-08-06 20:53:24 +0000209 DebugInfoFinder DbgFinder;
210 DbgFinder.processModule(M);
211 if (DbgFinder.compile_unit_count() != 0) {
Devang Patel92c55112009-07-06 23:28:36 +0000212 // FIXME : What if more then one CUs are present in a module ?
Devang Patel22516662009-08-06 20:53:24 +0000213 GlobalVariable *CU = *DbgFinder.compile_unit_begin();
Sanjiv Guptabde79422009-06-16 09:45:18 +0000214 EmitDebugDirectives = true;
215 SwitchToCU(CU);
216 }
217
218 // Emit debug info for decls of composite types.
Sanjiv Guptadcb6da32009-06-13 17:35:54 +0000219 EmitCompositeTypeDecls(M);
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000220}
221
Sanjiv Guptabde79422009-06-16 09:45:18 +0000222/// Helper to find first valid debug loc for a function.
223///
224static const DebugLoc GetDebugLocForFunction(const MachineFunction &MF) {
225 DebugLoc DL;
226 for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
227 I != E; ++I) {
228 for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
229 II != E; ++II) {
230 DL = II->getDebugLoc();
231 if (!DL.isUnknown())
232 return DL;
233 }
234 }
235 return DL;
236}
237
238/// BeginFunction - Emit necessary debug info to start a function.
239///
240void PIC16DbgInfo::BeginFunction(const MachineFunction &MF) {
241 if (! EmitDebugDirectives) return;
242
243 // Retreive the first valid debug Loc and process it.
244 const DebugLoc &DL = GetDebugLocForFunction(MF);
Sanjiv Gupta394a1a22009-08-07 11:00:02 +0000245 // Emit debug info only if valid debug info is available.
246 if (!DL.isUnknown()) {
247 ChangeDebugLoc(MF, DL, true);
248 EmitFunctBeginDI(MF.getFunction());
249 }
Sanjiv Guptabde79422009-06-16 09:45:18 +0000250 // Set current line to 0 so that.line directive is genearted after .bf.
251 CurLine = 0;
252}
253
254/// ChangeDebugLoc - Take necessary steps when DebugLoc changes.
255/// CurFile and CurLine may change as a result of this.
256///
257void PIC16DbgInfo::ChangeDebugLoc(const MachineFunction &MF,
258 const DebugLoc &DL, bool IsInBeginFunction) {
259 if (! EmitDebugDirectives) return;
260 assert (! DL.isUnknown() && "can't change to invalid debug loc");
261
262 GlobalVariable *CU = MF.getDebugLocTuple(DL).CompileUnit;
263 unsigned line = MF.getDebugLocTuple(DL).Line;
264
265 SwitchToCU(CU);
266 SwitchToLine(line, IsInBeginFunction);
267}
268
269/// SwitchToLine - Emit line directive for a new line.
270///
271void PIC16DbgInfo::SwitchToLine(unsigned Line, bool IsInBeginFunction) {
272 if (CurLine == Line) return;
273 if (!IsInBeginFunction) O << "\n\t.line " << Line << "\n";
274 CurLine = Line;
275}
276
277/// EndFunction - Emit .ef for end of function.
278///
279void PIC16DbgInfo::EndFunction(const MachineFunction &MF) {
280 if (! EmitDebugDirectives) return;
Sanjiv Gupta394a1a22009-08-07 11:00:02 +0000281 const DebugLoc &DL = GetDebugLocForFunction(MF);
282 // Emit debug info only if valid debug info is available.
283 if (!DL.isUnknown())
284 EmitFunctEndDI(MF.getFunction(), CurLine);
Sanjiv Guptabde79422009-06-16 09:45:18 +0000285}
286
287/// EndModule - Emit .eof for end of module.
288///
289void PIC16DbgInfo::EndModule(Module &M) {
290 if (! EmitDebugDirectives) return;
291 EmitVarDebugInfo(M);
292 if (CurFile != "") O << "\n\t.eof";
293}
294
295/// EmitCompositeTypeElements - Emit debug information for members of a
296/// composite type.
297///
298void PIC16DbgInfo::EmitCompositeTypeElements (DICompositeType CTy,
Sanjiv Guptabfa79b82009-08-15 14:36:48 +0000299 std::string SuffixNo) {
Sanjiv Guptabde79422009-06-16 09:45:18 +0000300 unsigned long Value = 0;
301 DIArray Elements = CTy.getTypeArray();
302 for (unsigned i = 0, N = Elements.getNumElements(); i < N; i++) {
303 DIDescriptor Element = Elements.getElement(i);
304 unsigned short TypeNo = 0;
305 bool HasAux = false;
306 int ElementAux[PIC16Dbg::AuxSize] = { 0 };
307 std::string TagName = "";
308 std::string ElementName;
309 GlobalVariable *GV = Element.getGV();
310 DIDerivedType DITy(GV);
311 DITy.getName(ElementName);
312 unsigned short ElementSize = DITy.getSizeInBits()/8;
313 // Get mangleddd name for this structure/union element.
Sanjiv Guptabfa79b82009-08-15 14:36:48 +0000314 std::string MangMemName = ElementName + SuffixNo;
Sanjiv Guptabde79422009-06-16 09:45:18 +0000315 PopulateDebugInfo(DITy, TypeNo, HasAux, ElementAux, TagName);
Daniel Dunbar1c723b72009-06-26 02:03:52 +0000316 short Class = 0;
Sanjiv Guptabde79422009-06-16 09:45:18 +0000317 if( CTy.getTag() == dwarf::DW_TAG_union_type)
318 Class = PIC16Dbg::C_MOU;
319 else if (CTy.getTag() == dwarf::DW_TAG_structure_type)
320 Class = PIC16Dbg::C_MOS;
Devang Patel715c6622009-08-10 22:11:20 +0000321 EmitSymbol(MangMemName.c_str(), Class, TypeNo, Value);
Sanjiv Guptabde79422009-06-16 09:45:18 +0000322 if (CTy.getTag() == dwarf::DW_TAG_structure_type)
323 Value += ElementSize;
324 if (HasAux)
Devang Patel715c6622009-08-10 22:11:20 +0000325 EmitAuxEntry(MangMemName.c_str(), ElementAux, PIC16Dbg::AuxSize, TagName);
Sanjiv Guptabde79422009-06-16 09:45:18 +0000326 }
327}
328
329/// EmitCompositeTypeDecls - Emit composite type declarations like structure
330/// and union declarations.
331///
Sanjiv Guptadcb6da32009-06-13 17:35:54 +0000332void PIC16DbgInfo::EmitCompositeTypeDecls(Module &M) {
Devang Patel715c6622009-08-10 22:11:20 +0000333 DebugInfoFinder DbgFinder;
334 DbgFinder.processModule(M);
Sanjiv Guptabfa79b82009-08-15 14:36:48 +0000335 for (DebugInfoFinder::iterator I = DbgFinder.type_begin(),
336 E = DbgFinder.type_end(); I != E; ++I) {
Devang Patel715c6622009-08-10 22:11:20 +0000337 DICompositeType CTy(*I);
338 if (CTy.isNull())
339 continue;
340 if (CTy.getTag() == dwarf::DW_TAG_union_type ||
341 CTy.getTag() == dwarf::DW_TAG_structure_type ) {
342 std::string Name;
343 CTy.getName(Name);
Sanjiv Guptabfa79b82009-08-15 14:36:48 +0000344 // Get the number after llvm.dbg.composite and make UniqueSuffix from
345 // it.
346 std::string DIVar = CTy.getGV()->getNameStr();
347 std::string UniqueSuffix = "." + DIVar.substr(18);
348 std::string MangledCTyName = Name + UniqueSuffix;
Devang Patel715c6622009-08-10 22:11:20 +0000349 unsigned short size = CTy.getSizeInBits()/8;
350 int Aux[PIC16Dbg::AuxSize] = {0};
351 // 7th and 8th byte represent size of structure/union.
352 Aux[6] = size & 0xff;
353 Aux[7] = size >> 8;
354 // Emit .def for structure/union tag.
355 if( CTy.getTag() == dwarf::DW_TAG_union_type)
356 EmitSymbol(MangledCTyName.c_str(), PIC16Dbg::C_UNTAG);
357 else if (CTy.getTag() == dwarf::DW_TAG_structure_type)
358 EmitSymbol(MangledCTyName.c_str(), PIC16Dbg::C_STRTAG);
359
360 // Emit auxiliary debug information for structure/union tag.
361 EmitAuxEntry(MangledCTyName.c_str(), Aux, PIC16Dbg::AuxSize);
362
363 // Emit members.
Sanjiv Guptabfa79b82009-08-15 14:36:48 +0000364 EmitCompositeTypeElements (CTy, UniqueSuffix);
Devang Patel715c6622009-08-10 22:11:20 +0000365
366 // Emit mangled Symbol for end of structure/union.
Sanjiv Guptabfa79b82009-08-15 14:36:48 +0000367 std::string EOSSymbol = ".eos" + UniqueSuffix;
Devang Patel715c6622009-08-10 22:11:20 +0000368 EmitSymbol(EOSSymbol.c_str(), PIC16Dbg::C_EOS);
369 EmitAuxEntry(EOSSymbol.c_str(), Aux, PIC16Dbg::AuxSize,
370 MangledCTyName.c_str());
Sanjiv Guptadcb6da32009-06-13 17:35:54 +0000371 }
372 }
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000373}
374
Devang Patel715c6622009-08-10 22:11:20 +0000375
Sanjiv Guptabde79422009-06-16 09:45:18 +0000376/// EmitFunctBeginDI - Emit .bf for function.
377///
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000378void PIC16DbgInfo::EmitFunctBeginDI(const Function *F) {
379 std::string FunctName = F->getName();
Sanjiv Guptadcb6da32009-06-13 17:35:54 +0000380 if (EmitDebugDirectives) {
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000381 std::string FunctBeginSym = ".bf." + FunctName;
382 std::string BlockBeginSym = ".bb." + FunctName;
383
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000384 int BFAux[PIC16Dbg::AuxSize] = {0};
Sanjiv Guptabde79422009-06-16 09:45:18 +0000385 BFAux[4] = CurLine;
386 BFAux[5] = CurLine >> 8;
387
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000388 // Emit debug directives for beginning of function.
389 EmitSymbol(FunctBeginSym, PIC16Dbg::C_FCN);
390 EmitAuxEntry(FunctBeginSym, BFAux, PIC16Dbg::AuxSize);
Sanjiv Guptabde79422009-06-16 09:45:18 +0000391
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000392 EmitSymbol(BlockBeginSym, PIC16Dbg::C_BLOCK);
393 EmitAuxEntry(BlockBeginSym, BFAux, PIC16Dbg::AuxSize);
394 }
395}
396
Sanjiv Guptabde79422009-06-16 09:45:18 +0000397/// EmitFunctEndDI - Emit .ef for function end.
398///
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000399void PIC16DbgInfo::EmitFunctEndDI(const Function *F, unsigned Line) {
400 std::string FunctName = F->getName();
Sanjiv Guptadcb6da32009-06-13 17:35:54 +0000401 if (EmitDebugDirectives) {
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000402 std::string FunctEndSym = ".ef." + FunctName;
403 std::string BlockEndSym = ".eb." + FunctName;
404
405 // Emit debug directives for end of function.
406 EmitSymbol(BlockEndSym, PIC16Dbg::C_BLOCK);
407 int EFAux[PIC16Dbg::AuxSize] = {0};
408 // 5th and 6th byte stand for line number.
Sanjiv Guptabde79422009-06-16 09:45:18 +0000409 EFAux[4] = CurLine;
410 EFAux[5] = CurLine >> 8;
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000411 EmitAuxEntry(BlockEndSym, EFAux, PIC16Dbg::AuxSize);
412 EmitSymbol(FunctEndSym, PIC16Dbg::C_FCN);
413 EmitAuxEntry(FunctEndSym, EFAux, PIC16Dbg::AuxSize);
414 }
415}
416
417/// EmitAuxEntry - Emit Auxiliary debug information.
418///
Sanjiv Guptabde79422009-06-16 09:45:18 +0000419void PIC16DbgInfo::EmitAuxEntry(const std::string VarName, int Aux[], int Num,
420 std::string TagName) {
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000421 O << "\n\t.dim " << VarName << ", 1" ;
Sanjiv Guptabde79422009-06-16 09:45:18 +0000422 // TagName is emitted in case of structure/union objects.
423 if (TagName != "")
424 O << ", " << TagName;
425 for (int i = 0; i<Num; i++)
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000426 O << "," << Aux[i];
427}
428
Sanjiv Guptabde79422009-06-16 09:45:18 +0000429/// EmitSymbol - Emit .def for a symbol. Value is offset for the member.
430///
Sanjiv Guptadcb6da32009-06-13 17:35:54 +0000431void PIC16DbgInfo::EmitSymbol(std::string Name, short Class, unsigned short
432 Type, unsigned long Value) {
433 O << "\n\t" << ".def "<< Name << ", type = " << Type << ", class = "
434 << Class;
435 if (Value > 0)
436 O << ", value = " << Value;
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000437}
438
Sanjiv Guptabde79422009-06-16 09:45:18 +0000439/// EmitVarDebugInfo - Emit debug information for all variables.
440///
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000441void PIC16DbgInfo::EmitVarDebugInfo(Module &M) {
Devang Patel22516662009-08-06 20:53:24 +0000442 DebugInfoFinder DbgFinder;
443 DbgFinder.processModule(M);
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000444
Devang Patel22516662009-08-06 20:53:24 +0000445 for (DebugInfoFinder::iterator I = DbgFinder.global_variable_begin(),
446 E = DbgFinder.global_variable_end(); I != E; ++I) {
Devang Patel92c55112009-07-06 23:28:36 +0000447 DIGlobalVariable DIGV(*I);
448 DIType Ty = DIGV.getType();
449 unsigned short TypeNo = 0;
450 bool HasAux = false;
451 int Aux[PIC16Dbg::AuxSize] = { 0 };
452 std::string TagName = "";
Daniel Dunbarf6ccee52009-07-24 08:24:36 +0000453 std::string VarName = TAI->getGlobalPrefix()+DIGV.getGlobal()->getNameStr();
Devang Patel92c55112009-07-06 23:28:36 +0000454 PopulateDebugInfo(Ty, TypeNo, HasAux, Aux, TagName);
455 // Emit debug info only if type information is availaible.
456 if (TypeNo != PIC16Dbg::T_NULL) {
457 O << "\n\t.type " << VarName << ", " << TypeNo;
458 short ClassNo = getStorageClass(DIGV);
459 O << "\n\t.class " << VarName << ", " << ClassNo;
460 if (HasAux)
461 EmitAuxEntry(VarName, Aux, PIC16Dbg::AuxSize, TagName);
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000462 }
463 }
464 O << "\n";
465}
466
Sanjiv Guptabde79422009-06-16 09:45:18 +0000467/// SwitchToCU - Switch to a new compilation unit.
468///
469void PIC16DbgInfo::SwitchToCU(GlobalVariable *CU) {
470 // Get the file path from CU.
471 DICompileUnit cu(CU);
472 std::string DirName, FileName;
473 std::string FilePath = cu.getDirectory(DirName) + "/" +
474 cu.getFilename(FileName);
475
476 // Nothing to do if source file is still same.
477 if ( FilePath == CurFile ) return;
478
479 // Else, close the current one and start a new.
480 if (CurFile != "") O << "\n\t.eof";
481 O << "\n\t.file\t\"" << FilePath << "\"\n" ;
482 CurFile = FilePath;
483 CurLine = 0;
Sanjiv Guptadd4694b2009-05-28 18:24:11 +0000484}
Sanjiv Gupta3fc7e532009-06-03 16:27:49 +0000485
Sanjiv Guptabde79422009-06-16 09:45:18 +0000486/// EmitEOF - Emit .eof for end of file.
487///
Sanjiv Gupta3fc7e532009-06-03 16:27:49 +0000488void PIC16DbgInfo::EmitEOF() {
489 if (CurFile != "")
490 O << "\n\t.EOF";
491}
492