Created
June 23, 2018 18:00
-
-
Save jerrymarino/9de95355173b77b559e388a2682fec65 to your computer and use it in GitHub Desktop.
Transform and compile raw SIL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Path to the swift compiler | |
SWIFT=(~/myswift/build/Ninja-DebugAssert/swift-macosx-x86_64/bin/swift) | |
SWIFTC=(~/myswift/build/Ninja-DebugAssert/swift-macosx-x86_64/bin/swiftc) | |
IFS='' read -d '' -r SOURCE <<"EOF" | |
struct Some { | |
let attr = 0 | |
} | |
let x = Some() | |
print("Value", x.attr) | |
print("Info", Some.Type.self, Mirror(reflecting: x)) | |
EOF | |
MODULE=FunModule | |
# Write the file, and emit sil | |
echo "$SOURCE" > some.swift | |
$SWIFT -frontend -emit-silgen some.swift -module-name $MODULE -o some.sil | |
cat some.sil | |
# Now do some transformations on the sil | |
sed -i "" "s,Some,Fun,g" some.sil | |
# Compile and link the executable | |
$SWIFT -frontend -c some.sil -g -module-name $MODULE -emit-module-path $MODULE.swiftmodule -o some.o | |
$SWIFTC some.o |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment