Swift编译流

Swift编译流和Clang一样都是编译前端,和 Clang 一样代码会被解析成语法数 AST,接下来会比 Clang 多一步,通过 SILGen 生成 SIL 这一次方便做些 Swift 特定的优化,SIL 会被传递给 IR 生成阶段生成 LLVM IR,最后由 LLVM 解决余下事情。

//生成程序
swiftc toy.swift

//生成检查 AST
swiftc -dump-ast toy.swift

//可以还原之前函数名
swiftc -emit-silgen toy.swift | xcrun swift-demangle

//llvm ir 和汇编的生成
swiftc -emit-ir toy.swift
swiftc -emit-assembly toy.swift

//生成可执行的脚本
xcrun -sdk macosx swiftc toy.swift -o toy