Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Xcode generate Assembly code for a Swift File?

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?

like image 548
Ahmad F Avatar asked Aug 27 '17 09:08

Ahmad F


People also ask

How to see assembly code in Xcode?

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.

How do I create a swift file in Xcode?

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.


1 Answers

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.

like image 146
ntoonio Avatar answered Sep 17 '22 11:09

ntoonio