Skip to content

Instantly share code, notes, and snippets.

@fjolnir
Created August 17, 2012 13:35
Show Gist options
  • Save fjolnir/3378731 to your computer and use it in GitHub Desktop.
Save fjolnir/3378731 to your computer and use it in GitHub Desktop.
\ Tranquil compiler
import "CoreFoundation"
inPath = "Tests/smartfib.tq"
outPath = "a.out"
runtimeLibPath = "Build/libtranquil.dylib"
ldFlags = ["-lobjc", runtimeLibPath]
(0 to: (... count)) each: { i |
if ...[i] == "-o"
outPath = ...[++i]
else if inPath == nil
inPath = ...[i]
else
ldFlags << ...[i]
}
irPath = "/tmp/#{CFUUIDCreateString(nil, CFUUIDCreate(nil))}.bc"
compilationTask = NSTask launchedTaskWithLaunchPath: "Build/tranquil"
arguments: ["-aot", "-o", irPath, inPath];
waitUntilExit;
self
if (compilationTask terminationStatus) != 0
Abort()
asmPath = "/tmp/#{CFUUIDCreateString(nil, CFUUIDCreate(nil))}.s"
assemblingTask = NSTask launchedTaskWithLaunchPath: "/usr/local/llvm/bin/llc"
arguments: ["-O2", "-o", asmPath, irPath];
waitUntilExit;
self
if (assemblingTask terminationStatus) != 0
Abort()
linkingTask = NSTask launchedTaskWithLaunchPath: "/usr/local/llvm/bin/clang"
arguments: ldFlags + ["-o", outPath, asmPath];
waitUntilExit;
self
if (linkingTask terminationStatus) != 0
Abort()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment