I have been doing research in cross compile flash SWF files into C/C++ source files There are plenty of tools in decompiling SWF files into plain-text files formats. The Free SWF Decompiler provides plenty opensource solution on this.
To decompiler SWF into C/C++ source files, I had tried the following solutions
1) Haxe: The Haxe Compiler is responsible for translating the Haxe programming language to the target platform native source code or binary
To do this, I need to
a) Decompile SWF into actionscripts files
b) Convert actionscripts to Haxe language script
c) Compiler haxe into C++ source file
d) Recompiler C++ source files with Keil MDK-ARM
Drawback: The output C++ file is huge & contains many Flex SDK like resources in C source format, which is hard to re-compiler in Keil MDK-ARM. And it seem quite an inefficient job to get the Keil compilable binary code.
Recently, I had found another possible solution to do this by Adobe Flash C++ Compiler, ie FlasCC ( A complete BSD-like C/C++ development environment with a GCC based cross-compiler capable of targeting the Adobe Flash Runtime)
But I am not sure if it would work as I expected.
Since FlasCC can compile c/c++ code into ActionScript bytecode (ABC) as well as LLVM bytecode. My thought is
a) Parse SWF ActionScript bytecode (ABC)
b) Read ActionScript bytecode (ABC) in FlahCC (not sure if this can be done?)
c) By the equivalent ActionScript bytecode (ABC) in FlasCC, output its LLVM bytecode (not sure if this can be done?)
d) Convert LLVM bytecode to C++ code by LLC
In this way, the ActionScript bytecode can be optimized through LLVM LTO(Link Time Optimized) Build
Since I am not llvm expert, I need some advise on this.
Is this workable? Or is there any other way to do this?
Generally speaking, no. Auto-compilation of flash to binary will be quite complex thing to do and ineffective one too.
I'm surprised the first approach you used actually worked, I'd expect the resulting code to fail here and there randomly. Anyhow, there is not a single chance as3->haxe compilation can be effective in tems of resulting code performance.
As for the second approach, compilers are one-way thing, you can't use FlasCC to decompile ABC bytecode nor to compile as3, it can only be used to compile c/c++ to ABC.
Compilation of ABC to LLVM and then to binary seems much more feasible and doable, but will require quite a lot of effort and yet again I doubt the result will be any fast. And I'm almost sure it will be far slower than just an swf running in flash player on target platform. (Yet, considering the things you've already doneI'd estimate that you will be able to make a prototype in 2 or 3 month of hard work, so it may be worth a shot.)