Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 1 | //===--- Tools.cpp - Tools Implementations ------------------------------*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "Tools.h" |
| 11 | |
Daniel Dunbar | 871adcf | 2009-03-18 07:06:02 +0000 | [diff] [blame] | 12 | #include "clang/Driver/Arg.h" |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 13 | #include "clang/Driver/ArgList.h" |
Daniel Dunbar | 871adcf | 2009-03-18 07:06:02 +0000 | [diff] [blame] | 14 | #include "clang/Driver/Compilation.h" |
| 15 | #include "clang/Driver/Job.h" |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 16 | #include "clang/Driver/HostInfo.h" |
| 17 | #include "clang/Driver/Option.h" |
| 18 | #include "clang/Driver/ToolChain.h" |
Daniel Dunbar | 871adcf | 2009-03-18 07:06:02 +0000 | [diff] [blame] | 19 | #include "clang/Driver/Util.h" |
| 20 | |
| 21 | #include "llvm/ADT/SmallVector.h" |
| 22 | |
| 23 | #include "InputInfo.h" |
| 24 | |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 25 | using namespace clang::driver; |
| 26 | using namespace clang::driver::tools; |
| 27 | |
| 28 | void Clang::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 871adcf | 2009-03-18 07:06:02 +0000 | [diff] [blame] | 29 | Job &Dest, |
| 30 | const InputInfo &Output, |
Daniel Dunbar | 62cf601 | 2009-03-18 06:07:59 +0000 | [diff] [blame] | 31 | const InputInfoList &Inputs, |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 32 | const ArgList &TCArgs, |
| 33 | const char *LinkingOutput) const { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 34 | ArgStringList CmdArgs; |
| 35 | |
| 36 | for (InputInfoList::const_iterator |
| 37 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 38 | const InputInfo &II = *it; |
| 39 | if (II.isPipe()) |
| 40 | CmdArgs.push_back("-"); |
| 41 | else |
| 42 | CmdArgs.push_back(II.getInputFilename()); |
| 43 | } |
| 44 | |
| 45 | if (Output.isPipe()) { |
| 46 | CmdArgs.push_back("-o"); |
| 47 | CmdArgs.push_back("-"); |
| 48 | } else if (const char *N = Output.getInputFilename()) { |
| 49 | CmdArgs.push_back("-o"); |
| 50 | CmdArgs.push_back(N); |
| 51 | } |
| 52 | |
| 53 | Dest.addCommand(new Command("clang", CmdArgs)); |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 54 | } |
| 55 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 56 | void gcc::Common::ConstructJob(Compilation &C, const JobAction &JA, |
| 57 | Job &Dest, |
| 58 | const InputInfo &Output, |
| 59 | const InputInfoList &Inputs, |
| 60 | const ArgList &TCArgs, |
| 61 | const char *LinkingOutput) const { |
| 62 | ArgStringList CmdArgs; |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 63 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 64 | for (ArgList::const_iterator |
| 65 | it = TCArgs.begin(), ie = TCArgs.end(); it != ie; ++it) { |
| 66 | Arg *A = *it; |
| 67 | if (A->getOption().hasForwardToGCC()) |
| 68 | A->render(TCArgs, CmdArgs); |
| 69 | } |
| 70 | |
| 71 | RenderExtraToolArgs(CmdArgs); |
| 72 | |
| 73 | // If using a driver driver, force the arch. |
| 74 | if (getToolChain().getHost().useDriverDriver()) { |
| 75 | CmdArgs.push_back("-arch"); |
| 76 | CmdArgs.push_back(getToolChain().getArchName().c_str()); |
| 77 | } |
| 78 | |
| 79 | if (Output.isPipe()) { |
| 80 | CmdArgs.push_back("-o"); |
| 81 | CmdArgs.push_back("-"); |
| 82 | } else if (const char *N = Output.getInputFilename()) { |
| 83 | CmdArgs.push_back("-o"); |
| 84 | CmdArgs.push_back(N); |
| 85 | } else |
| 86 | CmdArgs.push_back("-fsyntax-only"); |
| 87 | |
| 88 | |
| 89 | // Only pass -x if gcc will understand it; otherwise hope gcc |
| 90 | // understands the suffix correctly. The main use case this would go |
| 91 | // wrong in is for linker inputs if they happened to have an odd |
| 92 | // suffix; really the only way to get this to happen is a command |
| 93 | // like '-x foobar a.c' which will treat a.c like a linker input. |
| 94 | // |
| 95 | // FIXME: For the linker case specifically, can we safely convert |
| 96 | // inputs into '-Wl,' options? |
| 97 | for (InputInfoList::const_iterator |
| 98 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 99 | const InputInfo &II = *it; |
| 100 | if (types::canTypeBeUserSpecified(II.getType())) { |
| 101 | CmdArgs.push_back("-x"); |
| 102 | CmdArgs.push_back(types::getTypeName(II.getType())); |
| 103 | } |
| 104 | |
| 105 | if (II.isPipe()) |
| 106 | CmdArgs.push_back("-"); |
| 107 | else |
| 108 | // FIXME: Linker inputs |
| 109 | CmdArgs.push_back(II.getInputFilename()); |
| 110 | } |
| 111 | |
| 112 | Dest.addCommand(new Command("gcc", CmdArgs)); |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 113 | } |
| 114 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 115 | void gcc::Preprocess::RenderExtraToolArgs(ArgStringList &CmdArgs) const { |
| 116 | CmdArgs.push_back("-E"); |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 117 | } |
| 118 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 119 | void gcc::Precompile::RenderExtraToolArgs(ArgStringList &CmdArgs) const { |
| 120 | // The type is good enough. |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 121 | } |
| 122 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 123 | void gcc::Compile::RenderExtraToolArgs(ArgStringList &CmdArgs) const { |
| 124 | CmdArgs.push_back("-S"); |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 125 | } |
| 126 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 127 | void gcc::Assemble::RenderExtraToolArgs(ArgStringList &CmdArgs) const { |
| 128 | CmdArgs.push_back("-c"); |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 129 | } |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 130 | |
| 131 | void gcc::Link::RenderExtraToolArgs(ArgStringList &CmdArgs) const { |
| 132 | // The types are (hopefully) good enough. |
| 133 | } |
| 134 | |