Files
swift-mirror/include/swift/Driver/FrontendUtil.h
Connor Wakamo 8db11fd059 [driver] Added an API for creating a CompilerInvocation from driver arguments.
Added a new API, swift::driver::createCompilerInvocation. This takes an array
of driver arguments, constructs a Driver and a Compilation, and then uses the
Compilation's frontend arguments to create a CompilerInvocation.

This works by forcing Driver to create a Compilation which contains a single
compile command. (It achieves this by passing
"-force-single-frontend-invocation" after all other arguments.) This approach
roughly matches Clang's clang::createInvocationFromCommandLine.

As implied by the namespacing, this lives in swiftDriver. As a result,
swiftDriver now depends on swiftFrontend.

In support of this, added a couple of driver diagnostics for exceptional error
cases (where Driver produced something other than a single Command, or if that
Command is not a frontend command).

This fixes <rdar://problem/16125395>.

Swift SVN r20972
2014-08-03 19:04:22 +00:00

47 lines
1.5 KiB
C++

//===--- FrontendUtil.h - Driver Utilities for Frontend ---------*- C++ -*-===//
//
// 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
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_DRIVER_FRONTENDUTIL_H
#define SWIFT_DRIVER_FRONTENDUTIL_H
#include "swift/Basic/LLVM.h"
#include <memory>
namespace swift {
class CompilerInvocation;
class DiagnosticEngine;
namespace driver {
/// \brief Creates a CompilerInvocation from the given driver arguments.
///
/// \param ArgList The driver arguments for which a CompilerInvocation
/// should be created.
/// \param Diags The DiagnosticEngine which should be used for parsing arguments
///
/// \returns A fully-formed CompilerInvocation, or nullptr if one couldn't be
/// created.
///
/// \note This function is not intended to create CompilerInvocation instances
/// which are suitable for use in REPL or immediate modes, since it will have
/// the effect of overriding the frontend's requested action to
/// FrontendOptions::ActionType::Parse.
std::unique_ptr<CompilerInvocation> createCompilerInvocation(
ArrayRef<const char *> ArgList, DiagnosticEngine &Diags);
} // end namespace driver
} // end namespace swift
#endif