ribrdb / desynced-tools

Tools for working with behaviors and blueprints from Desynced.
MIT License
4 stars 3 forks source link

decompile to JS #64

Open ribrdb opened 5 months ago

ribrdb commented 5 months ago

My laptop died so I lost the progress I had on this. My latest idea was based on this paper: Baker, Brenda S. "An algorithm for structuring flowgraphs." Journal of the ACM (JACM) 24.1 (1977): 98-120. https://www.cs.tufts.edu/comp/150FP/archive/brenda-baker/structuring.pdf

And the source code for struct: https://github.com/dank101/4.3BSD-Reno/tree/master/pgrm/struct/struct

The desynced behaviors correlate pretty well with FORTRAN 66 if you treat dynamic jumps as computed goto, so we can translate from our internal IR to the struct ir (replacing stage 1 of struct), and then adjust the output stage to generate JS, either using the typescript AST factory or directly as text (which is more like the 4.out.c).

This fortran reference can help with understanding the struct code: https://docs.oracle.com/cd/E19957-01/805-4939/6j4m0vn79/index.html

My initial idea was to port the c code to typescript, although I wonder if we could compile it to wasm32. The c code is ancient and generates tons of warnings. I was able to get it running in a 32 bit arch linux vm running under qemu (https://mac.getutm.app/). It won't work at all with a 32 bit compiler.