[llvm-commits] CVS: llvm/lib/CodeGen/DwarfWriter.cpp MachineDebugInfo.cpp

Jim Laskey jlaskey at apple.com
Fri Jan 27 07:21:06 PST 2006



Changes in directory llvm/lib/CodeGen:

DwarfWriter.cpp updated: 1.19 -> 1.20
MachineDebugInfo.cpp updated: 1.6 -> 1.7
---
Log message:

Improve visibility/correctness of operand indices in "llvm.db" objects.
Handle 64 in DIEs.


---
Diffs of the changes:  (+71 -48)

 DwarfWriter.cpp      |   59 ++++++++++++++++++++++++++++++++++++--------------
 MachineDebugInfo.cpp |   60 +++++++++++++++++++++++----------------------------
 2 files changed, 71 insertions(+), 48 deletions(-)


Index: llvm/lib/CodeGen/DwarfWriter.cpp
diff -u llvm/lib/CodeGen/DwarfWriter.cpp:1.19 llvm/lib/CodeGen/DwarfWriter.cpp:1.20
--- llvm/lib/CodeGen/DwarfWriter.cpp:1.19	Thu Jan 26 15:22:49 2006
+++ llvm/lib/CodeGen/DwarfWriter.cpp	Fri Jan 27 09:20:54 2006
@@ -674,6 +674,7 @@
   case DW_FORM_data1: DW.EmitByte(Integer);         break;
   case DW_FORM_data2: DW.EmitShort(Integer);        break;
   case DW_FORM_data4: DW.EmitLong(Integer);         break;
+  case DW_FORM_data8: DW.EmitLongLong(Integer);     break;
   case DW_FORM_udata: DW.EmitULEB128Bytes(Integer); break;
   case DW_FORM_sdata: DW.EmitSLEB128Bytes(Integer); break;
   default: assert(0 && "DIE Value form not supported yet"); break;
@@ -688,6 +689,7 @@
   case DW_FORM_data1: return sizeof(int8_t);
   case DW_FORM_data2: return sizeof(int16_t);
   case DW_FORM_data4: return sizeof(int32_t);
+  case DW_FORM_data8: return sizeof(int64_t);
   case DW_FORM_udata: return DW.SizeULEB128(Integer);
   case DW_FORM_sdata: return DW.SizeSLEB128(Integer);
   default: assert(0 && "DIE Value form not supported yet"); break;
@@ -796,20 +798,27 @@
   if (Context) delete Context;
 }
     
-/// AddInt - Add a simple integer attribute data and value.
+/// AddUInt - Add an unsigned integer attribute data and value.
 ///
