aboutsummaryrefslogtreecommitdiff
path: root/clang
diff options
context:
space:
mode:
authorRoman Divacky <rdivacky@freebsd.org>2012-12-13 16:09:42 +0000
committerRoman Divacky <rdivacky@freebsd.org>2012-12-13 16:09:42 +0000
commitd93c8c008efe57266df832b5e401df821cdd48bd (patch)
tree491506a6aa0b7bb9a605f06940e217fe3f0dd1ab /clang
parentf2bb66b7180f515595e3c106c29bd3dd8cac8d98 (diff)
downloadllvm-d93c8c008efe57266df832b5e401df821cdd48bd.zip
llvm-d93c8c008efe57266df832b5e401df821cdd48bd.tar.gz
llvm-d93c8c008efe57266df832b5e401df821cdd48bd.tar.bz2
Dont use/link ARCMT, StaticAnalyzer and Rewriter to clang when the user
specifies not to. Dont build ASTMatchers with Rewriter disabled and StaticAnalyzer when it's disabled. Without all those three, the clang binary shrinks (x86_64) from ~36MB to ~32MB (unstripped). llvm-svn: 170135
Diffstat (limited to 'clang')
-rw-r--r--clang/include/clang/Basic/DiagnosticFrontendKinds.td2
-rw-r--r--clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp46
-rw-r--r--clang/lib/FrontendTool/Makefile15
-rwxr-xr-xclang/lib/Makefile18
-rw-r--r--clang/tools/driver/Makefile22
-rw-r--r--clang/unittests/Makefile16
6 files changed, 106 insertions, 13 deletions
diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index 84c1345..13641c1 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -60,6 +60,8 @@ def warn_fe_cc_log_diagnostics_failure : Warning<
"unable to open CC_LOG_DIAGNOSTICS file: %0 (using stderr)">;
def err_fe_no_pch_in_dir : Error<
"no suitable precompiled header file found in directory '%0'">;
+def err_fe_action_not_available : Error<
+ "action %0 not compiled in">;
def warn_fe_serialized_diag_failure : Warning<
"unable to open file %0 for serializing diagnostics (%1)">,
diff --git a/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp b/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
index aea5b08..8cc2592 100644
--- a/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ b/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -31,6 +31,7 @@ using namespace clang;
static FrontendAction *CreateFrontendBaseAction(CompilerInstance &CI) {
using namespace clang::frontend;
+ StringRef Action("unknown");
switch (CI.getFrontendOpts().ProgramAction) {
case ASTDeclList: return new ASTDeclListAction();
@@ -42,12 +43,20 @@ static FrontendAction *CreateFrontendBaseAction(CompilerInstance &CI) {
case DumpTokens: return new DumpTokensAction();
case EmitAssembly: return new EmitAssemblyAction();
case EmitBC: return new EmitBCAction();
+#ifdef CLANG_ENABLE_REWRITER
case EmitHTML: return new HTMLPrintAction();
+#else
+ case EmitHTML: Action = "EmitHTML"; break;
+#endif
case EmitLLVM: return new EmitLLVMAction();
case EmitLLVMOnly: return new EmitLLVMOnlyAction();
case EmitCodeGenOnly: return new EmitCodeGenOnlyAction();
case EmitObj: return new EmitObjAction();
+#ifdef CLANG_ENABLE_REWRITER
case FixIt: return new FixItAction();
+#else
+ case FixIt: Action = "FixIt"; break;
+#endif
case GenerateModule: return new GenerateModuleAction;
case GeneratePCH: return new GeneratePCHAction;
case GeneratePTH: return new GeneratePTHAction();
@@ -74,19 +83,46 @@ static FrontendAction *CreateFrontendBaseAction(CompilerInstance &CI) {
case PrintDeclContext: return new DeclContextPrintAction();
case PrintPreamble: return new PrintPreambleAction();
case PrintPreprocessedInput: {
- if (CI.getPreprocessorOutputOpts().RewriteIncludes)
+ if (CI.getPreprocessorOutputOpts().RewriteIncludes) {
+#ifdef CLANG_ENABLE_REWRITER
return new RewriteIncludesAction();
+#else
+ Action = "RewriteIncludesAction";
+ break;
+#endif
+ }
return new PrintPreprocessedAction();
}
+#ifdef CLANG_ENABLE_REWRITER
case RewriteMacros: return new RewriteMacrosAction();
case RewriteObjC: return new RewriteObjCAction();
case RewriteTest: return new RewriteTestAction();
- case RunAnalysis: return new ento::AnalysisAction();
+#else
+ case RewriteMacros: Action = "RewriteMacros"; break;
+ case RewriteObjC: Action = "RewriteObjC"; break;
+ case RewriteTest: Action = "RewriteTest"; break;
+#endif
+#ifdef CLANG_ENABLE_ARCMT
case MigrateSource: return new arcmt::MigrateSourceAction();
+#else
+ case MigrateSource: Action = "MigrateSource"; break;
+#endif
+#ifdef CLANG_ENABLE_STATIC_ANALYZER
+ case RunAnalysis: return new ento::AnalysisAction();
+#else
+ case RunAnalysis: Action = "RunAnalysis"; break;
+#endif
case RunPreprocessorOnly: return new PreprocessOnlyAction();
}
+
+#if !defined(CLANG_ENABLE_ARCMT) || !defined(CLANG_ENABLE_STATIC_ANALYZER) \
+ || !defined(CLANG_ENABLE_REWRITER)
+ CI.getDiagnostics().Report(diag::err_fe_action_not_available) << Action;
+ return 0;
+#else
llvm_unreachable("Invalid program action!");
+#endif
}
static FrontendAction *CreateFrontendAction(CompilerInstance &CI) {
@@ -97,10 +133,13 @@ static FrontendAction *CreateFrontendAction(CompilerInstance &CI) {
const FrontendOptions &FEOpts = CI.getFrontendOpts();
+#ifdef CLANG_ENABLE_REWRITER
if (FEOpts.FixAndRecompile) {
Act = new FixItRecompile(Act);
}
+#endif
+#ifdef CLANG_ENABLE_ARCMT
// Potentially wrap the base FE action in an ARC Migrate Tool action.
switch (FEOpts.ARCMTAction) {
case FrontendOptions::ARCMT_None:
@@ -124,6 +163,7 @@ static FrontendAction *CreateFrontendAction(CompilerInstance &CI) {
FEOpts.ObjCMTAction & ~FrontendOptions::ObjCMT_Literals,
FEOpts.ObjCMTAction & ~FrontendOptions::ObjCMT_Subscripting);
}
+#endif
// If there are any AST files to merge, create a frontend action
// adaptor to perform the merge.
@@ -176,12 +216,14 @@ bool clang::ExecuteCompilerInvocation(CompilerInstance *Clang) {
llvm::cl::ParseCommandLineOptions(NumArgs + 1, Args);
}
+#ifdef CLANG_ENABLE_STATIC_ANALYZER
// Honor -analyzer-checker-help.
// This should happen AFTER plugins have been loaded!
if (Clang->getAnalyzerOpts()->ShowCheckerHelp) {
ento::printCheckerHelp(llvm::outs(), Clang->getFrontendOpts().Plugins);
return 0;
}
+#endif
// If there were errors in processing arguments, don't do anything else.
bool Success = false;
diff --git a/clang/lib/FrontendTool/Makefile b/clang/lib/FrontendTool/Makefile
index c43213f..9ce4b76 100644
--- a/clang/lib/FrontendTool/Makefile
+++ b/clang/lib/FrontendTool/Makefile
@@ -11,3 +11,18 @@ CLANG_LEVEL := ../..
LIBRARYNAME := clangFrontendTool
include $(CLANG_LEVEL)/Makefile
+include $(CLANG_LEVEL)/../../Makefile.config
+
+ifeq ($(ENABLE_CLANG_ARCMT),1)
+ CXX.Flags += -DCLANG_ENABLE_ARCMT
+endif
+
+ifeq ($(ENABLE_CLANG_REWRITER),1)
+ CXX.Flags += -DCLANG_ENABLE_REWRITER
+endif
+
+ifeq ($(ENABLE_CLANG_STATIC_ANALYZER),1)
+ CXX.Flags += -DCLANG_ENABLE_STATIC_ANALYZER
+endif
+
+
diff --git a/clang/lib/Makefile b/clang/lib/Makefile
index 17db50e..2e32dfe 100755
--- a/clang/lib/Makefile
+++ b/clang/lib/Makefile
@@ -8,9 +8,19 @@
##===----------------------------------------------------------------------===##
CLANG_LEVEL := ..
-PARALLEL_DIRS = Headers Basic Lex Parse AST ASTMatchers Sema CodeGen Analysis \
- StaticAnalyzer Edit Rewrite ARCMigrate Serialization Frontend \
- FrontendTool Tooling Driver Format
+# ARCMigrate and Rewrite are always needed because of libclang.
+PARALLEL_DIRS = Headers Basic Lex Parse AST Sema CodeGen Analysis Frontend \
+ FrontendTool Tooling Driver Format Edit ARCMigrate Rewrite \
+ Serialization
-include $(CLANG_LEVEL)/Makefile
+include $(CLANG_LEVEL)/../../Makefile.config
+
+ifeq ($(ENABLE_CLANG_REWRITER),1)
+PARALLEL_DIRS += ASTMatchers
+endif
+ifeq ($(ENABLE_CLANG_STATIC_ANALYZER),1)
+PARALLEL_DIRS += StaticAnalyzer
+endif
+
+include $(CLANG_LEVEL)/Makefile
diff --git a/clang/tools/driver/Makefile b/clang/tools/driver/Makefile
index 1ff3c50..ee8f135 100644
--- a/clang/tools/driver/Makefile
+++ b/clang/tools/driver/Makefile
@@ -32,12 +32,22 @@ include $(CLANG_LEVEL)/../../Makefile.config
LINK_COMPONENTS := $(TARGETS_TO_BUILD) asmparser bitreader bitwriter codegen \
instrumentation ipo linker selectiondag
USEDLIBS = clangFrontendTool.a clangFrontend.a clangDriver.a \
- clangSerialization.a clangCodeGen.a clangParse.a clangSema.a \
- clangStaticAnalyzerFrontend.a clangStaticAnalyzerCheckers.a \
- clangStaticAnalyzerCore.a \
- clangAnalysis.a clangARCMigrate.a \
- clangRewriteFrontend.a clangRewriteCore.a \
- clangEdit.a clangAST.a clangLex.a clangBasic.a
+ clangSerialization.a clangCodeGen.a clangParse.a clangSema.a
+
+ifeq ($(ENABLE_CLANG_STATIC_ANALYZER),1)
+USEDLIBS += clangStaticAnalyzerFrontend.a clangStaticAnalyzerCheckers.a \
+ clangStaticAnalyzerCore.a
+endif
+
+ifeq ($(ENABLE_CLANG_ARCMT),1)
+USEDLIBS += clangARCMigrate.a
+endif
+
+ifeq ($(ENABLE_CLANG_REWRITER),1)
+USEDLIBS += clangRewriteFrontend.a clangRewriteCore.a
+endif
+
+USEDLIBS += clangAnalysis.a clangEdit.a clangAST.a clangBasic.a clangLex.a
include $(CLANG_LEVEL)/Makefile
diff --git a/clang/unittests/Makefile b/clang/unittests/Makefile
index 799bc55..e01a6ac 100644
--- a/clang/unittests/Makefile
+++ b/clang/unittests/Makefile
@@ -14,7 +14,21 @@ ifndef CLANG_LEVEL
IS_UNITTEST_LEVEL := 1
CLANG_LEVEL := ..
-PARALLEL_DIRS = ASTMatchers Basic AST Frontend Lex Tooling Format
+PARALLEL_DIRS = Basic Lex
+
+include $(CLANG_LEVEL)/../..//Makefile.config
+
+ifeq ($(ENABLE_CLANG_REWRITER),1)
+PARALLEL_DIRS += Format
+endif
+
+ifeq ($(ENABLE_CLANG_REWRITER),1)
+PARALLEL_DIRS += ASTMatchers AST Tooling
+endif
+
+ifeq ($(ENABLE_CLANG_STATIC_ANALYZER),1)
+PARALLEL_DIRS += Frontend
+endif
endif # CLANG_LEVEL