aboutsummaryrefslogtreecommitdiff
path: root/lib/Frontend/ASTConsumers.cpp
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-09-24 18:54:49 +0000
committerAnders Carlsson <andersca@mac.com>2009-09-24 18:54:49 +0000
commit78762ebb9ad71d681110d4bada4b0575eaadfebe (patch)
treeb2d92c49abb7073ce9dcfa1f3161091249155228 /lib/Frontend/ASTConsumers.cpp
parent6c2497248bc4f7fd8e5fb0a206d20abbf0e16645 (diff)
Add a -dump-record-layouts argument to clang-cc.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82703 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/ASTConsumers.cpp')
-rw-r--r--lib/Frontend/ASTConsumers.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/Frontend/ASTConsumers.cpp b/lib/Frontend/ASTConsumers.cpp
index 3abd2b36e6..aec68f3e11 100644
--- a/lib/Frontend/ASTConsumers.cpp
+++ b/lib/Frontend/ASTConsumers.cpp
@@ -20,6 +20,7 @@
#include "clang/AST/AST.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/ASTContext.h"
+#include "clang/AST/RecordLayout.h"
#include "clang/AST/PrettyPrinter.h"
#include "clang/CodeGen/ModuleBuilder.h"
#include "llvm/Module.h"
@@ -419,6 +420,55 @@ ASTConsumer *clang::CreateDeclContextPrinter() {
}
//===----------------------------------------------------------------------===//
+/// RecordLayoutDumper - C++ Record Layout Dumping.
+namespace {
+class RecordLayoutDumper : public ASTConsumer {
+ llvm::raw_ostream& Out;
+
+ // FIXME: Maybe this be useful in ASTContext.cpp.
+ void DumpRecordLayout(const CXXRecordDecl *RD, ASTContext &C) {
+ const ASTRecordLayout &Info = C.getASTRecordLayout(RD);
+
+ Out << RD->getKindName() << ' ' << RD->getQualifiedNameAsString() << '\n';
+ Out << " sizeof=" << Info.getSize() / 8;
+ Out << ", dsize=" << Info.getDataSize() / 8;
+ Out << ", align=" << Info.getAlignment() / 8 << '\n';
+ Out << " nvsize=" << Info.getNonVirtualSize() / 8;
+ Out << ", nvalign=" << Info.getNonVirtualAlign() / 8 << '\n';
+ Out << '\n';
+ }
+
+public:
+ RecordLayoutDumper() : Out(llvm::errs()) {}
+
+ void HandleTranslationUnit(ASTContext &C) {
+ for (ASTContext::type_iterator I = C.types_begin(), E = C.types_end();
+ I != E; ++I) {
+ const RecordType *RT = dyn_cast<RecordType>(*I);
+ if (!RT)
+ continue;
+
+ const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(RT->getDecl());
+ if (!RD)
+ continue;
+
+ if (RD->isImplicit())
+ continue;
+
+ // FIXME: Do we really need to hard code this?
+ if (RD->getQualifiedNameAsString() == "__va_list_tag")
+ continue;
+
+ DumpRecordLayout(RD, C);
+ }
+ }
+};
+} // end anonymous namespace
+ASTConsumer *clang::CreateRecordLayoutDumper() {
+ return new RecordLayoutDumper();
+}
+
+//===----------------------------------------------------------------------===//
/// InheritanceViewer - C++ Inheritance Visualization
namespace {