-void DIE::AddInt(unsigned Attribute, unsigned Form,
-                 int Integer, bool IsSigned) {
+void DIE::AddUInt(unsigned Attribute, unsigned Form, uint64_t Integer) {
   if (Form == 0) {
-    if (IsSigned) {
-      if ((char)Integer == Integer)       Form = DW_FORM_data1;
-      else if ((short)Integer == Integer) Form = DW_FORM_data2;
-      else                                Form = DW_FORM_data4;
-    } else {
       if ((unsigned char)Integer == Integer)       Form = DW_FORM_data1;
       else if ((unsigned short)Integer == Integer) Form = DW_FORM_data2;
-      else                                         Form = DW_FORM_data4;
-    }
+      else if ((unsigned int)Integer == Integer)   Form = DW_FORM_data4;
+      else                                         Form = DW_FORM_data8;
+  }
+  Abbrev->AddAttribute(Attribute, Form);
+  Values.push_back(new DIEInteger(Integer));
+}
+    
+/// AddSInt - Add an signed integer attribute data and value.
+///
+void DIE::AddSInt(unsigned Attribute, unsigned Form, int64_t Integer) {
+  if (Form == 0) {
+      if ((char)Integer == Integer)       Form = DW_FORM_data1;
+      else if ((short)Integer == Integer) Form = DW_FORM_data2;
+      else if ((int)Integer == Integer)   Form = DW_FORM_data4;
+      else                                Form = DW_FORM_data8;
   }
   Abbrev->AddAttribute(Attribute, Form);
   Values.push_back(new DIEInteger(Integer));
@@ -932,8 +941,8 @@
     // construct the type DIE.
     TypeDie = new DIE(DW_TAG_base_type, DW_CHILDREN_no);
     TypeDie->AddString(DW_AT_name,      DW_FORM_string, Name);
-    TypeDie->AddInt   (DW_AT_byte_size, DW_FORM_data1,  Size);
-    TypeDie->AddInt   (DW_AT_encoding,  DW_FORM_data1,  Encoding);
+    TypeDie->AddUInt  (DW_AT_byte_size, DW_FORM_data1,  Size);
+    TypeDie->AddUInt  (DW_AT_encoding,  DW_FORM_data1,  Encoding);
     TypeDie->Complete(DW);
     
     // Add to context owner.
@@ -958,10 +967,10 @@
     // FIXME - need source file name line number.
     VariableDie = new DIE(DW_TAG_variable, DW_CHILDREN_no);
     VariableDie->AddString     (DW_AT_name,      DW_FORM_string, Name);
-    VariableDie->AddInt        (DW_AT_decl_file, 0,              0);
-    VariableDie->AddInt        (DW_AT_decl_line, 0,              0);
+    VariableDie->AddUInt       (DW_AT_decl_file, 0,              0);
+    VariableDie->AddUInt       (DW_AT_decl_line, 0,              0);
     VariableDie->AddDIEntry    (DW_AT_type,      DW_FORM_ref4,   Type);
-    VariableDie->AddInt        (DW_AT_external,  DW_FORM_flag,   1);
+    VariableDie->AddUInt       (DW_AT_external,  DW_FORM_flag,   1);
     // FIXME - needs to be a proper expression.
     VariableDie->AddObjectLabel(DW_AT_location,  DW_FORM_block1, MangledName);
     VariableDie->Complete(DW);
@@ -1096,6 +1105,24 @@
   PrintHex(Value);
 }
 
+/// EmitLongLong - Emit a long long directive and value.
+///
+void DwarfWriter::EmitLongLong(uint64_t Value) const {
+  if (Asm->Data64bitsDirective) {
+    O << Asm->Data64bitsDirective << "0x" << std::hex << Value << std::dec;
+  } else {
+    const TargetData &TD = Asm->TM.getTargetData();
+    
+    if (TD.isBigEndian()) {
+      EmitLong(unsigned(Value >> 32)); O << "\n";
+      EmitLong(unsigned(Value));
+    } else {
+      EmitLong(unsigned(Value)); O << "\n";
+      EmitLong(unsigned(Value >> 32));
+    }
+  }
+}
+
 /// EmitString - Emit a string with quotes and a null terminator.
 /// Special characters are emitted properly. (Eg. '\t')
 void DwarfWriter::EmitString(const std::string &String) const {
@@ -1249,7 +1276,7 @@
   Unit->AddLabel (DW_AT_high_pc,   DW_FORM_addr,   DWLabel("text_end", 0));
   Unit->AddLabel (DW_AT_low_pc,    DW_FORM_addr,   DWLabel("text_begin", 0));
   Unit->AddString(DW_AT_producer,  DW_FORM_string, CompileUnit.getProducer());
-  Unit->AddInt   (DW_AT_language,  DW_FORM_data1,  CompileUnit.getLanguage());
+  Unit->AddUInt  (DW_AT_language,  DW_FORM_data1,  CompileUnit.getLanguage());
   Unit->AddString(DW_AT_name,      DW_FORM_string, CompileUnit.getFileName());
   Unit->AddString(DW_AT_comp_dir,  DW_FORM_string, CompileUnit.getDirectory());
   Unit->Complete(*this);


Index: llvm/lib/CodeGen/MachineDebugInfo.cpp
diff -u llvm/lib/CodeGen/MachineDebugInfo.cpp:1.6 llvm/lib/CodeGen/MachineDebugInfo.cpp:1.7
--- llvm/lib/CodeGen/MachineDebugInfo.cpp:1.6	Thu Jan 26 15:22:49 2006
+++ llvm/lib/CodeGen/MachineDebugInfo.cpp	Fri Jan 27 09:20:54 2006
@@ -97,6 +97,19 @@
   }
   return "";
 }
+
+/// getGlobalValue - Return either a direct or cast Global value.
+///
+static GlobalVariable *getGlobalValue(Value *V) {
+  if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) {
+    return GV;
+  } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) {
+    return CE->getOpcode() == Instruction::Cast ?  dyn_cast<GlobalVariable>(V)
+                                                :  NULL;
+  }
+  return NULL;
+}
+
   
 //===----------------------------------------------------------------------===//
 
