mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
- 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
86 lines
2.7 KiB
C++
86 lines
2.7 KiB
C++
//===-- driver.cpp - Swift Compiler Driver --------------------------------===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See http://swift.org/LICENSE.txt for license information
|
|
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This is the entry point to the swift compiler driver.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "swift/AST/DiagnosticEngine.h"
|
|
#include "swift/Basic/SourceManager.h"
|
|
#include "swift/Driver/Compilation.h"
|
|
#include "swift/Driver/Driver.h"
|
|
#include "swift/Driver/Job.h"
|
|
#include "swift/Frontend/PrintingDiagnosticConsumer.h"
|
|
#include "llvm/ADT/SmallVector.h"
|
|
#include "llvm/Support/CommandLine.h"
|
|
#include "llvm/Support/Host.h"
|
|
#include "llvm/Support/ManagedStatic.h"
|
|
#include "llvm/Support/PrettyStackTrace.h"
|
|
#include "llvm/Support/Process.h"
|
|
#include "llvm/Support/Signals.h"
|
|
#include "llvm/Support/TargetSelect.h"
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
#include <memory>
|
|
|
|
using namespace swift;
|
|
using namespace swift::driver;
|
|
|
|
std::string getExecutablePath(const char *FirstArg) {
|
|
void *P = (void *)(intptr_t)getExecutablePath;
|
|
return llvm::sys::fs::getMainExecutable(FirstArg, P);
|
|
}
|
|
|
|
int main(int argc_, const char **argv_) {
|
|
// Print a stack trace if we signal out.
|
|
llvm::sys::PrintStackTraceOnErrorSignal();
|
|
llvm::PrettyStackTraceProgram X(argc_, argv_);
|
|
|
|
// Set up an object which will call llvm::llvm_shutdown() on exit.
|
|
llvm::llvm_shutdown_obj Y;
|
|
|
|
llvm::SmallVector<const char *, 256> argv;
|
|
llvm::SpecificBumpPtrAllocator<char> ArgAllocator;
|
|
llvm::error_code EC = llvm::sys::Process::GetArgumentVector(argv,
|
|
llvm::ArrayRef<const char *>(argv_, argc_), ArgAllocator);
|
|
if (EC) {
|
|
llvm::errs() << "error: couldn't get arguments: " << EC.message() << '\n';
|
|
return 1;
|
|
}
|
|
|
|
// TODO: handle integrated tools, such as the frontend.
|
|
|
|
std::string Path = getExecutablePath(argv[0]);
|
|
|
|
PrintingDiagnosticConsumer PDC;
|
|
|
|
SourceManager SM;
|
|
DiagnosticEngine Diags(SM);
|
|
Diags.addConsumer(PDC);
|
|
|
|
Driver TheDriver(Path, Diags);
|
|
|
|
llvm::InitializeAllTargets();
|
|
|
|
std::unique_ptr<Compilation> C = TheDriver.buildCompilation(argv);
|
|
|
|
// In the event of an unrecoverable error, BuildCompilation will exit early,
|
|
// so we can start with a 0 result code.
|
|
int ResultCode = 0;
|
|
if (C) {
|
|
// TODO: actually perform the Compilation, via the Driver.
|
|
ResultCode = C->getJobs().run();
|
|
}
|
|
|
|
return ResultCode;
|
|
}
|