I don't know how best to implement this, but here's my method for tiDE (which supports Axe):
Open an instance of the emulator behind the scenes (invisible) and turn off the speed limit.
Load Axe into the emulator, and load the source code into the emulator
Force some keypresses to open Axe and compile the source
Extract the resulting program, save to hard disk.