6 ms·
> Too high-level, too JavaScript-centric. It’s going to take programs encoded as Abstract Syntax Trees (ASTs) as input, which seems quite wrong. GCC, clang, and
by azakai 11y ago
> Too high-level, too JavaScript-centric. It’s going to take programs encoded as Abstract Syntax Trees (ASTs) as input, which seems quite wrong. GCC, clang, and other real-world compilers usually generate Control Flow Graphs (CFGs) at the output stage, not ASTs. Forcing compilers to convert CFGs back into ASTs seems silly.
An AST is used because it allows significantly smaller download sizes, which is quite important on the web, more details here:
https://github.com/WebAssembly/design/blob/master/AstSemantics.md https://github.com/WebAssembly/design/blob/master/AstSemanti...
WebAssembly is in a different situation than gcc, clang, etc. It makes sense for LLVM IR, for example, to have a CFG, as it is a compiler IR meant for optimization. But WebAssembly binaries are meant to be distributed over the web and instantiated as quickly as possible.
> This decision was clearly made to try and simplify the job of WebAssembly VM implementers, at the expense of everyone else.
I don't think that is the reason at all. In fact it adds work for those people to handle an AST. But the work is justified by the startup speed benefits that it brings to the web platform.
- pcwalton 11y agoI think Luke Wagner put it best. Paraphrased, "an encoded AST is just a bytecode for a register VM with a compressed encoding form for 'the last register I mentioned'". Besides, converting a CFG to a high-level AST is a complete non-problem these days.
- chas 11y agoWhat resources are there on the state of the art algorithm-wise for doing that conversion?
- azakai 11y agoOne option is the relooper [1][2] which is used in emscripten. It recreates high-level control structures as best it can, then falls back to a helper variable when it can't. Another option is node-splitting, where irreducible control flow is solved by duplicating code (but that has a bad worst-case code size increase). [1] http://dl.acm.org/citation.cfm?doid=2048147.2048224 http://dl.acm.org/citation.cfm?doid=2048147.2048224 [2] https://github.com/kripken/emscripten-fastcomp/blob/master/lib/Target/JSBackend/Relooper.h https://github.com/kripken/emscripten-fastcomp/blob/master/l...