From e246119a1c575a8417106d07553dfc16041ce7c4 Mon Sep 17 00:00:00 2001 From: "Brett R. Toomey" Date: Sun, 19 Nov 2017 16:18:03 +0100 Subject: [PATCH] Added output, dynamic lib targets and documented all flags --- Sources/Core/Options.swift | 28 +++++++++++++++++++++++++--- Sources/Core/SourcePackage.swift | 8 +++++++- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/Sources/Core/Options.swift b/Sources/Core/Options.swift index 67b79d7..bbfd6c8 100644 --- a/Sources/Core/Options.swift +++ b/Sources/Core/Options.swift @@ -9,7 +9,7 @@ public struct Options { public var flags: Flags = [] public var jobs: Int = 1 - + public var outputName: String? public var optimizationLevel: Int = 0 public init(arguments: ArraySlice) { @@ -60,6 +60,17 @@ public struct Options { flags.insert(.emitAssembly) case "-test": flags.insert(.testMode) + case "-shared": + flags.insert(.shared) + case "-dynamiclib": + flags.insert(.dynamicLib) + case "-o": + guard let v = val else { + print("ERROR: -o expects an output name") + exit(1) + } + outputName = v + skip = true case "-jobs": guard let v = val, let j = Int(v) else { print("ERROR: -jobs expects an integer following it") @@ -90,20 +101,28 @@ public struct Options { print("\(purple)OPTIONS\(reset):") print(" -dump-ir Dump LLVM IR") print() + print(" -dynamiclib Emit dylib") + print() print(" -emit-asm Emit assembly file(s)") print(" -emit-ast Parse, check and emit AST file(s)") print(" -emit-bitcode Emit LLVM bitcode file(s)") print(" -emit-ir Emit LLVM IR file(s)") print(" -emit-times Emit times for each stage of compilation") print() + print(" -jobs Controls the amount of workers (default is # of cores)") + print() + print(" -no-cleanup Keeps the build folder after compilation") + print() print(" -Onone Compile with no optimizations") print(" -O1 Compile with basic optimizations") print(" -O2 Compile with most optimizations") print(" -O3 Compile with tail call elimination and loop unrolling") print() - print(" -jobs Controls the amount of workers (default is # of cores)") + print(" -o Write output to ") print() - print(" -no-cleanup Keeps the build folder after compilation") + print(" -shared Emit shared object") + print() + print(" -test Compile and run all unit tests") print() print(" -version Show version information and exit") exit(0) @@ -133,5 +152,8 @@ public struct Options { public static let emitAst = Flags(rawValue: 0b0100 << 8) public static let testMode = Flags(rawValue: 0b1000 << 8) + + public static let shared = Flags(rawValue: 0b0001 << 12) + public static let dynamicLib = Flags(rawValue: 0b0010 << 12) } } diff --git a/Sources/Core/SourcePackage.swift b/Sources/Core/SourcePackage.swift index 571e6c9..52e589a 100644 --- a/Sources/Core/SourcePackage.swift +++ b/Sources/Core/SourcePackage.swift @@ -260,7 +260,13 @@ extension SourcePackage { let clangPath = getClangPath() let objFilePaths = compiler.packages.values.map({ $0.objpath }) - var args = ["-o", moduleName] + objFilePaths + var args = ["-o", compiler.options.outputName ?? moduleName] + objFilePaths + + if compiler.options.flags.contains(.shared) { + args.append("-shared") + } else if compiler.options.flags.contains(.dynamicLib) { + args.append("-dynamiclib") + } let allLinkedLibraries = compiler.packages.values.reduce(Set(), { $0.union($1.linkedLibraries) }) for library in allLinkedLibraries {