mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
rename initializeLibSwift -> InitializeSwiftModules
and some updates in comments.
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "libswift",
|
||||
name: "SwiftCompilerSources",
|
||||
platforms: [
|
||||
.macOS("10.9"),
|
||||
],
|
||||
|
||||
@@ -111,7 +111,7 @@ This makes the SIL API easy to use and it allows to program in a "Swifty" style.
|
||||
|
||||
Bridging SIL classes is implemented by including a two word Swift object header (`SwiftObjectHeader`) in the C++ definition of a class, like in `SILFunction`, `SILBasicBlock` or `SILNode`. This enables to use SIL objects on both, the C++ and the Swift, side.
|
||||
|
||||
The Swift class metatypes are "registered" by `registerClass()`, called from `initializeLibSwift()`. On the C++ side, they are stored in static global variables (see `registerBridgedClass()`) and then used to initialize the object headers in the class constructors.
|
||||
The Swift class metatypes are "registered" by `registerClass()`, called from `initializeSwiftModules()`. On the C++ side, they are stored in static global variables (see `registerBridgedClass()`) and then used to initialize the object headers in the class constructors.
|
||||
|
||||
The reference counts in the object header are initialized to "immortal", which let's all ARC operations on SIL objects be no-ops.
|
||||
|
||||
|
||||
@@ -17,8 +17,8 @@ import OptimizerBridging
|
||||
import ExperimentalRegex
|
||||
#endif
|
||||
|
||||
@_cdecl("initializeLibSwift")
|
||||
public func initializeLibSwift() {
|
||||
@_cdecl("initializeSwiftModules")
|
||||
public func initializeSwiftModules() {
|
||||
registerSILClasses()
|
||||
registerSwiftPasses()
|
||||
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
|
||||
extern "C" {
|
||||
|
||||
void initializeLibSwift();
|
||||
void initializeSwiftModules();
|
||||
|
||||
}
|
||||
|
||||
void initializeLibSwift() {}
|
||||
void initializeSwiftModules() {}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//===--- InitializeLibSwift.h -----------------------------------*- C++ -*-===//
|
||||
//===--- InitializeSwiftModules.h -------------------------------*- C++ -*-===//
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
@@ -10,17 +10,17 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef SWIFT_BASIC_INITIALIZELIBSWIFT_H
|
||||
#define SWIFT_BASIC_INITIALIZELIBSWIFT_H
|
||||
#ifndef SWIFT_BASIC_INITIALIZE_SWIFT_MODULES_H
|
||||
#define SWIFT_BASIC_INITIALIZE_SWIFT_MODULES_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void initializeLibSwift();
|
||||
void initializeSwiftModules();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // SWIFT_BASIC_INITIALIZELIBSWIFT_H
|
||||
#endif // SWIFT_BASIC_INITIALIZE_SWIFT_MODULES_H
|
||||
@@ -34,10 +34,10 @@ inline StringRef getStringRef(BridgedStringRef str) {
|
||||
/// freeing it.
|
||||
inline BridgedStringRef getCopiedBridgedStringRef(std::string str,
|
||||
bool removeTrailingNewline = false) {
|
||||
// A couple of mallocs are needed for passing a std::string to libswift. But
|
||||
// A couple of mallocs are needed for passing a std::string to Swift. But
|
||||
// it's currently only used or debug descriptions. So, its' maybe not so bad -
|
||||
// for now.
|
||||
// TODO: find a better way to pass std::strings to libswift.
|
||||
// TODO: find a better way to pass std::strings to Swift.
|
||||
StringRef strRef(str);
|
||||
if (removeTrailingNewline)
|
||||
strRef.consume_back("\n");
|
||||
|
||||
@@ -123,7 +123,7 @@ public:
|
||||
setInsertionPoint(I);
|
||||
}
|
||||
|
||||
// Used by libswift bridging.
|
||||
// Used by swift bridging.
|
||||
explicit SILBuilder(SILInstruction *I, const SILDebugScope *debugScope)
|
||||
: TempContext(I->getFunction()->getModule()),
|
||||
C(TempContext), F(I->getFunction()), CurDebugScope(debugScope) {
|
||||
|
||||
@@ -67,7 +67,7 @@ template <typename VectorT = std::vector<SILInstruction *>,
|
||||
class SILInstructionWorklist : SILInstructionWorklistBase {
|
||||
BlotSetVector<SILInstruction *, VectorT, MapT> worklist;
|
||||
|
||||
/// For invoking Swift instruction passes in libswift.
|
||||
/// For invoking Swift instruction passes in Swift.
|
||||
LibswiftPassInvocation *libswiftPassInvocation = nullptr;
|
||||
|
||||
void operator=(const SILInstructionWorklist &rhs) = delete;
|
||||
|
||||
@@ -59,8 +59,8 @@ class Output;
|
||||
namespace swift {
|
||||
|
||||
/// The payload for the FixedSizeSlab.
|
||||
/// This is a super-class rather than a member of FixedSizeSlab to make bridging
|
||||
/// with libswift easier.
|
||||
/// This is a super-class rather than a member of FixedSizeSlab to make swift
|
||||
/// bridging easier.
|
||||
class FixedSizeSlabPayload {
|
||||
public:
|
||||
/// The capacity of the payload.
|
||||
|
||||
@@ -116,8 +116,8 @@ public:
|
||||
/// ValueBase subobject, the cast will yield a corrupted value.
|
||||
/// Always use the LLVM casts (cast<>, dyn_cast<>, etc.) instead.
|
||||
class alignas(8) SILNode :
|
||||
// SILNode contains a swift object header for bridging with libswift.
|
||||
// For details see libswift/README.md.
|
||||
// SILNode contains a swift object header for bridging with Swift.
|
||||
// For details see SwiftCompilerSources/README.md.
|
||||
public SwiftObjectHeader {
|
||||
public:
|
||||
enum { NumVOKindBits = 3 };
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
/// The C++ version of SwiftObject.
|
||||
///
|
||||
/// It is used for bridging the SIL core classes (e.g. SILFunction, SILNode,
|
||||
/// etc.) with libswift.
|
||||
/// For details see libswift/README.md.
|
||||
/// etc.) with Swift.
|
||||
/// For details see SwiftCompilerSources/README.md.
|
||||
///
|
||||
/// In C++ code, never use BridgedSwiftObject directly. SwiftObjectHeader has
|
||||
/// the proper constructor, which avoids the header to be uninitialized.
|
||||
|
||||
@@ -44,7 +44,7 @@ void executePassPipelinePlan(SILModule *SM, const SILPassPipelinePlan &plan,
|
||||
bool isMandatory = false,
|
||||
irgen::IRGenModule *IRMod = nullptr);
|
||||
|
||||
/// Utility class to invoke passes in libswift.
|
||||
/// Utility class to invoke Swift passes.
|
||||
class LibswiftPassInvocation {
|
||||
/// Backlink to the pass manager.
|
||||
SILPassManager *passManager;
|
||||
@@ -125,7 +125,7 @@ class SILPassManager {
|
||||
/// The number of passes run so far.
|
||||
unsigned NumPassesRun = 0;
|
||||
|
||||
/// For invoking Swift passes in libswift.
|
||||
/// For invoking Swift passes.
|
||||
LibswiftPassInvocation libswiftPassInvocation;
|
||||
|
||||
/// Change notifications, collected during a bridged pass run.
|
||||
|
||||
@@ -45,18 +45,18 @@
|
||||
|
||||
/// SWIFT_FUNCTION_PASS(Id, Tag, Description)
|
||||
/// This macro follows the same conventions as PASS(Id, Tag, Description),
|
||||
/// but is used for function passes which are implemented in libswift.
|
||||
/// but is used for function passes which are implemented in Swift.
|
||||
///
|
||||
/// No further code is need on the C++ side. In libswift a function pass with
|
||||
/// the same name must be registered with 'registerPass()'.
|
||||
/// No further code is need on the C++ side. On the swift swift a function
|
||||
/// pass with the same name must be registered with 'registerPass()'.
|
||||
///
|
||||
#ifndef SWIFT_FUNCTION_PASS
|
||||
#define SWIFT_FUNCTION_PASS(Id, Tag, Description) PASS(Id, Tag, Description)
|
||||
#endif
|
||||
|
||||
/// SWIFT_FUNCTION_PASS_WITH_LEGACY(Id, Tag, Description)
|
||||
/// Like SWIFT_FUNCTION_PASS, but the a C++ legacy pass is used if the not
|
||||
/// built with libswift.
|
||||
/// Like SWIFT_FUNCTION_PASS, but a C++ legacy pass is used if the Swift pass
|
||||
/// is not registered.
|
||||
/// The C++ legacy creation function must be named 'createLegacy<Id>'
|
||||
///
|
||||
#ifndef SWIFT_FUNCTION_PASS_WITH_LEGACY
|
||||
@@ -66,12 +66,12 @@
|
||||
|
||||
/// SWIFT_INSTRUCTION_PASS(Inst, Tag)
|
||||
/// Similar to SWIFT_FUNCTION_PASS, but defines an instruction pass which is
|
||||
/// implemented in libswift and is run by the SILCombiner.
|
||||
/// implemented in swift and is run by the SILCombiner.
|
||||
/// The \p Inst argument specifies the instruction class, and \p Tag a name
|
||||
/// for the pass.
|
||||
///
|
||||
/// No further code is need on the C++ side. In libswift an instruction pass
|
||||
/// with the same name must be registered with 'registerPass()'.
|
||||
/// No further code is need on the C++ side. On the swift side an instruction
|
||||
/// pass with the same name must be registered with 'registerPass()'.
|
||||
///
|
||||
#ifndef SWIFT_INSTRUCTION_PASS
|
||||
#define SWIFT_INSTRUCTION_PASS(Inst, Tag)
|
||||
@@ -79,8 +79,7 @@
|
||||
|
||||
/// SWIFT_INSTRUCTION_PASS_WITH_LEGACY(Inst, Tag)
|
||||
/// Like SWIFT_INSTRUCTION_PASS, but the a C++ legacy SILCombine visit
|
||||
/// function is used if the not
|
||||
/// built with libswift.
|
||||
/// function is used if the swift pass is not registered.
|
||||
/// The C++ legacy visit function must be named
|
||||
/// 'SILCombiner::legacyVisit<Inst>'.
|
||||
///
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#include "swift/AST/DiagnosticEngine.h"
|
||||
#include "swift/AST/DiagnosticsDriver.h"
|
||||
#include "swift/Basic/LLVMInitialize.h"
|
||||
#include "swift/Basic/InitializeLibSwift.h"
|
||||
#include "swift/Basic/InitializeSwiftModules.h"
|
||||
#include "swift/Basic/PrettyStackTrace.h"
|
||||
#include "swift/Basic/Program.h"
|
||||
#include "swift/Basic/TaskQueue.h"
|
||||
@@ -186,8 +186,8 @@ static bool appendSwiftDriverName(SmallString<256> &buffer) {
|
||||
static int run_driver(StringRef ExecName,
|
||||
const ArrayRef<const char *> argv) {
|
||||
// This is done here and not done in FrontendTool.cpp, because
|
||||
// FrontendTool.cpp is linked to tools, which don't use libswift.
|
||||
initializeLibSwift();
|
||||
// FrontendTool.cpp is linked to tools, which don't use swift modules.
|
||||
initializeSwiftModules();
|
||||
|
||||
// Handle integrated tools.
|
||||
if (argv.size() > 1) {
|
||||
|
||||
@@ -253,15 +253,15 @@ int swift::RunImmediately(CompilerInstance &CI,
|
||||
if (emplaceProcessArgs == nullptr)
|
||||
return -1;
|
||||
#else
|
||||
// In case the compiler is built with libswift, it already has the stdlib
|
||||
// In case the compiler is built with swift modules, it already has the stdlib
|
||||
// linked to. First try to lookup the symbol with the standard library
|
||||
// resolving.
|
||||
auto emplaceProcessArgs
|
||||
= (ArgOverride)dlsym(RTLD_DEFAULT, "_swift_stdlib_overrideUnsafeArgvArgc");
|
||||
|
||||
if (dlerror()) {
|
||||
// If this does not work (= not build with libswift), we have to explicitly
|
||||
// load the stdlib.
|
||||
// If this does not work (= the Swift modules are not linked to the tool),
|
||||
// we have to explicitly load the stdlib.
|
||||
auto stdlib = loadSwiftRuntime(Context.SearchPathOpts.RuntimeLibraryPaths);
|
||||
if (!stdlib) {
|
||||
CI.getDiags().diagnose(SourceLoc(),
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include "swift/Parse/SyntaxParsingContext.h"
|
||||
#include "swift/Syntax/SyntaxKind.h"
|
||||
|
||||
// Regex parser delivered via libSwift
|
||||
// Regex parser delivered via Swift modules.
|
||||
#include "swift/Parse/ExperimentalRegexBridging.h"
|
||||
static RegexLiteralParsingFn regexLiteralParsingFn = nullptr;
|
||||
void Parser_registerRegexLiteralParsingFn(RegexLiteralParsingFn fn) {
|
||||
|
||||
@@ -21,13 +21,12 @@ namespace {
|
||||
|
||||
bool nodeMetatypesInitialized = false;
|
||||
|
||||
// Filled in by class registration in initializeLibSwift().
|
||||
// Filled in by class registration in initializeSwiftModules().
|
||||
SwiftMetatype nodeMetatypes[(unsigned)SILNodeKind::Last_SILNode + 1];
|
||||
|
||||
}
|
||||
|
||||
// Does return null, if libswift is not used, i.e. initializeLibSwift() is
|
||||
// never called.
|
||||
// Does return null if initializeSwiftModules() is never called.
|
||||
SwiftMetatype SILNode::getSILNodeMetatype(SILNodeKind kind) {
|
||||
SwiftMetatype metatype = nodeMetatypes[(unsigned)kind];
|
||||
assert((!nodeMetatypesInitialized || metatype) &&
|
||||
@@ -71,8 +70,8 @@ static void setUnimplementedRange(SwiftMetatype metatype,
|
||||
}
|
||||
}
|
||||
|
||||
/// Registers the metatype of a libswift class.
|
||||
/// Called by initializeLibSwift().
|
||||
/// Registers the metatype of a swift SIL class.
|
||||
/// Called by initializeSwiftModules().
|
||||
void registerBridgedClass(BridgedStringRef className, SwiftMetatype metatype) {
|
||||
nodeMetatypesInitialized = true;
|
||||
|
||||
@@ -94,10 +93,10 @@ void registerBridgedClass(BridgedStringRef className, SwiftMetatype metatype) {
|
||||
}
|
||||
|
||||
// Pre-populate the "unimplemented" ranges of metatypes.
|
||||
// If a specifc class is not implemented yet in libswift, it bridges to an
|
||||
// If a specifc class is not implemented in Swift yet, it bridges to an
|
||||
// "unimplemented" class. This ensures that optimizations handle _all_ kind of
|
||||
// instructions gracefully, without the need to define the not-yet-used
|
||||
// classes in libswift.
|
||||
// classes in Swift.
|
||||
#define VALUE_RANGE(ID) SILNodeKind::First_##ID, SILNodeKind::Last_##ID
|
||||
if (clName == "UnimplementedRefCountingInst")
|
||||
return setUnimplementedRange(metatype, VALUE_RANGE(RefCountingInst));
|
||||
|
||||
@@ -243,7 +243,7 @@ static void runBridgedFunctionPass(BridgedFunctionPassRunFn &runFunction,
|
||||
runFunction({{f}, {passManager->getLibswiftPassInvocation()}});
|
||||
}
|
||||
|
||||
// Called from libswift's initializeLibSwift().
|
||||
// Called from initializeSwiftModules().
|
||||
void SILPassManager_registerFunctionPass(BridgedStringRef name,
|
||||
BridgedFunctionPassRunFn runFn) {
|
||||
bridgedPassRunFunctions[getStringRef(name)] = runFn;
|
||||
|
||||
@@ -468,7 +468,7 @@ void SILCombiner::eraseInstIncludingUsers(SILInstruction *inst) {
|
||||
eraseInstFromFunction(*inst);
|
||||
}
|
||||
|
||||
/// Runs an instruction pass in libswift.
|
||||
/// Runs a Swift instruction pass.
|
||||
void SILCombiner::runSwiftInstructionPass(SILInstruction *inst,
|
||||
void (*runFunction)(BridgedInstructionPassCtxt)) {
|
||||
Worklist.setLibswiftPassInvocation(&libswiftPassInvocation);
|
||||
@@ -481,7 +481,7 @@ void SILCombiner::runSwiftInstructionPass(SILInstruction *inst,
|
||||
static llvm::StringMap<BridgedInstructionPassRunFn> libswiftInstPasses;
|
||||
static bool passesRegistered = false;
|
||||
|
||||
// Called from libswift's initializeLibSwift().
|
||||
// Called from initializeSwiftModules().
|
||||
void SILCombine_registerInstructionPass(BridgedStringRef name,
|
||||
BridgedInstructionPassRunFn runFn) {
|
||||
libswiftInstPasses[getStringRef(name)] = runFn;
|
||||
|
||||
@@ -109,7 +109,7 @@ class SILCombiner :
|
||||
/// External context struct used by \see ownershipRAUWHelper.
|
||||
OwnershipFixupContext ownershipFixupContext;
|
||||
|
||||
/// For invoking Swift instruction passes in libswift.
|
||||
/// For invoking Swift instruction passes.
|
||||
LibswiftPassInvocation libswiftPassInvocation;
|
||||
|
||||
public:
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include "swift/AST/SILOptions.h"
|
||||
#include "swift/Basic/FileTypes.h"
|
||||
#include "swift/Basic/LLVMInitialize.h"
|
||||
#include "swift/Basic/InitializeLibSwift.h"
|
||||
#include "swift/Basic/InitializeSwiftModules.h"
|
||||
#include "swift/Frontend/DiagnosticVerifier.h"
|
||||
#include "swift/Frontend/Frontend.h"
|
||||
#include "swift/Frontend/PrintingDiagnosticConsumer.h"
|
||||
@@ -505,7 +505,7 @@ int main(int argc, char **argv) {
|
||||
|
||||
llvm::cl::ParseCommandLineOptions(argc, argv, "Swift SIL optimizer\n");
|
||||
|
||||
initializeLibSwift();
|
||||
initializeSwiftModules();
|
||||
|
||||
if (PrintStats)
|
||||
llvm::EnableStatistics();
|
||||
|
||||
Reference in New Issue
Block a user