How do I compile C++ to JavaScript in a browser?

别来无恙 提交于 2020-12-01 07:15:10

问题


I'm aware of Emscripten and LLVM, but neither are written in JavaScript intended for a browser.

As far as I can tell, the tools exist, but they haven't been put together, but I could very well be missing some key factor that makes it very difficult to compile C++ to JavaScript in a browser.

So I'll mention my naive implementation:

  1. Compile Emscripten to C, then use Clang to compile it to LLVM, then use Emscripten to compile it to JavaScript.
  2. Compile Clang to LLVM, then compile that to JavaScript through Emscripten.
  3. Write some C++ and run it through JavaScript Clang, then run that LLVM through Emscripten to get JavaSscript
  4. Run the resulting JavaScript!

I'm sure I'm missing something from my steps. Please let me know, and let me know if there are any efforts by the community to resolve those missing pieces.


EDIT: JSCPP is the closest I've found, but it lacks a lot of features and frankly the author took on an absurd undertaking, by trying to rewrite the parser etc. on his own, rather than using existing tools. Still, close and pretty neat.


回答1:


In theory, it may be possible to develop a self-hosting version of Emscripten that runs in a browser, though this hasn't been done yet.

Alternatively, it is possible to run a C++ compiler (or even an entire operating system) using an x86 emulator in JavaScript.



来源:https://stackoverflow.com/questions/44314441/how-do-i-compile-c-to-javascript-in-a-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!