Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jerrymarino/9de95355173b77b559e388a2682fec65 to your computer and use it in GitHub Desktop.
Save jerrymarino/9de95355173b77b559e388a2682fec65 to your computer and use it in GitHub Desktop.
Transform and compile raw SIL
#!/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