From b69eca5d2196c06870d3eeb62d689feebaaa8a4d Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Thu, 8 Apr 2010 02:59:56 +0000 Subject: [PATCH] Fronted: Kill overly specialized RecordLayoutDumper, just make -dump-record-layouts a bit that Sema honors. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@100747 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/LangOptions.h | 5 ++-- include/clang/Driver/CC1Options.td | 5 ++-- include/clang/Frontend/ASTConsumers.h | 4 --- include/clang/Frontend/FrontendActions.h | 6 ----- include/clang/Frontend/FrontendOptions.h | 1 - lib/Frontend/ASTConsumers.cpp | 32 ------------------------ lib/Frontend/CompilerInvocation.cpp | 4 +-- lib/Frontend/FrontendActions.cpp | 5 ---- lib/Sema/ParseAST.cpp | 24 ++++++++++++++++++ tools/driver/cc1_main.cpp | 1 - 10 files changed, 31 insertions(+), 56 deletions(-) diff --git a/include/clang/Basic/LangOptions.h b/include/clang/Basic/LangOptions.h index fdf69d063f..1dfc7a1dfa 100644 --- a/include/clang/Basic/LangOptions.h +++ b/include/clang/Basic/LangOptions.h @@ -98,8 +98,8 @@ public: unsigned ElideConstructors : 1; // Whether C++ copy constructors should be // elided if possible. unsigned CatchUndefined : 1; // Generate code to check for undefined ops. - unsigned DumpVtableLayouts : 1; // Dump the layouts of all the emitted - // vtables. + unsigned DumpRecordLayouts : 1; /// Dump the layout of IRgen'd records. + unsigned DumpVtableLayouts : 1; /// Dump the layouts of emitted vtables. private: unsigned GC : 2; // Objective-C Garbage Collection modes. We // declare this enum as unsigned because MSVC @@ -169,6 +169,7 @@ public: CharIsSigned = 1; ShortWChar = 0; CatchUndefined = 0; + DumpRecordLayouts = 0; DumpVtableLayouts = 0; } diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td index 93cf495b52..3d730153be 100644 --- a/include/clang/Driver/CC1Options.td +++ b/include/clang/Driver/CC1Options.td @@ -285,8 +285,6 @@ def ast_view : Flag<"-ast-view">, HelpText<"Build ASTs and view them with GraphViz">; def print_decl_contexts : Flag<"-print-decl-contexts">, HelpText<"Print DeclContexts and their Decls">; -def dump_record_layouts : Flag<"-dump-record-layouts">, - HelpText<"Dump record layout information">; def emit_pth : Flag<"-emit-pth">, HelpText<"Generate pre-tokenized header file">; def emit_pch : Flag<"-emit-pch">, @@ -317,6 +315,9 @@ def print_stats : Flag<"-print-stats">, def ftime_report : Flag<"-ftime-report">, HelpText<"Print the amount of time each phase of compilation takes">; +def dump_record_layouts : Flag<"-dump-record-layouts">, + HelpText<"Dump record layout information">; + //===----------------------------------------------------------------------===// // Language Options //===----------------------------------------------------------------------===// diff --git a/include/clang/Frontend/ASTConsumers.h b/include/clang/Frontend/ASTConsumers.h index b5b09f536d..9163a208de 100644 --- a/include/clang/Frontend/ASTConsumers.h +++ b/include/clang/Frontend/ASTConsumers.h @@ -57,10 +57,6 @@ 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, diff --git a/include/clang/Frontend/FrontendActions.h b/include/clang/Frontend/FrontendActions.h index a7b6aa7e75..8c9ebca887 100644 --- a/include/clang/Frontend/FrontendActions.h +++ b/include/clang/Frontend/FrontendActions.h @@ -73,12 +73,6 @@ protected: llvm::StringRef InFile); }; -class DumpRecordAction : public ASTFrontendAction { -protected: - virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI, - llvm::StringRef InFile); -}; - class FixItAction : public ASTFrontendAction { private: llvm::OwningPtr Rewriter; diff --git a/include/clang/Frontend/FrontendOptions.h b/include/clang/Frontend/FrontendOptions.h index ee3811a30b..7b4df1f667 100644 --- a/include/clang/Frontend/FrontendOptions.h +++ b/include/clang/Frontend/FrontendOptions.h @@ -24,7 +24,6 @@ namespace frontend { ASTPrintXML, ///< Parse ASTs and print them in XML. ASTView, ///< Parse ASTs and view them in Graphviz. DumpRawTokens, ///< Dump out raw tokens. - DumpRecordLayouts, ///< Dump record layout information. DumpTokens, ///< Dump out preprocessed tokens. EmitAssembly, ///< Emit a .s file. EmitBC, ///< Emit a .bc file. diff --git a/lib/Frontend/ASTConsumers.cpp b/lib/Frontend/ASTConsumers.cpp index 9186e4572f..b53a80e47b 100644 --- a/lib/Frontend/ASTConsumers.cpp +++ b/lib/Frontend/ASTConsumers.cpp @@ -435,38 +435,6 @@ ASTConsumer *clang::CreateDeclContextPrinter() { return new DeclContextPrinter(); } -//===----------------------------------------------------------------------===// -/// RecordLayoutDumper - C++ Record Layout Dumping. -namespace { -class RecordLayoutDumper : public ASTConsumer { -public: - RecordLayoutDumper() {} - - void HandleTranslationUnit(ASTContext &C) { - for (ASTContext::type_iterator I = C.types_begin(), E = C.types_end(); - I != E; ++I) { - const RecordType *RT = dyn_cast(*I); - if (!RT) - continue; - - const CXXRecordDecl *RD = dyn_cast(RT->getDecl()); - if (!RD || RD->isImplicit() || RD->isDependentType() || - RD->isInvalidDecl() || !RD->getDefinition()) - continue; - - // FIXME: Do we really need to hard code this? - if (RD->getQualifiedNameAsString() == "__va_list_tag") - continue; - - C.DumpRecordLayout(RD, llvm::errs()); - } - } -}; -} // end anonymous namespace -ASTConsumer *clang::CreateRecordLayoutDumper() { - return new RecordLayoutDumper(); -} - //===----------------------------------------------------------------------===// /// InheritanceViewer - C++ Inheritance Visualization diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 8aaef80b6e..0ab70a9c16 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -283,7 +283,6 @@ static const char *getActionName(frontend::ActionKind Kind) { case frontend::ASTPrintXML: return "-ast-print-xml"; case frontend::ASTView: return "-ast-view"; case frontend::DumpRawTokens: return "-dump-raw-tokens"; - case frontend::DumpRecordLayouts: return "-dump-record-layouts"; case frontend::DumpTokens: return "-dump-tokens"; case frontend::EmitAssembly: return "-S"; case frontend::EmitBC: return "-emit-llvm-bc"; @@ -865,8 +864,6 @@ ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args, Diagnostic &Diags) { Opts.ProgramAction = frontend::ASTView; break; case OPT_dump_raw_tokens: Opts.ProgramAction = frontend::DumpRawTokens; break; - case OPT_dump_record_layouts: - Opts.ProgramAction = frontend::DumpRecordLayouts; break; case OPT_dump_tokens: Opts.ProgramAction = frontend::DumpTokens; break; case OPT_S: @@ -1208,6 +1205,7 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, Opts.PICLevel = getLastArgIntValue(Args, OPT_pic_level, 0, Diags); Opts.SjLjExceptions = Args.hasArg(OPT_fsjlj_exceptions); Opts.Static = Args.hasArg(OPT_static_define); + Opts.DumpRecordLayouts = Args.hasArg(OPT_dump_record_layouts); Opts.DumpVtableLayouts = Args.hasArg(OPT_fdump_vtable_layouts); Opts.OptimizeSize = 0; diff --git a/lib/Frontend/FrontendActions.cpp b/lib/Frontend/FrontendActions.cpp index 87badc7711..6d7c6a8460 100644 --- a/lib/Frontend/FrontendActions.cpp +++ b/lib/Frontend/FrontendActions.cpp @@ -74,11 +74,6 @@ ASTConsumer *DeclContextPrintAction::CreateASTConsumer(CompilerInstance &CI, return CreateDeclContextPrinter(); } -ASTConsumer *DumpRecordAction::CreateASTConsumer(CompilerInstance &CI, - llvm::StringRef InFile) { - return CreateRecordLayoutDumper(); -} - ASTConsumer *GeneratePCHAction::CreateASTConsumer(CompilerInstance &CI, llvm::StringRef InFile) { const std::string &Sysroot = CI.getHeaderSearchOpts().Sysroot; diff --git a/lib/Sema/ParseAST.cpp b/lib/Sema/ParseAST.cpp index 7cd39895f6..f620927a8d 100644 --- a/lib/Sema/ParseAST.cpp +++ b/lib/Sema/ParseAST.cpp @@ -24,6 +24,26 @@ using namespace clang; +static void DumpRecordLayouts(ASTContext &C) { + for (ASTContext::type_iterator I = C.types_begin(), E = C.types_end(); + I != E; ++I) { + const RecordType *RT = dyn_cast(*I); + if (!RT) + continue; + + const CXXRecordDecl *RD = dyn_cast(RT->getDecl()); + if (!RD || RD->isImplicit() || RD->isDependentType() || + RD->isInvalidDecl() || !RD->getDefinition()) + continue; + + // FIXME: Do we really need to hard code this? + if (RD->getQualifiedNameAsString() == "__va_list_tag") + continue; + + C.DumpRecordLayout(RD, llvm::errs()); + } +} + //===----------------------------------------------------------------------===// // Public interface to the file //===----------------------------------------------------------------------===// @@ -82,6 +102,10 @@ void clang::ParseAST(Preprocessor &PP, ASTConsumer *Consumer, E = S.WeakTopLevelDecls().end(); I != E; ++I) Consumer->HandleTopLevelDecl(DeclGroupRef(*I)); + // Dump record layouts, if requested. + if (PP.getLangOptions().DumpRecordLayouts) + DumpRecordLayouts(Ctx); + Consumer->HandleTranslationUnit(Ctx); if (ExternalSemaSource *ESS = diff --git a/tools/driver/cc1_main.cpp b/tools/driver/cc1_main.cpp index d329c525ac..e9663f4bbc 100644 --- a/tools/driver/cc1_main.cpp +++ b/tools/driver/cc1_main.cpp @@ -64,7 +64,6 @@ static FrontendAction *CreateFrontendBaseAction(CompilerInstance &CI) { case ASTPrintXML: return new ASTPrintXMLAction(); case ASTView: return new ASTViewAction(); case DumpRawTokens: return new DumpRawTokensAction(); - case DumpRecordLayouts: return new DumpRecordAction(); case DumpTokens: return new DumpTokensAction(); case EmitAssembly: return new EmitAssemblyAction(); case EmitBC: return new EmitBCAction(); -- 2.40.0