Hi Jacek,

Yes, basically that should work - run

emcc input.bc -o output.js

where input.bc is LLVM IR, and then you'll get a js+wasm combination that
you can run in node.js or on the Web. And with -o output.html you'd also
get html etc.

Things to be careful of:

 * The LLVM version that generated the IR should be close enough to
emscripten's LLVM version. It's best to use the wasm backend (
https://v8.dev/blog/emscripten-llvm-wasm#testing) with emscripten - the
default there is a very recent build of LLVM from master. If that's too new
for you, you can use an older emscripten version perhaps.
 * An alternative to using LLVM IR is to use wasm object files, which are a
much more stable format. You can emit those using your compiler's LLVM by
telling it to use the wasm backend, and then run emcc on that .o file.
 * Emscripten's libc etc. assume the code was compiled with the emscripten
headers. If not, the ABI may be incompatible for things like syscalls.

- Alon


On Wed, Aug 7, 2019 at 3:07 AM Jacek Sieka <[email protected]> wrote:

> Hi!
>
> I'm experimenting a little with wasm for a llvm-based compiler I'm working
> on - https://github.com/arnetheduck/nlvm - for the Nim language.
>
> Nim typically is compiled to C and then the C compiler takes over meaning
> that it's fairly straightforward get it to compile with emcc to wasm
> instead. In `nlvm`, Nim is compiled straight to llvm IR and consequently,
> nlvm is able to output wasm code as well.
>
> The next step that I think would make sense to get the Nim code to run in
> a browser would be to use the emscripten runtime, but from what I can tell,
> when emcc runs it customizes the runtime for the specific case.
>
> How does that work? IFor example, is there some tooling in emcc that I can
> give an llvm IR file to (which imports various C functions like
> clang-compiled C code would), and have emcc output the corresponding
> html/js/wasm files?
>
> Thanks!
>
> Jacek
>
> --
> You received this message because you are subscribed to the Google Groups
> "emscripten-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/emscripten-discuss/e3c2ada5-f2fa-4ccf-8558-ca30fde4e656%40googlegroups.com
> <https://groups.google.com/d/msgid/emscripten-discuss/e3c2ada5-f2fa-4ccf-8558-ca30fde4e656%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/emscripten-discuss/CAEX4NpSp2MpFBHAc6JU%3Dyi_yBCuCPpzEC%3DBwp_G2r9KGKsa7aQ%40mail.gmail.com.

Reply via email to