Use global information to fill out Dwarf compile units.
authorJim Laskey <jlaskey@mac.com>
Thu, 26 Jan 2006 21:22:49 +0000 (21:22 +0000)
committerJim Laskey <jlaskey@mac.com>
Thu, 26 Jan 2006 21:22:49 +0000 (21:22 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25662 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/DwarfWriter.h
include/llvm/CodeGen/MachineDebugInfo.h
lib/CodeGen/DwarfWriter.cpp
lib/CodeGen/MachineDebugInfo.cpp

index f199dd25fd3930fe219418fda9a52d94479b6250..aec1077eedfa0fdb3c19a0ad92423e28478c60ed 100644 (file)
@@ -32,6 +32,7 @@ namespace llvm {
   // Forward declarations.
   //
   class AsmPrinter;
+  class CompileUnitWrapper;
   class DIE;
   class DwarfWriter; 
   class DWContext;
@@ -645,10 +646,10 @@ public:
                            unsigned Size, unsigned Align);
 
 private:
+
     /// NewCompileUnit - Create new compile unit information.
     ///
-    DIE *NewCompileUnit(const std::string &Directory,
-                        const std::string &SourceName);
+    DIE *DwarfWriter::NewCompileUnit(const CompileUnitWrapper &CompileUnit);
 
     /// EmitInitial - Emit initial Dwarf declarations.
     ///
index 7bbd11db7a6d3bd7a100d4f269a4c99a6c9143f2..fcd75f4749bf81d56b5854db730af735dfdda4ae 100644 (file)
@@ -271,6 +271,10 @@ public:
   ///
   void MachineDebugInfo::SetupCompileUnits(Module &M);
 
+  /// getCompileUnits - Return a vector of debug compile units.
+  ///
+  const UniqueVector<CompileUnitWrapper> getCompileUnits() const;
+
   /// getGlobalVariables - Return a vector of debug global variables.
   ///
   static std::vector<GlobalWrapper> getGlobalVariables(Module &M);
index 512f479fdd22a384fcb1875b85c096143ac6263c..cd2a9da12ce26ed5a91bd9bbba878793be07e417 100644 (file)
@@ -1242,20 +1242,16 @@ void DwarfWriter::NewGlobalVariable(DWContext *Context,
 
 /// NewCompileUnit - Create new compile unit information.
 ///
-DIE *DwarfWriter::NewCompileUnit(const std::string &Directory,
-                                 const std::string &SourceName) {
+DIE *DwarfWriter::NewCompileUnit(const CompileUnitWrapper &CompileUnit) {
   DIE *Unit = new DIE(DW_TAG_compile_unit, DW_CHILDREN_yes);
   // FIXME - use the correct line set.
   Unit->AddLabel (DW_AT_stmt_list, DW_FORM_data4,  DWLabel("line", 0));
   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));
-  // FIXME - The producer needs to be in this form, but should come from
-  // an appropriate source.
-  Unit->AddString(DW_AT_producer,  DW_FORM_string,
-                  "llvm 3.4.x (LLVM Research Group)");
-  Unit->AddInt   (DW_AT_language,  DW_FORM_data1,  DW_LANG_C89);
-  Unit->AddString(DW_AT_name,      DW_FORM_string, SourceName);
-  Unit->AddString(DW_AT_comp_dir,  DW_FORM_string, Directory);
+  Unit->AddString(DW_AT_producer,  DW_FORM_string, CompileUnit.getProducer());
+  Unit->AddInt   (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);
   
   return Unit;
@@ -1700,17 +1696,11 @@ void DwarfWriter::EmitDebugMacInfo() {
 /// ConstructCompileUnitDIEs - Create a compile unit DIE for each source and
 /// header file.
 void DwarfWriter::ConstructCompileUnitDIEs() {
-  // Get directory and source information.
-  const UniqueVector<std::string> &Directories = DebugInfo->getDirectories();
-  const UniqueVector<SourceFileInfo> &SourceFiles = DebugInfo->getSourceFiles();
-
-  // Construct compile unit DIEs for each source.
-  for (unsigned SourceID = 1, NSID = SourceFiles.size();
-                SourceID <=  NSID; ++SourceID) {
-    const SourceFileInfo &SourceFile = SourceFiles[SourceID];
-    const std::string &Directory = Directories[SourceFile.getDirectoryID()];
-    const std::string &SourceName = SourceFile.getName();
-    DIE *Unit = NewCompileUnit(Directory, SourceName);
+  const UniqueVector<CompileUnitWrapper> CUW = DebugInfo->getCompileUnits();
+  
+  for (unsigned i = 1, N = CUW.size(); i <= N; ++i) {
+    const CompileUnitWrapper &CompileUnit = CUW[i];
+    DIE *Unit = NewCompileUnit(CompileUnit);
     DWContext *Context = new DWContext(*this, NULL, Unit);
     CompileUnits.push_back(Unit);
   }
index bfcd9815d4e5bae59de4f31e80c5c8d412ab8853..7d7bb932c6ab19f94b6875eeb577c05127d156a3 100644 (file)
@@ -180,7 +180,7 @@ unsigned GlobalWrapper::getTag() const {
 /// getContext - Return the "lldb.compile_unit" context global.
 ///
 GlobalVariable *GlobalWrapper::getContext() const {
-  return dyn_cast<GlobalVariable>(IC->getOperand(1));
+  return cast<GlobalVariable>(IC->getOperand(1));
 }
 
 /// getName - Return the name of the global.
@@ -192,7 +192,7 @@ const std::string GlobalWrapper::getName() const {
 /// getType - Return the type of the global.
 ///
 const GlobalVariable *GlobalWrapper::getType() const {
-  return dyn_cast<GlobalVariable>(IC->getOperand(4));
+  return cast<GlobalVariable>(IC->getOperand(4));
 }
 
 /// isStatic - Return true if the global is static.
@@ -274,6 +274,12 @@ void MachineDebugInfo::SetupCompileUnits(Module &M) {
   if (CompileUnits.size() != Globals.size()) CompileUnits.reset();
 }
 
+/// getCompileUnits - Return a vector of debug compile units.
+///
+const UniqueVector<CompileUnitWrapper> MachineDebugInfo::getCompileUnits()const{
+  return CompileUnits;
+}
+
 /// getGlobalVariables - Return a vector of debug global variables.
 ///
 std::vector<GlobalWrapper> MachineDebugInfo::getGlobalVariables(Module &M) {