Commit Graph

270 Commits

Author SHA1 Message Date
Jordan Rose
e715940241 [Driver] Teach "swift -i" and "swift -repl" to default to the current OS X SDK.
This only works when swift is packaged with Xcode or installed as a command
line tool, but those are the important cases.

<rdar://problem/14395800>, again.

Swift SVN r18757
2014-06-09 21:29:08 +00:00
Jordan Rose
9e492a508f [Driver] Don't crash when an input file has unknown type.
If we can't determine the type of an input file, we assume it's a linker
input of some sort (like Clang does). However, if we're not actually linking,
this resulted in unused inputs, which the driver choked on.

This commit updates the driver to throw away (and diagnose) inputs that
aren't going to be compiled if they aren't going to be used later on.
It also checks that none of our non-object output types are being treated
as linker inputs, since we do have that information around.

<rdar://problem/16019895>

Swift SVN r18667
2014-05-30 01:44:03 +00:00
Jordan Rose
780c6bd87a [Driver] Turn on the LLDB REPL by default!
You can use -integrated-repl to access the previous REPL implementation.

<rdar://problem/16776719>

Swift SVN r18084
2014-05-14 23:23:16 +00:00
Jordan Rose
67f319b747 [Driver] Hook up -emit-dependencies option, but don't do anything with it yet.
Part of <rdar://problem/14899639>

Swift SVN r18044
2014-05-14 00:34:07 +00:00
Jordan Rose
c6c6c6ef0f [Driver] Preserve .o files when compiling with debug info.
Since we don't generate dSYMs yet, this is the only way to create debuggable
binaries.

Thanks, Jim.

Swift SVN r17853
2014-05-10 22:34:35 +00:00
Jordan Rose
087e59eca8 [Driver] Delete temporary files unless -save-temps is passed.
If a temporary file is mentioned in the output map, it is also preserved.
We can make a nicer -save-temps later, but for now this will at least stop
leaving random files in /var/tmp.

<rdar://problem/16874893>

Swift SVN r17850
2014-05-10 21:58:23 +00:00
Jordan Rose
216d8b9521 fixup
Swift SVN r17794
2014-05-09 19:11:10 +00:00
Jordan Rose
737703b325 [Driver] Drop -working-directory option.
This wasn't hooked up correctly anyway. We can add it back if it becomes
important.

Swift SVN r17793
2014-05-09 19:11:10 +00:00
Jordan Rose
c941322ec1 [Driver] Clean up Options.td, including adding -version and -h.
(as aliases for --version and -help)

Clean-up of FrontendOptions.td to come soon.

Swift SVN r17792
2014-05-09 19:11:06 +00:00
Jordan Rose
9c6ddc085f [driver] Add -lldb-repl and -integrated-repl modes.
Since LLDB is taking over as the REPL for Swift, we eventually want "swift"
and "swift -repl" to invoke "lldb --repl" rather than the frontend. However,
we only want to do this if the LLDB that's present is related to the Swift
that's present -- we don't want to invoke some random LLDB on the system
or in some other Xcode installation. Therefore, Swift searches for LLDB--
first next to the driver, then in the usr/bin/ outside of a toolchain--
before choosing to use it.

If the user just passes -repl and an LLDB is not found relative to the
driver, the existing "integrated" REPL will be launched instead.*

If the user passes -lldb-repl and an LLDB is not found relative to the
driver, one from the user's PATH will be chosen (like the linker).

The user can also pass -integrated-repl to get the existing behavior.
"swift -frontend -repl" always uses the integrated REPL.

* Since LLDB's not quite ready to be the REPL yet, "swift -repl" still
invokes the integrated REPL. "swift -repl -experimental-prefer-lldb" tests
the new behavior; this option will become the default (and the flag removed)
in <rdar://problem/16776719>.

<rdar://problem/16776705>

Swift SVN r17134
2014-05-01 02:15:53 +00:00
John McCall
3cf3f42e98 When targeting arm64-apple-ios, the target CPU is cyclone,
which provides the Neon feature.  Do all the necessary
plumbing to get this from the driver to the backend.

Also, support -arch arm64, and diagnose bad -arch values
instead of silently ignoring them.  It's not clear to me
that we really want to support -arch as an alternative
to -target, but unless we rip it out or establish some
sort of real policy about it, it really ought to do
something approximating the right thing.

It would be nice if we could abstract enough of clang's
driver that we could re-use some of its basic logic about
tool chains and targets instaed of iteratively
rediscovering everything it does that's actually
critically important.

Swift SVN r16447
2014-04-17 06:36:03 +00:00
Dmitri Hrybenko
e50b52fa02 Serializer/Driver: serialize comments to separate .swiftdoc files
The driver infers the filename from the module file by replacing the extension,
and passes the explicit path to the swiftdoc file to the frontend.  But there
is no option in the driver to control emission of swiftdoc (it is always
emitted, and name is always inferred from the swiftmodule name).

