I would really like to use swift for embedded programming as I feel like its a much better replacement for c++, The processor I'm using is an ARM Cortex-M4F(http://www.ti.com/tool/ek-tm4c123gxl). Looking at the swift compiler page, it says you can generate LLVM IR from swift source and then I was hoping to cross compile with LLVM. Would this be possible?
It definitely is possible to generate machine code with Swift. In fact, by default when you compile a Swift program in Xcode or with the swiftc command-line compiler, the executable file produced is composed of machine-code.
The LLVM bytecode is generated at some point during the build process, but the final executable that's produced is machine-code. There are compiler options that allow you to produce only LLVM bytcode if you want, but LLVM bytecode isn't usually executed directly, like Java bytecode with is run by the Java runtime.
As far as cross-compiling for ARM, I'm not sure how it works with the swiftc tool, but if you build an Xcode iOS project, it produces an ARM executable. I'm sure the swiftc complier has all the options you need to produce ARM executables.
However, the one catch I can think of, is that lots of Swift's functionality depends on Apple's frameworks. However, now that Swift has been open-sourced, there gradually be more pure swift libraries for all kinds of things.
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