In fact, I am aware of that running:
xcrun -sdk macosx swiftc -O -emit-assembly SwiftFile.swift -o result
on terminal should generate "result" file which contains assembly code for "SwiftFile.swift" file.
Also, there are tools such as Hopper to do such a task, furthermore, it can generate Pseudo-code to let it more easy to read.
However, is there a way to do it directly from Xcode? if there is, how to do it?
Put break point in the code where you want to see assembly code. Then you can view assembly code when code reached to that breakpoint.
To create a new Swift package, open Xcode and select File > New > Swift Package. Choose a name and select a file location. Select “Create Git repository on my Mac” to put your package under version control. On completion, the Swift package opens in Xcode and looks similar to a standard Xcode project.
Go to your targets, click Build Phases. Add a Run Script by clicking the plus in the upper left corner. In text area add the code
xcrun -sdk macosx swiftc -O -emit-assembly Folder/SwiftFile.swift -o result.asm
This will generate an assembly file every time you build for that target. You can also create a new target if you don't want it to generate assembly every time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With