Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Experiment] Emit also WebAssembly in the backend #34

Open
LefterisJP opened this issue Feb 17, 2017 · 4 comments
Open

[Experiment] Emit also WebAssembly in the backend #34

LefterisJP opened this issue Feb 17, 2017 · 4 comments

Comments

@LefterisJP
Copy link
Contributor

LefterisJP commented Feb 17, 2017

Think on the benefits of adding emitting web assembly from Refu.
Think if it makes sense to also emit WebAssembly code for web development.

It would be quite easy to do since LLVM can directly translate to Web Assembly

@LefterisJP LefterisJP changed the title [Experiment] Add WASM backend [Experiment] Emit also WebAssembly in the backend Feb 17, 2017
@axic
Copy link
Contributor

axic commented Feb 20, 2017

We've tried this and the LLVM IR output generated using the --output-backend can be compiled using llc to WebAssembly. If there would be an output, say --output-llvm-ir, which doesn't include the debug lines and only outputs a single, linked IR, that could be compiled to WebAssembly without manual changes.

A few language features could help a lot in making this better:

  1. Support namespaces in foreign_import. Wasm has a two-level import system, where each import has a namespace and a symbol.

  2. Support a way to specify actual exports. Currently all global functions are exported.

  3. Support emitting Webassembly inline assembly (or at least the (unreachable) instruction)

@axic
Copy link
Contributor

axic commented Feb 20, 2017

@axic
Copy link
Contributor

axic commented Feb 25, 2017

There's a --llvm-ir option now to display the IR on the standard output. Perhaps it should be changed to emit a file out.

@LefterisJP
Copy link
Contributor Author

That is going to be easy, LLVM has a PrintToFile method, existing even in 3.7.

/**
 * Print a representation of a module to a file. The ErrorMessage needs to be
 * disposed with LLVMDisposeMessage. Returns 0 on success, 1 otherwise.
 *
 * @see Module::print()
 */
LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename,
                               char **ErrorMessage);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants