]> granicus.if.org Git - clang/commitdiff
AST: Dump ASTRecordLayout objects when they are created with -fdump-record-layouts.
authorDaniel Dunbar <daniel@zuster.org>
Mon, 19 Apr 2010 20:44:53 +0000 (20:44 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Mon, 19 Apr 2010 20:44:53 +0000 (20:44 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101815 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ASTContext.cpp
lib/AST/RecordLayoutBuilder.cpp
lib/CodeGen/CGRecordLayoutBuilder.cpp

index a3c08d56b0452a16d3d62402caa13cdb25674094..96e2e75eaaaa5592f4498c5a306d2c763b2a9c37 100644 (file)
@@ -998,6 +998,11 @@ const ASTRecordLayout &ASTContext::getASTRecordLayout(const RecordDecl *D) {
     ASTRecordLayoutBuilder::ComputeLayout(*this, D);
   ASTRecordLayouts[D] = NewEntry;
 
+  if (getLangOptions().DumpRecordLayouts) {
+    llvm::errs() << "\n*** Dumping AST Record Layout\n";
+    DumpRecordLayout(D, llvm::errs());
+  }
+
   return *NewEntry;
 }
 
index 3038d912fc32cbce2f9a9b974e1532467a4686a2..3782985e53029edcc62a47882bce51998a17f679 100644 (file)
@@ -860,7 +860,7 @@ const CXXMethodDecl *
 ASTRecordLayoutBuilder::ComputeKeyFunction(const CXXRecordDecl *RD) {
   assert(RD->isDynamicClass() && "Class does not have any virtual methods!");
 
-  // If a class isnt' polymorphic it doesn't have a key function.
+  // If a class isn't polymorphic it doesn't have a key function.
   if (!RD->isPolymorphic())
     return 0;
 
@@ -983,17 +983,6 @@ static void DumpCXXRecordLayout(llvm::raw_ostream &OS,
                         "(primary virtual base)" : "(virtual base)",
                         /*IncludeVirtualBases=*/false);
   }
-}
-
-void ASTContext::DumpRecordLayout(const RecordDecl *RD,
-                                  llvm::raw_ostream &OS) {
-  const ASTRecordLayout &Info = getASTRecordLayout(RD);
-
-  if (const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD))
-    DumpCXXRecordLayout(OS, CXXRD, *this, 0, 0, 0,
-                        /*IncludeVirtualBases=*/true);
-  else
-    OS << getTypeDeclType(RD).getAsString();
 
   OS << "  sizeof=" << Info.getSize() / 8;
   OS << ", dsize=" << Info.getDataSize() / 8;
@@ -1002,3 +991,27 @@ void ASTContext::DumpRecordLayout(const RecordDecl *RD,
   OS << ", nvalign=" << Info.getNonVirtualAlign() / 8 << '\n';
   OS << '\n';
 }
+
+void ASTContext::DumpRecordLayout(const RecordDecl *RD,
+                                  llvm::raw_ostream &OS) {
+  const ASTRecordLayout &Info = getASTRecordLayout(RD);
+
+  if (const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD))
+    return DumpCXXRecordLayout(OS, CXXRD, *this, 0, 0, 0,
+                               /*IncludeVirtualBases=*/true);
+
+  OS << "Type: " << getTypeDeclType(RD).getAsString() << "\n";
+  OS << "Record: ";
+  RD->dump();
+  OS << "\nLayout: ";
+  OS << "<ASTRecordLayout\n";
+  OS << "  Size:" << Info.getSize() << "\n";
+  OS << "  DataSize:" << Info.getDataSize() << "\n";
+  OS << "  Alignment:" << Info.getAlignment() << "\n";
+  OS << "  FieldOffsets: [";
+  for (unsigned i = 0, e = Info.getFieldCount(); i != e; ++i) {
+    if (i) OS << ", ";
+    OS << Info.getFieldOffset(i);
+  }
+  OS << "]>\n";
+}
index f056314221a8d52c9626d5e440d2b947be7da225..7b7394a81968b4bf63df10b7c5185671437fb335 100644 (file)
@@ -566,7 +566,7 @@ CGRecordLayout *CodeGenTypes::ComputeRecordLayout(const RecordDecl *D) {
 
   // Dump the layout, if requested.
   if (getContext().getLangOptions().DumpRecordLayouts) {
-    llvm::errs() << "\n*** Dumping Record Layout\n";
+    llvm::errs() << "\n*** Dumping IRgen Record Layout\n";
     llvm::errs() << "Record: ";
     D->dump();
     llvm::errs() << "\nLayout: ";