LLVM API Documentation
00001 //===--- lib/CodeGen/DIE.h - DWARF Info Entries -----------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // Data structures for DWARF info entries. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef CODEGEN_ASMPRINTER_DIE_H__ 00015 #define CODEGEN_ASMPRINTER_DIE_H__ 00016 00017 #include "llvm/ADT/FoldingSet.h" 00018 #include "llvm/ADT/SmallVector.h" 00019 #include "llvm/Support/Compiler.h" 00020 #include "llvm/Support/Dwarf.h" 00021 #include <vector> 00022 00023 namespace llvm { 00024 class AsmPrinter; 00025 class MCSymbol; 00026 class raw_ostream; 00027 00028 //===--------------------------------------------------------------------===// 00029 /// DIEAbbrevData - Dwarf abbreviation data, describes the one attribute of a 00030 /// Dwarf abbreviation. 00031 class DIEAbbrevData { 00032 /// Attribute - Dwarf attribute code. 00033 /// 00034 uint16_t Attribute; 00035 00036 /// Form - Dwarf form code. 00037 /// 00038 uint16_t Form; 00039 public: 00040 DIEAbbrevData(uint16_t A, uint16_t F) : Attribute(A), Form(F) {} 00041 00042 // Accessors. 00043 uint16_t getAttribute() const { return Attribute; } 00044 uint16_t getForm() const { return Form; } 00045 00046 /// Profile - Used to gather unique data for the abbreviation folding set. 00047 /// 00048 void Profile(FoldingSetNodeID &ID) const; 00049 }; 00050 00051 //===--------------------------------------------------------------------===// 00052 /// DIEAbbrev - Dwarf abbreviation, describes the organization of a debug 00053 /// information object. 00054 class DIEAbbrev : public FoldingSetNode { 00055 /// Tag - Dwarf tag code. 00056 /// 00057 uint16_t Tag; 00058 00059 /// ChildrenFlag - Dwarf children flag. 00060 /// 00061 uint16_t ChildrenFlag; 00062 00063 /// Unique number for node. 00064 /// 00065 unsigned Number; 00066 00067 /// Data - Raw data bytes for abbreviation. 00068 /// 00069 SmallVector<DIEAbbrevData, 12> Data; 00070 00071 public: 00072 DIEAbbrev(uint16_t T, uint16_t C) : Tag(T), ChildrenFlag(C), Data() {} 00073 00074 // Accessors. 00075 uint16_t getTag() const { return Tag; } 00076 unsigned getNumber() const { return Number; } 00077 uint16_t getChildrenFlag() const { return ChildrenFlag; } 00078 const SmallVectorImpl<DIEAbbrevData> &getData() const { return Data; } 00079 void setTag(uint16_t T) { Tag = T; } 00080 void setChildrenFlag(uint16_t CF) { ChildrenFlag = CF; } 00081 void setNumber(unsigned N) { Number = N; } 00082 00083 /// AddAttribute - Adds another set of attribute information to the 00084 /// abbreviation. 00085 void AddAttribute(uint16_t Attribute, uint16_t Form) { 00086 Data.push_back(DIEAbbrevData(Attribute, Form)); 00087 } 00088 00089 /// AddFirstAttribute - Adds a set of attribute information to the front 00090 /// of the abbreviation. 00091 void AddFirstAttribute(uint16_t Attribute, uint16_t Form) { 00092 Data.insert(Data.begin(), DIEAbbrevData(Attribute, Form)); 00093 } 00094 00095 /// Profile - Used to gather unique data for the abbreviation folding set. 00096 /// 00097 void Profile(FoldingSetNodeID &ID) const; 00098 00099 /// Emit - Print the abbreviation using the specified asm printer. 00100 /// 00101 void Emit(AsmPrinter *AP) const; 00102 00103 #ifndef NDEBUG 00104 void print(raw_ostream &O); 00105 void dump(); 00106 #endif 00107 }; 00108 00109 //===--------------------------------------------------------------------===// 00110 /// DIE - A structured debug information entry. Has an abbreviation which 00111 /// describes its organization. 00112 class DIEValue; 00113 00114 class DIE { 00115 protected: 00116 /// Offset - Offset in debug info section. 00117 /// 00118 unsigned Offset; 00119 00120 /// Size - Size of instance + children. 00121 /// 00122 unsigned Size; 00123 00124 /// Abbrev - Buffer for constructing abbreviation. 00125 /// 00126 DIEAbbrev Abbrev; 00127 00128 /// Children DIEs. 00129 /// 00130 std::vector<DIE *> Children; 00131 00132 DIE *Parent; 00133 00134 /// Attribute values. 00135 /// 00136 SmallVector<DIEValue*, 12> Values; 00137 00138 // Private data for print() 00139 mutable unsigned IndentCount; 00140 public: 00141 explicit DIE(unsigned Tag) 00142 : Offset(0), Size(0), Abbrev(Tag, dwarf::DW_CHILDREN_no), Parent(0) {} 00143 virtual ~DIE(); 00144 00145 // Accessors. 00146 DIEAbbrev &getAbbrev() { return Abbrev; } 00147 unsigned getAbbrevNumber() const { return Abbrev.getNumber(); } 00148 unsigned getTag() const { return Abbrev.getTag(); } 00149 unsigned getOffset() const { return Offset; } 00150 unsigned getSize() const { return Size; } 00151 const std::vector<DIE *> &getChildren() const { return Children; } 00152 const SmallVectorImpl<DIEValue*> &getValues() const { return Values; } 00153 DIE *getParent() const { return Parent; } 00154 /// Climb up the parent chain to get the compile unit DIE this DIE belongs 00155 /// to. 00156 DIE *getCompileUnit(); 00157 void setTag(unsigned Tag) { Abbrev.setTag(Tag); } 00158 void setOffset(unsigned O) { Offset = O; } 00159 void setSize(unsigned S) { Size = S; } 00160 00161 /// addValue - Add a value and attributes to a DIE. 00162 /// 00163 void addValue(unsigned Attribute, unsigned Form, DIEValue *Value) { 00164 Abbrev.AddAttribute(Attribute, Form); 00165 Values.push_back(Value); 00166 } 00167 00168 /// addChild - Add a child to the DIE. 00169 /// 00170 void addChild(DIE *Child) { 00171 if (Child->getParent()) { 00172 assert (Child->getParent() == this && "Unexpected DIE Parent!"); 00173 return; 00174 } 00175 Abbrev.setChildrenFlag(dwarf::DW_CHILDREN_yes); 00176 Children.push_back(Child); 00177 Child->Parent = this; 00178 } 00179 00180 #ifndef NDEBUG 00181 void print(raw_ostream &O, unsigned IndentCount = 0) const; 00182 void dump(); 00183 #endif 00184 }; 00185 00186 //===--------------------------------------------------------------------===// 00187 /// DIEValue - A debug information entry value. 00188 /// 00189 class DIEValue { 00190 virtual void anchor(); 00191 public: 00192 enum { 00193 isInteger, 00194 isString, 00195 isLabel, 00196 isDelta, 00197 isEntry, 00198 isBlock 00199 }; 00200 protected: 00201 /// Type - Type of data stored in the value. 00202 /// 00203 unsigned Type; 00204 public: 00205 explicit DIEValue(unsigned T) : Type(T) {} 00206 virtual ~DIEValue() {} 00207 00208 // Accessors 00209 unsigned getType() const { return Type; } 00210 00211 /// EmitValue - Emit value via the Dwarf writer. 00212 /// 00213 virtual void EmitValue(AsmPrinter *AP, unsigned Form) const = 0; 00214 00215 /// SizeOf - Return the size of a value in bytes. 00216 /// 00217 virtual unsigned SizeOf(AsmPrinter *AP, unsigned Form) const = 0; 00218 00219 #ifndef NDEBUG 00220 virtual void print(raw_ostream &O) = 0; 00221 void dump(); 00222 #endif 00223 }; 00224 00225 //===--------------------------------------------------------------------===// 00226 /// DIEInteger - An integer value DIE. 00227 /// 00228 class DIEInteger : public DIEValue { 00229 uint64_t Integer; 00230 public: 00231 explicit DIEInteger(uint64_t I) : DIEValue(isInteger), Integer(I) {} 00232 00233 /// BestForm - Choose the best form for integer. 00234 /// 00235 static unsigned BestForm(bool IsSigned, uint64_t Int) { 00236 if (IsSigned) { 00237 const int64_t SignedInt = Int; 00238 if ((char)Int == SignedInt) return dwarf::DW_FORM_data1; 00239 if ((short)Int == SignedInt) return dwarf::DW_FORM_data2; 00240 if ((int)Int == SignedInt) return dwarf::DW_FORM_data4; 00241 } else { 00242 if ((unsigned char)Int == Int) return dwarf::DW_FORM_data1; 00243 if ((unsigned short)Int == Int) return dwarf::DW_FORM_data2; 00244 if ((unsigned int)Int == Int) return dwarf::DW_FORM_data4; 00245 } 00246 return dwarf::DW_FORM_data8; 00247 } 00248 00249 /// EmitValue - Emit integer of appropriate size. 00250 /// 00251 virtual void EmitValue(AsmPrinter *AP, unsigned Form) const; 00252 00253 uint64_t getValue() const { return Integer; } 00254 00255 /// SizeOf - Determine size of integer value in bytes. 00256 /// 00257 virtual unsigned SizeOf(AsmPrinter *AP, unsigned Form) const; 00258 00259 // Implement isa/cast/dyncast. 00260 static bool classof(const DIEValue *I) { return I->getType() == isInteger; } 00261 00262 #ifndef NDEBUG 00263 virtual void print(raw_ostream &O); 00264 #endif 00265 }; 00266 00267 //===--------------------------------------------------------------------===// 00268 /// DIELabel - A label expression DIE. 00269 // 00270 class DIELabel : public DIEValue { 00271 const MCSymbol *Label; 00272 public: 00273 explicit DIELabel(const MCSymbol *L) : DIEValue(isLabel), Label(L) {} 00274 00275 /// EmitValue - Emit label value. 00276 /// 00277 virtual void EmitValue(AsmPrinter *AP, unsigned Form) const; 00278 00279 /// getValue - Get MCSymbol. 00280 /// 00281 const MCSymbol *getValue() const { return Label; } 00282 00283 /// SizeOf - Determine size of label value in bytes. 00284 /// 00285 virtual unsigned SizeOf(AsmPrinter *AP, unsigned Form) const; 00286 00287 // Implement isa/cast/dyncast. 00288 static bool classof(const DIEValue *L) { return L->getType() == isLabel; } 00289 00290 #ifndef NDEBUG 00291 virtual void print(raw_ostream &O); 00292 #endif 00293 }; 00294 00295 //===--------------------------------------------------------------------===// 00296 /// DIEDelta - A simple label difference DIE. 00297 /// 00298 class DIEDelta : public DIEValue { 00299 const MCSymbol *LabelHi; 00300 const MCSymbol *LabelLo; 00301 public: 00302 DIEDelta(const MCSymbol *Hi, const MCSymbol *Lo) 00303 : DIEValue(isDelta), LabelHi(Hi), LabelLo(Lo) {} 00304 00305 /// EmitValue - Emit delta value. 00306 /// 00307 virtual void EmitValue(AsmPrinter *AP, unsigned Form) const; 00308 00309 /// SizeOf - Determine size of delta value in bytes. 00310 /// 00311 virtual unsigned SizeOf(AsmPrinter *AP, unsigned Form) const; 00312 00313 // Implement isa/cast/dyncast. 00314 static bool classof(const DIEValue *D) { return D->getType() == isDelta; } 00315 00316 #ifndef NDEBUG 00317 virtual void print(raw_ostream &O); 00318 #endif 00319 }; 00320 00321 //===--------------------------------------------------------------------===// 00322 /// DIEEntry - A pointer to another debug information entry. An instance of 00323 /// this class can also be used as a proxy for a debug information entry not 00324 /// yet defined (ie. types.) 00325 class DIEEntry : public DIEValue { 00326 DIE *const Entry; 00327 public: 00328 explicit DIEEntry(DIE *E) : DIEValue(isEntry), Entry(E) { 00329 assert(E && "Cannot construct a DIEEntry with a null DIE"); 00330 } 00331 00332 DIE *getEntry() const { return Entry; } 00333 00334 /// EmitValue - Emit debug information entry offset. 00335 /// 00336 virtual void EmitValue(AsmPrinter *AP, unsigned Form) const; 00337 00338 /// SizeOf - Determine size of debug information entry in bytes. 00339 /// 00340 virtual unsigned SizeOf(AsmPrinter *AP, unsigned Form) const { 00341 return sizeof(int32_t); 00342 } 00343 00344 // Implement isa/cast/dyncast. 00345 static bool classof(const DIEValue *E) { return E->getType() == isEntry; } 00346 00347 #ifndef NDEBUG 00348 virtual void print(raw_ostream &O); 00349 #endif 00350 }; 00351 00352 //===--------------------------------------------------------------------===// 00353 /// DIEBlock - A block of values. Primarily used for location expressions. 00354 // 00355 class DIEBlock : public DIEValue, public DIE { 00356 unsigned Size; // Size in bytes excluding size header. 00357 public: 00358 DIEBlock() 00359 : DIEValue(isBlock), DIE(0), Size(0) {} 00360 virtual ~DIEBlock() {} 00361 00362 /// ComputeSize - calculate the size of the block. 00363 /// 00364 unsigned ComputeSize(AsmPrinter *AP); 00365 00366 /// BestForm - Choose the best form for data. 00367 /// 00368 unsigned BestForm() const { 00369 if ((unsigned char)Size == Size) return dwarf::DW_FORM_block1; 00370 if ((unsigned short)Size == Size) return dwarf::DW_FORM_block2; 00371 if ((unsigned int)Size == Size) return dwarf::DW_FORM_block4; 00372 return dwarf::DW_FORM_block; 00373 } 00374 00375 /// EmitValue - Emit block data. 00376 /// 00377 virtual void EmitValue(AsmPrinter *AP, unsigned Form) const; 00378 00379 /// SizeOf - Determine size of block data in bytes. 00380 /// 00381 virtual unsigned SizeOf(AsmPrinter *AP, unsigned Form) const; 00382 00383 // Implement isa/cast/dyncast. 00384 static bool classof(const DIEValue *E) { return E->getType() == isBlock; } 00385 00386 #ifndef NDEBUG 00387 virtual void print(raw_ostream &O); 00388 #endif 00389 }; 00390 00391 } // end llvm namespace 00392 00393 #endif