Using swift compiler for bare metal?

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.


I was exploring this possibility (using Swift for embedded applications). Since Swift needs a runtime, after static compilation of "Hello, World!" (on Ubuntu, x86-64 using latest Swift 3.0.2) the result binary size was over 5 Megabytes, which might be an issue on "small" ARM controllers (like Cortex-M0).

链接地址: http://www.djcxy.com/p/31272.html

上一篇: 带有外部认证的AWS API网关

下一篇: 使用swift编译器来裸机?