Post AM34eErSqI6NHm3J0i by wim_v12e@cybre.space
 (DIR) More posts by wim_v12e@cybre.space
 (DIR) Post #AM34eErSqI6NHm3J0i by wim_v12e@cybre.space
       2022-07-31T10:56:35Z
       
       1 likes, 1 repeats
       
       I went down a deep rabbit hole (and I'm still falling). It started out with the idea of trying to compile #Uxntal into LLVM IR (and maybe WASM). Now I've jumped ships mid-course and changed to C as a target; I will probably, out of sheer perverseness, do Fortran as well. So this is decompilation of a stack-based assembly language into a non-stack-based higher-level language.It's one of these "how hard can it be?" things. The answer in short is, it's impossible; but there are degrees of approximation, and they are increasingly difficult. So it's a lot of fun.#compilers #decompilation
       
 (DIR) Post #AM67GiWiagrJGZZOka by lanodan@queer.hacktivis.me
       2022-08-01T22:18:40.912739Z
       
       0 likes, 0 repeats
       
       @wim_v12e Makes me wonder if someone did a QBE one for #uxntal.
       
 (DIR) Post #AM67J0Wcdz9jfOcKJc by csepp@merveilles.town
       2022-07-31T11:42:18Z
       
       0 likes, 0 repeats
       
       @wim_v12e Factor used an SSA compiler, so it should be somewhat possible, but if I remember correctly, the optimization guidelines say that some functions do need to use the stack because the compiler doesn't know ahead of time what they will do. 🤔I guess it falls into halting problem / Rice's theorem territory?
       
 (DIR) Post #AM67J1rveFnFplarAG by wim_v12e@cybre.space
       2022-07-31T12:45:15Z
       
       1 likes, 0 repeats
       
       @csepp Yes, that's it. In Uxntal you can compute the address you want to jump to. So the only way to know that value for sure is to run the program, and you can't be sure that it will every terminate. There is of course an obvious way around that which is to delegate all such constructs to runtime, by integrating the VM into the compiler. So when I say "impossible", it means "impossible to create a direct translation to a language that does not allow jumps to computed addresses". I am a bit tempted to allow e.g. linear operations on constants, as these are mostly likely the most common ones, but I'm not sufficiently motivated to implement that. My approach is indeed to create SSA-style registers, very much like LLVM does. But looking at LLVM IR in more detail, there is actually very little to be gained by using it as a target rather than C. And in C I don't need to insert phi functions.
       
 (DIR) Post #AM74JhhpzctKsxSnRY by wim_v12e@cybre.space
       2022-08-02T09:14:34Z
       
       1 likes, 0 repeats
       
       @lanodan Ah, nice, I didn't know about that. Looks a bit like a middle ground between C and LLVM IR. It would be a great target for my compiler.