695 Commits

Author SHA1 Message Date
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
Connor Wakamo
db3888ba0f [driver] Replaced Tool::constructJob()’s LinkingOutput parameter with an OutputMode parameter.
Moved OutputMode out of Driver and directly into swift::driver.
Adjusted callers of Tool::constructJob() to pass an OutputMode.

Swift SVN r12497
2014-01-17 19:39:23 +00:00
Connor Wakamo
11a6121caa [driver] Updated OutputMode to include the module name.
This is centralized, as many Commands need to reference the module name.

Swift SVN r12496
2014-01-17 19:39:23 +00:00
Connor Wakamo
f892b1a544 [driver] Implemented support for adding an additional output for a swiftmodule to the CommandOutput of frontend Commands.
Adjusted Driver::buildJobs() and Driver::buildJobsForAction() to include a const OutputMode& parameter.
Updated Driver::buildJobsForAction() to set an additional swiftmodule output on Jobs generated from a CompileJobAction if the OutputMode says the driver should generate a module.
This change now causes frontend invocations to pass “-emit-module -module-output-path <path>” when a module is requested, though the partial modules are not yet properly merged.

Swift SVN r12495
2014-01-17 19:39:22 +00:00
Connor Wakamo
b94e9e3f76 [driver] Slightly refactored Driver’s handling of OutputMode.
Instead of having buildActions() call the private Driver::getOutputMode() function, establish an OutputMode using a new Driver::buildOutputMode() function.
This change will allow the OutputMode to be more easily shared across functions without needing to generate it each time (though, at the moment, only buildActions() uses the OutputMode).

Swift SVN r12494
2014-01-17 19:39:22 +00:00
Connor Wakamo
e9599f249d [driver] Added support for adding a MergeModuleJobAction to the Action graph.
Updated Driver::OutputMode to also contain a ShouldGenerateModule field.
Updated Driver::getOutputMode() to set OutputMode::ShouldGenerateModule appropriately.
Updated Driver::buildActions() to insert a MergeModuleJobAction into the Action graph if the Driver’s OutputMode indicates that a module should be generated.

Swift SVN r12492
2014-01-17 19:39:21 +00:00
Connor Wakamo
824c0cb126 [driver] Reworked the CommandOutput class to add support for specifying additional outputs.
This will allow the driver to specify the location for, among other things, the partial swiftmodule generated by a single frontend invocation.

Swift SVN r12449
2014-01-17 01:11:55 +00:00
Connor Wakamo
40b38c40b2 [driver] Reworked Driver::buildJobsForAction() so that it doesn’t create the same Job multiple times.
Since a Job may be reached through multiple paths in the dependency graph, we
need to include support for caching Jobs. (Currently, the cache maps
Action/ToolChain pairs to Jobs.)

As a result of these changes, Tool::constructJob() and
Driver::buildJobsForAction() return a plain Job *, instead of a
std::unique_ptr<Job>, since the Jobs returned by buildJobsForAction() no longer
need to be unique.

Swift SVN r12443
2014-01-17 00:47:21 +00:00
Connor Wakamo
31df3cb241 [driver] Updated Driver::printJobs() to only print each Job once, even though it may be in the graph multiple times (as input to multiple Jobs).
Swift SVN r12442
2014-01-17 00:47:20 +00:00
Connor Wakamo
3df87a6c8c Revert "[driver] Added an assertion to Driver::buildJobsForAction() to ensure that it only builds Jobs for JobActions."
This reverts r12433.

Swift SVN r12436
2014-01-17 00:01:05 +00:00
Connor Wakamo
3bcad8fef0 [driver] Added an assertion to Driver::buildJobsForAction() to ensure that it only builds Jobs for JobActions.
Swift SVN r12433
2014-01-16 23:42:54 +00:00
Connor Wakamo
d5f95cd574 [driver] Add a new -driver-skip-execution flag.
This instructs the driver to skip task execution by using a DummyTaskQueue in Compilation::performJobsInList().
This option should generally only be used for testing, as DummyTaskQueue may provide fake buffered output.

Swift SVN r12350
2014-01-15 21:27:56 +00:00
Connor Wakamo
5a603a3cd1 [driver] Add support for -emit-ir and -emit-bc.
Added driver-level support for generating commands with -emit-ir and -emit-bc as well integrated frontend support for handling -emit-ir and -emit-bc.

