From: Daniel Dunbar Date: Wed, 3 Feb 2010 03:07:56 +0000 (+0000) Subject: Driver: Add -[no-]integrated-as for clang. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8767cbc475ed96397b6f08617814eeb9cab121bd;p=clang Driver: Add -[no-]integrated-as for clang. - Requires backend support, which only exists for i386--darwin currently. No 'as' required: -- ddunbar@ozzy:tmp$ cat t.c int main() { return 42; } ddunbar@ozzy:tmp$ clang -m32 -integrated-as t.c ddunbar@ozzy:tmp$ ./a.out; echo $? 42 ddunbar@ozzy:tmp$ -- The random extra whitespace is how you know its working! :) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95194 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index 881ca0381b..dbdddf4eb3 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -377,6 +377,7 @@ def image__base : Separate<"-image_base">; def include_ : JoinedOrSeparate<"-include">, Group, EnumName<"include">; def init : Separate<"-init">; def install__name : Separate<"-install_name">; +def integrated_as : Flag<"-integrated-as">, Flags<[DriverOption]>; def iprefix : JoinedOrSeparate<"-iprefix">, Group; def iquote : JoinedOrSeparate<"-iquote">, Group; def isysroot : JoinedOrSeparate<"-isysroot">, Group; @@ -444,6 +445,7 @@ def m_Joined : Joined<"-m">, Group; def no_canonical_prefixes : Flag<"-no-canonical-prefixes">, Flags<[DriverOption, HelpHidden]>, HelpText<"Use relative instead of canonical paths">; def no_cpp_precomp : Flag<"-no-cpp-precomp">; +def no_integrated_as : Flag<"-no-integrated-as">, Flags<[DriverOption]>; def no_integrated_cpp : Flag<"-no-integrated-cpp">, Flags<[DriverOption]>; def no__dead__strip__inits__and__terms : Flag<"-no_dead_strip_inits_and_terms">; def nobuiltininc : Flag<"-nobuiltininc">; diff --git a/include/clang/Driver/Tool.h b/include/clang/Driver/Tool.h index 8a89f01e0f..851e4235b0 100644 --- a/include/clang/Driver/Tool.h +++ b/include/clang/Driver/Tool.h @@ -45,6 +45,7 @@ public: virtual bool acceptsPipedInput() const = 0; virtual bool canPipeOutput() const = 0; + virtual bool hasIntegratedAssembler() const { return false; } virtual bool hasIntegratedCPP() const = 0; /// ConstructJob - Construct jobs to perform the action \arg JA, diff --git a/include/clang/Driver/ToolChain.h b/include/clang/Driver/ToolChain.h index c4209ac3ba..669d64263d 100644 --- a/include/clang/Driver/ToolChain.h +++ b/include/clang/Driver/ToolChain.h @@ -90,6 +90,10 @@ public: /// IsBlocksDefault - Does this tool chain enable -fblocks by default. virtual bool IsBlocksDefault() const { return false; } + /// IsIntegratedAssemblerDefault - Does this tool chain enable -integrated-as + /// by default. + virtual bool IsIntegratedAssemblerDefault() const { return false; } + /// IsObjCNonFragileABIDefault - Does this tool chain set /// -fobjc-nonfragile-abi by default. virtual bool IsObjCNonFragileABIDefault() const { return false; } diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index 62c2d12cd3..a2fc5aa08d 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -865,6 +865,44 @@ void Driver::BuildJobs(Compilation &C) const { } } +static const Tool &SelectToolForJob(Compilation &C, const ToolChain *TC, + const JobAction *JA, + const ActionList *&Inputs) { + const Tool *ToolForJob = 0; + + // See if we should look for a compiler with an integrated assembler. We match + // bottom up, so what we are actually looking for is an assembler job with a + // compiler input. + if (C.getArgs().hasArg(options::OPT_integrated_as, + options::OPT_no_integrated_as, + TC->IsIntegratedAssemblerDefault()) && + !C.getArgs().hasArg(options::OPT_save_temps) && + isa(JA) && + Inputs->size() == 1 && isa(*Inputs->begin())) { + const Tool &Compiler = TC->SelectTool(C,cast(**Inputs->begin())); + if (Compiler.hasIntegratedAssembler()) { + Inputs = &(*Inputs)[0]->getInputs(); + ToolForJob = &Compiler; + } + } + + // Otherwise use the tool for the current job. + if (!ToolForJob) + ToolForJob = &TC->SelectTool(C, *JA); + + // See if we should use an integrated preprocessor. We do so when we have + // exactly one input, since this is the only use case we care about + // (irrelevant since we don't support combine yet). + if (Inputs->size() == 1 && isa(*Inputs->begin()) && + !C.getArgs().hasArg(options::OPT_no_integrated_cpp) && + !C.getArgs().hasArg(options::OPT_traditional_cpp) && + !C.getArgs().hasArg(options::OPT_save_temps) && + ToolForJob->hasIntegratedCPP()) + Inputs = &(*Inputs)[0]->getInputs(); + + return *ToolForJob; +} + void Driver::BuildJobsForAction(Compilation &C, const Action *A, const ToolChain *TC, @@ -905,21 +943,10 @@ void Driver::BuildJobsForAction(Compilation &C, return; } - const JobAction *JA = cast(A); - const Tool &T = TC->SelectTool(C, *JA); - - // See if we should use an integrated preprocessor. We do so when we have - // exactly one input, since this is the only use case we care about - // (irrelevant since we don't support combine yet). const ActionList *Inputs = &A->getInputs(); - if (Inputs->size() == 1 && isa(*Inputs->begin())) { - if (!C.getArgs().hasArg(options::OPT_no_integrated_cpp) && - !C.getArgs().hasArg(options::OPT_traditional_cpp) && - !C.getArgs().hasArg(options::OPT_save_temps) && - T.hasIntegratedCPP()) { - Inputs = &(*Inputs)[0]->getInputs(); - } - } + + const JobAction *JA = cast(A); + const Tool &T = SelectToolForJob(C, TC, JA, Inputs); // Only use pipes when there is exactly one input. bool TryToUsePipeInput = Inputs->size() == 1 && T.acceptsPipedInput(); diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index b0278b8aec..df8c11837e 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -651,6 +651,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back("-Eonly"); else CmdArgs.push_back("-E"); + } else if (isa(JA)) { + CmdArgs.push_back("-emit-obj"); } else if (isa(JA)) { // Use PCH if the user requested it, except for C++ (for now). bool UsePCH = D.CCCUsePCH; diff --git a/lib/Driver/Tools.h b/lib/Driver/Tools.h index 572c7f4e78..db596417a9 100644 --- a/lib/Driver/Tools.h +++ b/lib/Driver/Tools.h @@ -41,6 +41,7 @@ namespace tools { virtual bool acceptsPipedInput() const { return true; } virtual bool canPipeOutput() const { return true; } + virtual bool hasIntegratedAssembler() const { return true; } virtual bool hasIntegratedCPP() const { return true; } virtual void ConstructJob(Compilation &C, const JobAction &JA,