cancel
Showing results for 
Search instead for 
Did you mean: 

Self-compilation

MikeDB
Lead

Has anybody implemented a small compiler that runs on an STM32 M3 or M7 to produce code for itself. Must be a compiler, not interpreter, as runtime speed is paramount. Doesn't need to be a complete C++ instruction set, a mini-C or something like that would be fine.

1 ACCEPTED SOLUTION

Accepted Solutions

There's this interesting project - https://github.com/jserv/amacc

But unfortunately it's for ARMv7-A, not ARMv7-M.

Anyway, you can try to find an interpreter/vm (Lua, Forth, etc.) with a JIT compilation instead of C compiler. [Click Show More]

For example, here's a "Stack" VM implementation with JIT for micro:bit (ARMv6-M) - https://github.com/thomasdenney/microjit

View solution in original post

12 REPLIES 12

There's this interesting project - https://github.com/jserv/amacc

But unfortunately it's for ARMv7-A, not ARMv7-M.

Anyway, you can try to find an interpreter/vm (Lua, Forth, etc.) with a JIT compilation instead of C compiler. [Click Show More]

For example, here's a "Stack" VM implementation with JIT for micro:bit (ARMv6-M) - https://github.com/thomasdenney/microjit

MikeDB
Lead

JIT is too slow sorry. I'll have a look at the first one and see if can be converted

AvaTar
Lead

Minding the limited RAM and absence of a MMU on a Cortex M MCU, this does not make sense practically. As exercise, perhaps.

MikeDB
Lead

I once had perfectly good C and Pascal compilers on an early PC with 256K RAM and floppy discs so I think a 1M RAM H series STM32 with about 1000 times the processing power should be up to the job.

S.Ma
Principal

And how do you debug?

Same as in the 80s - printing to the LCD. This is only a few hundred k of code tops, not the multi-megabyte stuff that obviously needs modern facilities on an attached PC.

Uwe Bonnes
Principal II

Where does compiler input come from?

A flash card. Main development would be on a PC of course as its more convenient, but I want users to be able to alter a line of code on site without having to find a PC that has the complete ARM development suite on it. The editor of course would also be more simplistic than Visual Studio or whatever, but I have a solution to that. Problem is a small compiler that produces ARM assembly code.

S.Ma
Principal

What is the intrisic need to generate machine code within the MCU ? Patch FW ?

Most MCU devices don't necessarily have Displays or console connexions. Take a Rice cooker or an e-bike.