Swift SVN r11375
2013-12-17 02:43:40 +00:00
Connor Wakamo
3b80655e62 [driver] Switched from --help-hidden to -help-hidden.
Left --help-hidden in as an alias for consistency with clang, but -help-hidden is now the primary spelling of this option.

Swift SVN r11350
2013-12-16 19:23:16 +00:00
Connor Wakamo
44971d2e5a [driver] Added support for specifying the number of commands to execute in parallel.
The driver does not yet support parallel execution, but this sets the Compilation up with the necessary information to execute commands in parallel.

Swift SVN r11333
2013-12-15 21:47:35 +00:00
Connor Wakamo
6127955b05 [driver] Add support for passing arguments after -- down to the frontend as-is if the driver is in immediate mode.
In Driver::translateInputArgs(), don’t break apart the OPT__DASH_DASH argument if we’re in immediate mode.
Mark OPT__DASH_DASH as being a FrontendOption.
In Swift::constructJob(), add support for types::TY_Nothing, and pass the argument for OPT__DASH_DASH as-is if the driver is invoking the frontend in immediate mode.

Swift SVN r11325
2013-12-15 00:58:27 +00:00
Connor Wakamo
58ec588819 [driver] Adjusted the implementation of Driver::getOutputMode() so that it uses Option::matches() instead of a series of ArgList::getLastArg() calls.
Also added support for indicating that -i and -repl produce no output.

Swift SVN r11323
2013-12-15 00:58:25 +00:00
Connor Wakamo
02c1532d27 Initial support for an integrated frontend in swift_driver.
- Added support for invoking the Swift frontend via "swift_driver -frontend".
- Added frontend_main.cpp, which implements the main entry point for the
  integrated frontend. (Currently, this supports compiling an input Swift file
  into an object file.)
- Removed lib/Frontend/FrontendOptions.td, and replaced its functionality with
  options in include/Swift/Driver/Options.td and a new
  include/Swift/Driver/FrontendOptions.td. Options supported by the frontend
  are denoted by the FrontendOption flag; options which are not supported by
  the driver are denoted by the NoDriverOption flag.
- Updated CompilerInvocation::parseArgs() to use the option table returned from
  createDriverOptTable(), including renaming a handful of options. (-triple is
  now -target, and -Xclang is now -Xcc.)

Swift SVN r11082
2013-12-10 18:06:54 +00:00
Connor Wakamo
d456848811 [driver] Added support for differentiating SIL emitted by -emit-sil and -emit-silgen.
SIL emitted by -emit-silgen is treated internally as “raw-sil”, while SIL emitted by -emit-silgen is treated internally as “sil".
Externally, there are no changes; both kinds of SIL still have a “.sil” file extension.
Updated test/Driver/Actions.swift to account for the change in behavior with -emit-silgen.

Swift SVN r10947
2013-12-06 23:11:30 +00:00
Connor Wakamo
3d9f94e715 Properly implemented "swift_driver -driver-print-bindings".
This produces output similar to "clang -ccc-print-bindings".
Also added several tests to ensure that "swift_driver -driver-print-bindings"
behaves as expected.

Swift SVN r10935
2013-12-06 21:23:03 +00:00
Connor Wakamo
ed2038585f Initial set of changes to add a new 'swift_driver' executable.
- Added a couple of new targets:
  - libswiftDriver, which contains most of the driver implementation
  - swift_driver, which produces the actual executable

- Added centralized version information into libswiftBasic.

- Added a new "Driver Design & Internals" document, which currently describes
  the high-level design of the Swift driver.

- Implemented an early version of the functionality of the driver, including
  versions of the Parse, Pipeline, Bind, Translate, and Execute driver stages.
  Parse, Pipeline, and Bind are largely implemented; Translate and Execute are
  early placeholders. (Translate produces "swift_driver --version" and "ld -v"
  commands, while Execute performs all subtasks sequentially, rather than in
  parallel.)

This is just the starting point for the Swift driver. Tests for the existing
behavior are forthcoming.

Swift SVN r10933
2013-12-06 21:23:01 +00:00