Files
swift-mirror/include/swift/FrontendTool/FrontendTool.h
Ryan Mansfield ba0ce8aea6 Add frontend options to write SIL and LLVM IR as additional compilation output.
This commit adds -sil-output-path and -ir-output-path frontend options that
allow generating SIL and LLVM IR files as supplementary outputs during normal
compilation.

These options can be useful for debugging and analysis tools
workflows that need access to intermediate compilation artifacts
without requiring separate compiler invocations.

Expected behaviour:

Primary File mode:
 - SIL: Generates one .sil file per source file
 - IR: Generates one .ll file per source file

Single-threaded WMO mode:
 - SIL: Generates one .sil file for the entire module
 - IR: Generates one .ll file for the entire module

Multi-threaded WMO mode:
 - SIL: Generates one .sil file for the entire module
 - IR: Generates separate .ll files per source file

File Maps with WMO:
 - Both SIL and IR outputs using first entry's naming, which is
   consistent with the behaviour of other supplementary outputs.

rdar://160297898
2025-10-06 15:45:49 -04:00

88 lines
2.9 KiB
C++

//===--- FrontendTool.h - Frontend control ----------------------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This file provides a high-level API for interacting with the basic
// frontend tool operation.
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_FRONTENDTOOL_H
#define SWIFT_FRONTENDTOOL_H
#include "swift/Basic/LLVM.h"
namespace llvm {
class Module;
}
namespace swift {
class CompilerInvocation;
class CompilerInstance;
class SILModule;
/// A simple observer of frontend activity.
///
/// Don't let this interface block enhancements to the frontend pipeline.
class FrontendObserver {
public:
FrontendObserver() = default;
virtual ~FrontendObserver() = default;
/// The frontend has parsed the command line.
virtual void parsedArgs(CompilerInvocation &invocation);
/// The frontend has configured the compiler instance.
virtual void configuredCompiler(CompilerInstance &instance);
/// The frontend has performed semantic analysis.
virtual void performedSemanticAnalysis(CompilerInstance &instance);
/// The frontend has performed basic SIL generation.
/// SIL diagnostic passes have not yet been applied.
virtual void performedSILGeneration(SILModule &module);
/// The frontend has executed the SIL optimization and diagnostics pipelines.
virtual void performedSILProcessing(SILModule &module);
// TODO: maybe enhance this interface to hear about IRGen and LLVM
// progress.
};
namespace frontend {
namespace utils {
StringRef escapeForMake(StringRef raw, llvm::SmallVectorImpl<char> &buffer);
}
}
/// Perform all the operations of the frontend, exactly as if invoked
/// with -frontend.
///
/// \param args the arguments to use as the arguments to the frontend
/// \param argv0 the name used as the frontend executable
/// \param mainAddr an address from the main executable
///
/// \return the exit value of the frontend: 0 or 1 on success unless
/// the frontend executes in immediate mode, in which case this will be
/// the exit value of the script, assuming it exits normally
int performFrontend(ArrayRef<const char *> args,
const char *argv0,
void *mainAddr,
FrontendObserver *observer = nullptr);
bool performCompileStepsPostSema(CompilerInstance &Instance, int &ReturnValue,
FrontendObserver *observer,
ArrayRef<const char *> CommandLineArgs);
} // namespace swift
#endif