@@ -112,51 +125,45 @@
 : DebugInfoWrapper(G)
 {
   // FIXME - should probably ease up on the number of operands (version.)
-  assert(IC->getNumOperands() == 7 &&
+  assert(IC->getNumOperands() == N_op &&
          "Compile unit does not have correct number of operands");
 }
 
 /// getTag - Return the compile unit's tag number.  Currently should be 
 /// DW_TAG_variable.
 unsigned CompileUnitWrapper::getTag() const {
-  ConstantUInt *CI = dyn_cast<ConstantUInt>(IC->getOperand(0));
-  assert(CI && "Compile unit tag not an unsigned integer");
-  return CI->getValue();
+  return cast<ConstantUInt>(IC->getOperand(Tag_op))->getValue();
 }
 
 /// isCorrectDebugVersion - Return true if is the correct llvm debug version.
 /// Currently the value is 0 (zero.)  If the value is is not correct then
 /// ignore all debug information.
 bool CompileUnitWrapper::isCorrectDebugVersion() const {
-  ConstantUInt *CI = dyn_cast<ConstantUInt>(IC->getOperand(1));
-  assert(CI && "Compile unit debug version not an unsigned integer");
-  return CI->getValue() == 0;
+  return cast<ConstantUInt>(IC->getOperand(Version_op))->getValue();
 }
 
 /// getLanguage - Return the compile unit's language number (ex. DW_LANG_C89.)
 ///
 unsigned CompileUnitWrapper::getLanguage() const {
-  ConstantUInt *CI = dyn_cast<ConstantUInt>(IC->getOperand(2));
-  assert(CI && "Compile unit language number not an unsigned integer");
-  return CI->getValue();
+  return cast<ConstantUInt>(IC->getOperand(Language_op))->getValue();
 }
 
 /// getFileName - Return the compile unit's file name.
 ///
 const std::string CompileUnitWrapper::getFileName() const {
-  return getStringValue(IC->getOperand(3));
+  return getStringValue(IC->getOperand(FileName_op));
 }
 
 /// getDirectory - Return the compile unit's file directory.
 ///
 const std::string CompileUnitWrapper::getDirectory() const {
-  return getStringValue(IC->getOperand(4));
+  return getStringValue(IC->getOperand(Directory_op));
 }
   
 /// getProducer - Return the compile unit's generator name.
 ///
 const std::string CompileUnitWrapper::getProducer() const {
-  return getStringValue(IC->getOperand(5));
+  return getStringValue(IC->getOperand(Producer_op));
 }
 
 //===----------------------------------------------------------------------===//
@@ -165,61 +172,50 @@
 : DebugInfoWrapper(G)
 {
   // FIXME - should probably ease up on the number of operands (version.)
-  assert(IC->getNumOperands() == 8 &&
+  assert(IC->getNumOperands() == N_op &&
          "Global does not have correct number of operands");
 }
 
 /// getTag - Return the global's tag number.  Currently should be 
 /// DW_TAG_variable or DW_TAG_subprogram.
 unsigned GlobalWrapper::getTag() const {
-  ConstantUInt *CI = dyn_cast<ConstantUInt>(IC->getOperand(0));
-  assert(CI && "Global tag not an unsigned integer");
-  return CI->getValue();
+  return cast<ConstantUInt>(IC->getOperand(Tag_op))->getValue();
 }
 
 /// getContext - Return the "lldb.compile_unit" context global.
 ///
 GlobalVariable *GlobalWrapper::getContext() const {
-  return cast<GlobalVariable>(IC->getOperand(1));
+  return getGlobalValue(IC->getOperand(Context_op));
 }
 
 /// getName - Return the name of the global.
 ///
 const std::string GlobalWrapper::getName() const {
-  return getStringValue(IC->getOperand(2));
+  return getStringValue(IC->getOperand(Name_op));
 }
 
 /// getType - Return the type of the global.
 ///
 const GlobalVariable *GlobalWrapper::getType() const {
-  return cast<GlobalVariable>(IC->getOperand(4));
+  return getGlobalValue(IC->getOperand(Type_op));
 }
 
 /// isStatic - Return true if the global is static.
 ///
 bool GlobalWrapper::isStatic() const {
-  ConstantBool *CB = dyn_cast<ConstantBool>(IC->getOperand(5));
-  assert(CB && "Global static flag is not boolean");
-  return CB->getValue();
+  return cast<ConstantBool>(IC->getOperand(Static_op))->getValue();
 }
 
 /// isDefinition - Return true if the global is a definition.
 ///
 bool GlobalWrapper::isDefinition() const {
-  ConstantBool *CB = dyn_cast<ConstantBool>(IC->getOperand(6));
-  assert(CB && "Global definition flag is not boolean");
-  return CB->getValue();
+  return dyn_cast<ConstantBool>(IC->getOperand(Definition_op))->getValue();
 }
 
 /// getGlobalVariable - Return the global variable (tag == DW_TAG_variable.)
 ///
 GlobalVariable *GlobalWrapper::getGlobalVariable() const {
-  ConstantExpr *CE = dyn_cast<ConstantExpr>(IC->getOperand(7));
-  assert(CE && CE->getOpcode() == Instruction::Cast &&
-         "Global location is not a cast of GlobalVariable");
-  GlobalVariable *GV = dyn_cast<GlobalVariable>(CE->getOperand(0));
-  assert(GV && "Global location is not a cast of GlobalVariable");
-  return GV;
+  return getGlobalValue(IC->getOperand(GlobalVariable_op));
 }
 
 //===----------------------------------------------------------------------===//






More information about the llvm-commits mailing list