The swiftdoc file consists of a single table that maps USRs to {brief comment,
raw comment}.  In order to look up a comment for decl we generate the USR
first.  We hope that the performance hit will not be that bad, because most
declarations come from Clang.  The advantage of this design is that the
swiftdoc file is not locked to the swiftmodule file, and can be updated,
replaced, and even localized.


Swift SVN r14914
2014-03-11 10:42:26 +00:00
Jordan Rose
798e13d15c Wire up -emit-objc-header[-path] options that don't do anything yet.
These options piggyback on the "merge module" phase of the driver
because the header we output needs an entire complete module.

Swift SVN r13800
2014-02-12 01:19:13 +00:00
Jordan Rose
d354c89a65 [driver] Continue treating a single input file as indicating a module "main".
...unless we know better (e.g. because the user passed -emit-library,
-parse-as-library, or -parse-stdlib).

Swift SVN r13767
2014-02-11 00:18:38 +00:00
Jordan Rose
c24a6a7b46 [driver] Disallow "swift" as a module name unless -parse-stdlib is passed.
I didn't bother duplicating this check in -frontend mode. I think that's
acceptable.

<rdar://problem/15083796>

Swift SVN r13759
2014-02-10 22:40:44 +00:00
Jordan Rose
0de8d19514 Define globals for the names of the stdlib, ObjectiveC, and Foundation modules.
This is mostly useful for the standard library, whose name is going to
change to "Swift" soon. (See <rdar://problem/15972383>.) But it's good DRY.

Swift SVN r13758
2014-02-10 22:40:42 +00:00
Jordan Rose
3747aa1008 [driver] Handle .o files and .swiftmodule files passed on the command line.
This isn't perfect, since /both/ show up as arguments to both the
module-merger and the linker. However, it gets the job done: each tool just
ignores the inputs it doesn't use.

Swift SVN r13470
2014-02-05 01:58:15 +00:00
Jordan Rose
6435b64d6a [driver] Write textual output to stdout if no -o option is given.
Swift SVN r13468
2014-02-05 01:34:44 +00:00
Jordan Rose
c08571901c [driver] Refactor output filename generation into a helper function.
Use early returns instead of nested ifs. No functionality change.

Swift SVN r13467
2014-02-05 01:34:43 +00:00
Jordan Rose
df1bb7dd54 Re-apply "[driver] Pass -Xfrontend options to the module-merge tool."
Re-apply r13400, reverted in r13405, with the test fixed to handle
SWIFT_NEW_DRIVER=OFF.

Swift SVN r13451
2014-02-04 22:46:46 +00:00
Michael Gottesman
c7e9c655f0 Revert "[driver] Pass -Xfrontend options to the module-merge tool."
This reverts commit r13400. This broke the build.

Swift SVN r13405
2014-02-04 05:48:51 +00:00
Jordan Rose
099d37830a [driver] Pass -Xfrontend options to the module-merge tool.
...and honor -o for -emit-module mode if we're not emitting any other kind
of output.

Swift SVN r13400
2014-02-04 01:32:46 +00:00
Jordan Rose
5fd7325c83 [driver] Don't crash when given an unknown argument!
Swift SVN r13267
2014-02-01 01:20:00 +00:00
Connor Wakamo
6f365157a9 [driver] Added support for specifying output levels.
Added an OutputLevel enum, which is used by Compilation to determine what kind
of output it should emit when performing Jobs.

In Driver::buildCompilation(), set the default OutputLevel for the Compilation
to Normal, but set it to Verbose if -v was passed. This means that, by default,
the driver will only print subtask output; this matches Clang's behavior.

Swift SVN r13255
2014-02-01 00:22:42 +00:00
Connor Wakamo
49d8d07224 [driver] Moved Command printing into Command::printCommandLine().
This was previously implemented in both Compilation::performJobsInList() and printJob().

Swift SVN r13253
2014-02-01 00:22:41 +00:00
Connor Wakamo
70b47ef783 [driver] Forward-declare DiagnosticEngine in Driver.h instead of including swift/ADT/DiagnosticEngine.h.
Also removed an unnecessary newline in the declaration of Driver’s constructor.

Swift SVN r13177
2014-01-30 22:42:19 +00:00
Connor Wakamo
0d483cdd88 [driver] Emit real diagnostics in the driver and integrated frontend instead of just printing to stderr.
Added DiagnosticsDriver.def and DiagnosticsDriver.h for driver-only diagnostics.
(Diagnostics which are shared with the frontend remain in
DiagnosticsFrontend.{def,h}.)

Added a DiagnosticEngine& to Compilation, so that it can emit diagnostics for
events which occur while performing Jobs.

Replaced all of the locations where we were manually printing error messages to
emitting real diagnostics, adding diagnostics if necessary.

Updated Driver::buildCompilation() so that it fails early if any errors were
encountered.

Updated test/Driver/actions.swift to pass a -module-name for multi-input tests.

Swift SVN r13175
2014-01-30 22:42:16 +00:00
Connor Wakamo
37d5f8d925 [driver] Do not issue an error if one of the multiple top-level outputs is a swiftmodule.
This will occur if -emit-{library,executable} and -emit-module is passed but -g
is not, since both the LinkJobAction and the MergeModuleJobAction will be
top-level actions.

Swift SVN r13139
2014-01-30 04:53:19 +00:00
Connor Wakamo
df76387cad [driver] Remove any preexisting diagnostics files before compilation.
Since the driver may create only some of the diagnostics files it was asked to
create, start by removing all diagnostics files so clients can detect the
presence of one to determine if the command which creates it actually ran.

This is important so that clients do not mix old and new diagnostics files,
which may occur in the event of a compilation error.

Swift SVN r13074
2014-01-28 23:52:40 +00:00
Jordan Rose
b77dccef4e [driver] Add the -emit-library option.
This emits a dynamic library as the final build product (rather than an
executable), as well as implicitly passing -parse-as-library to the frontend.

Swift SVN r12930
2014-01-24 19:46:39 +00:00
Jordan Rose
be735e5380 [driver] Only build a swiftmodule for debug purposes if we are linking.
Swift SVN r12926
2014-01-24 19:02:11 +00:00
Jordan Rose
76c04132c0 [driver] In -g mode, create the __SWIFT,__ast section used by the debugger.
The section contains a copy of the serialized module for the binary.

Swift SVN r12924
2014-01-24 18:42:08 +00:00
Jordan Rose
d24b212597 [driver] Use the input file name as the output executable name.
...when no -module-name or -o is provided.

This makes the single-file compile /very/ easy: compiling "foo.swift"
produces an output named "foo", rather than "a.out". For multi-file
modes, the module name is used if -o is missing; if no module name is
provided, it defaults to "main".

In a nutshell:
  explicit -o > explicit -module-name > single file's stem name > "main"

<rdar://problem/12593849>

Swift SVN r12841
2014-01-23 02:11:48 +00:00
Connor Wakamo
6384482902 [driver] Added support to honor the SDKROOT environment variable.
Centralized the driver-level handling of the SDK path in OutputInfo and
Driver::buildOutputInfo(), and added support for falling back to getenv(SDKROOT)
if -sdk wasn't passed (and SDKROOT is set in the environment).

Updated Swift::constructJob() to get the SDK path from the OutputInfo instead of
just passing -sdk from the original driver invocation.

Also added a driver-level check to ensure that the specified SDK is present;
if not, print out a warning. This fixes <rdar://problem/14409974>.

Added test/Driver/sdk.swift to test the -sdk and SDKROOT behavior, as well as
the nonexistent SDK warning.

Swift SVN r12815
2014-01-22 23:41:29 +00:00
Jordan Rose
c101e360a9 [driver] Use "const std::string &" instead of StringRef.
…for strings required to be null-terminated.

Swift SVN r12790
2014-01-22 21:56:24 +00:00
Connor Wakamo
ec0372f4bc [driver] Added support for using the OutputFileMap for determining output paths.
In Driver::buildJobsForAction(), consult the OutputFileMap if we're building a
Job for a CompileJobAction and we're not in SingleCompile mode.

Swift SVN r12774
2014-01-22 21:07:06 +00:00
Connor Wakamo
78dbfde1f9 [driver] Implemented support for -driver-print-output-file-map.
This option asks the driver to print its OutputFileMap.
To support this, added OutputFileMap::dump().

Swift SVN r12773
2014-01-22 21:07:06 +00:00
Connor Wakamo
77890aa5cc [driver] Added initial support for loading an OutputFileMap.
Added an -output-file-map option which will specify the path to an
OutputFileMap.

Added Driver::buildOutputFileMap(), which constructs an OutputFileMap
from the arguments.

Added OutputFileMap* parameters to Driver::buildJobs() and
Driver::buildJobsForAction(). (These parameters are not yet honored, except to
pass to calls of these functions.)

Swift SVN r12772
2014-01-22 21:07:05 +00:00
Connor Wakamo
b3e0b6574b [driver] Enhanced the output of -driver-print-bindings to print additional outputs.
Since a CommandOutput may have multiple outputs, print any additional outputs
after printing the primary output, using the following format:

... output: {<type>: "<primary output>", <type>: "<additional output>", ...}

Swift SVN r12690
2014-01-22 03:28:15 +00:00
Connor Wakamo
0a3202a46a [driver] Standardized the names of output-specifying options for secondary outputs.
The new format is "-<option>" and "-<option>-path". As a result:
  - Renamed -serialized-diagnostics-path to -serialize-diagnostics-path.
  - Renamed -module-output-path to -emit-module-path.

Swift SVN r12614
2014-01-20 23:16:22 +00:00
Connor Wakamo
66d4c813d4 [driver] Added serialized diagnostics as an additional output for compile commands.
Added a SerializedDiagnostics entry to Types.def.
In Driver::buildJobsForAction(), set an appropriate path for serialized
diagnostics, if requested. In Swift::constructJob(), check for an additional
SerializedDiagnostics output to determine if -serialize-diagnostics and
-serialized-diagnostics-path should be passed.

This is necessary infrastructure for the output file map.

Swift SVN r12613
2014-01-20 22:37:53 +00:00
Connor Wakamo
a982000175 [driver] Added a hidden -force-single-frontend-invocation option.
This sets OutputInfo::CompilerMode to a new SingleCompile mode, which in turn
causes the driver to create a single CompileJobAction for all inputs. This mode
also prevents the creation of a MergeModuleJobAction, since we can rely on the
frontend to generate a full swiftmodule.

This mode will allow the driver to properly compile the stdlib; if this mode is
necessary for other inputs, we can rename and publicize this option.

Swift SVN r12612
2014-01-20 21:47:17 +00:00
Connor Wakamo
4a79769742 [driver] Make CommandOutput::BaseInput into a bare StringRef, treating an empty reference as no value.
Swift SVN r12607
2014-01-20 19:26:50 +00:00
Connor Wakamo
abbef6bc3f [driver] A handful of fixes to make -v only display version info if no inputs are provided.
Swift SVN r12548
2014-01-18 21:11:06 +00:00
Connor Wakamo
bb439764b4 [driver] Implemented driver-level support for immediate mode and the REPL.
Introduced OutputInfo::Mode and OutputInfo::CompilerMode, which dictate how the
driver should invoke the integrated frontend. Currently, there are three
options:

- StandardCompile: invoke the frontend once-per-input, using -primary-file
- REPL: invoke the frontend as the REPL
- Immediate: invoke the frontend in immediate mode

Updated buildOutputInfo() to properly set the CompilerMode, and updated
buildActions() and Swift::constructJob() to honor the CompilerMode.

With these changes, "swift_driver" (with no inputs) and "swift_driver -repl"
should invoke the REPL, and "swift_driver -i" should invoke the frontend in
immediate mode.

Swift SVN r12547
2014-01-18 20:55:21 +00:00
Connor Wakamo
5f00a5b1a9 [driver] Adjusted CommandOutput so that BaseInput is an Optional<StringRef>.
Not all Commands will have a base input (REPL commands, in particular), so make
BaseInput optional.

Swift SVN r12546
2014-01-18 20:55:20 +00:00
Connor Wakamo
62d1fec41e [driver] Added support for suppressing the "no input files" error.
While SuppressNoInputFiles is not yet set, this is necessary for driver-level
support for the REPL, which requires no input files.

Swift SVN r12545
2014-01-18 20:55:19 +00:00
Connor Wakamo
622b83b98d [driver] Updated OutputInfo with a ShouldTreatModuleAsTopLevelOutput field.
This will indicate that the generated module was user-requested, so it should be
placed alongside other outputs.

Updated buildOutputInfo() in a few ways:
  - Updated it to set ShouldTreatModuleAsTopLevelOutput correctly.
  - Updated it such that -g implies that a module should be generated, but treated as an intermediate.
  - Moved the fallback ModuleName handling into buildOutputInfo(), which requires passing an InputList.

Swift SVN r12502
2014-01-17 19:39:25 +00:00
Connor Wakamo
6a33e53258 [driver] Renamed OutputMode to OutputInfo.
OutputInfo no longer just describes a "mode", so use a more applicable name for
the class.

Swift SVN r12501
2014-01-17 19:39:25 +00:00
Connor Wakamo
5dae76ea22 [driver] Added support for determining a better output for a merge module Command.
First, prefer -module-output-path over any other options when binding the output
for a merge module Command. If that’s not set, use the same behavior as other
intermediate outputs, but use the module name as the base name (instead of the
BaseInput, which is not descriptive enough for a swiftmodule).

This does not yet handle the case where the emitted module should be treated as
a top-level output, even though it’s not the top-level job (essentially,
whenever -emit-module is passed but the driver isn't in EmitModuleOnly mode).

Swift SVN r12500
2014-01-17 19:39:24 +00:00