forked from OSchip/llvm-project
Add a -dump-record-layouts argument to clang-cc.
llvm-svn: 82703
This commit is contained in:
parent
0868eea3f0
commit
d934010557
|
@ -342,7 +342,7 @@
|
|||
1A2193CC0F45EEB700C0713D /* Mangle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; name = Mangle.cpp; path = lib/CodeGen/Mangle.cpp; sourceTree = "<group>"; tabWidth = 2; };
|
||||
1A2193CD0F45EEB700C0713D /* Mangle.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.c.h; name = Mangle.h; path = lib/CodeGen/Mangle.h; sourceTree = "<group>"; tabWidth = 2; };
|
||||
1A2A54A40FD1DD1C00F4CE45 /* AnalysisConsumer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = AnalysisConsumer.cpp; path = lib/Frontend/AnalysisConsumer.cpp; sourceTree = "<group>"; };
|
||||
1A2A54A50FD1DD1C00F4CE45 /* ASTConsumers.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ASTConsumers.cpp; path = lib/Frontend/ASTConsumers.cpp; sourceTree = "<group>"; };
|
||||
1A2A54A50FD1DD1C00F4CE45 /* ASTConsumers.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; name = ASTConsumers.cpp; path = lib/Frontend/ASTConsumers.cpp; sourceTree = "<group>"; tabWidth = 2; };
|
||||
1A2A54A60FD1DD1C00F4CE45 /* Backend.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Backend.cpp; path = lib/Frontend/Backend.cpp; sourceTree = "<group>"; };
|
||||
1A2A54A70FD1DD1C00F4CE45 /* CacheTokens.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CacheTokens.cpp; path = lib/Frontend/CacheTokens.cpp; sourceTree = "<group>"; };
|
||||
1A2A54A80FD1DD1C00F4CE45 /* DependencyFile.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DependencyFile.cpp; path = lib/Frontend/DependencyFile.cpp; sourceTree = "<group>"; };
|
||||
|
|
|
@ -57,6 +57,10 @@ ASTConsumer *CreateASTViewer();
|
|||
// to stderr; this is intended for debugging.
|
||||
ASTConsumer *CreateDeclContextPrinter();
|
||||
|
||||
// RecordLayout dumper: prints out the record layout information for all records
|
||||
// in the translation unit; this is intended for debugging.
|
||||
ASTConsumer *CreateRecordLayoutDumper();
|
||||
|
||||
// ObjC rewriter: attempts tp rewrite ObjC constructs into pure C code.
|
||||
// This is considered experimental, and only works with Apple's ObjC runtime.
|
||||
ASTConsumer *CreateObjCRewriter(const std::string &InFile,
|
||||
|
|
|
@ -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"
|
||||
|
@ -418,6 +419,55 @@ ASTConsumer *clang::CreateDeclContextPrinter() {
|
|||
return new DeclContextPrinter();
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
/// 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
|
||||
|
||||
|
|
|
@ -138,6 +138,7 @@ enum ProgActions {
|
|||
ASTDump, // Parse ASTs and dump them.
|
||||
ASTView, // Parse ASTs and view them in Graphviz.
|
||||
PrintDeclContext, // Print DeclContext and their Decls.
|
||||
DumpRecordLayouts, // Dump record layout information.
|
||||
ParsePrintCallbacks, // Parse and print each callback.
|
||||
ParseSyntaxOnly, // Parse and perform semantic analysis.
|
||||
ParseNoop, // Parse with noop callbacks.
|
||||
|
@ -183,6 +184,8 @@ ProgAction(llvm::cl::desc("Choose output type:"), llvm::cl::ZeroOrMore,
|
|||
"Build ASTs and view them with GraphViz"),
|
||||
clEnumValN(PrintDeclContext, "print-decl-contexts",
|
||||
"Print DeclContexts and their Decls"),
|
||||
clEnumValN(DumpRecordLayouts, "dump-record-layouts",
|
||||
"Dump record layout information"),
|
||||
clEnumValN(GeneratePTH, "emit-pth",
|
||||
"Generate pre-tokenized header file"),
|
||||
clEnumValN(GeneratePCH, "emit-pch",
|
||||
|
@ -1774,6 +1777,9 @@ static ASTConsumer *CreateConsumerAction(Preprocessor &PP,
|
|||
case PrintDeclContext:
|
||||
return CreateDeclContextPrinter();
|
||||
|
||||
case DumpRecordLayouts:
|
||||
return CreateRecordLayoutDumper();
|
||||
|
||||
case InheritanceView:
|
||||
return CreateInheritanceViewer(InheritanceViewCls);
|
||||
|
||||
|
|
Loading…
Reference in New Issue