diff options
Diffstat (limited to 'lib/Frontend/ASTConsumers.cpp')
-rw-r--r-- | lib/Frontend/ASTConsumers.cpp | 50 |
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 { |