Hi René,

Great questions.  It sounds like you have a pretty good understanding of
the various phases.  I will reiterate your list, filling in a few details
for you.   At the high level emcc is the compiler driver, rather than the
compiler itself.  gcc and clang both take this roll too, and under the hood
both clang and gcc fork separate processes for the actual compiling and
linking.

emcc ->
   1. clang.exe: C-Code -> LLVM IR
   2. clang.exe: LLVM IR -> LLVM IR (optimized) (clang/llvm) ( this really
happens as part of (1) when you build with optimizations enabled)
   3. clang.exe: LLVM IR -> wasm object file
   4. wasm-ld.exe: combine files -> Wasm Binary
   5. wasm-opt.exe: Wasm Binary -> Optimized Wasm Binary (optional)
   6. emcc.py: Generate JS wrapper code (optional)


On Fri, Jun 2, 2023 at 9:25 AM René N. <wither2...@gmail.com> wrote:

> Hello guys,
>
> for a uni paper I need to explain how Emscripten works (on higher-level)
> to emit WebAssembly-Binary in the end.
> I'm new into compilers and toolchains and I'm not sure if I understand it
> correctly, how Emscripten is converting compatible code (like C) to
> WebAssembly Binary.
>
> If I got it right, for creating .wasm, these tools are used by Emscripten:
>
>    - emsdk as configurator for the whole toolchain
>    - emcc (which includes Clang+LLVM)
>    - the (upstream) LLVM WebAssembly Backend
>    - Binaryen
>
> So if i got it right, to create .wasm, the compilation works like this:
>
>    1. C-Code -> LLVM IR
>    2. LLVM IR -> LLVM IR (optimized)
>    3. LLVM IR (optimized) -> Wasm Binary
>    4. Wasm Binary -> Wasm Binary (optimized)
>    5. (Wasm Binary (optimized) -> JS) [optional]
>
> Did I forget something?
>
> What I am especially unsure of, is, which tool is doing what:
> So emcc uses Clang+LLVM. Now I'm not sure if emcc emits LLVM IR only
> (since Clang is creating LLVM IR), or does it also convert it to emit Wasm
> Binary (which means that the upstream LLVM Wasm Backend lies in the emcc)?
> What I'm quite sure of, is that step 1 is done by Clang and steps 4 & 5
> are done by Binaryen.
>
> Also, to me it seems like 'emcc' has 2 different meanings: 1. as part(!!)
> of the compilation process and 2. as command representation for the whole
> toolchain
>
> Also, which component/tool of Emscripten is creating the JS and HTML
> Gluecode?
>
> I'm happy if someone can help me out!
>
> --
> 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 emscripten-discuss+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/emscripten-discuss/3efb5151-1d5c-4ae1-89a5-b37ed3085793n%40googlegroups.com
> <https://groups.google.com/d/msgid/emscripten-discuss/3efb5151-1d5c-4ae1-89a5-b37ed3085793n%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 emscripten-discuss+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/emscripten-discuss/CAL_va2-0PF%2BM%3DWfea8S0XLB6dnQ4M4cMkcL3a5d-jwzu514spw%40mail.gmail.com.

Reply via email to