LLVM: lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp File Reference (original) (raw)

This file lowers exception-related instructions and setjmp/longjmp function calls to use Emscripten's library functions. More...

This file lowers exception-related instructions and setjmp/longjmp function calls to use Emscripten's library functions.

The pass uses JavaScript's try and catch mechanism in case of Emscripten EH/SjLj and Wasm EH intrinsics in case of Emscripten SjLJ.

In detail, this pass does following things:

  1. Assumes the existence of global variables: THREW, threwValue __THREW and threwValue are defined in compiler-rt in Emscripten. These variables are used for both exceptions and setjmp/longjmps. __THREW indicates whether an exception or a longjmp occurred or not. 0 means nothing occurred, 1 means an exception occurred, and other numbers mean a longjmp occurred. In the case of longjmp, THREW variable indicates the corresponding setjmp buffer the longjmp corresponds to. __threwValue is 0 for exceptions, and the argument to longjmp in case of longjmp.
  1. We assume the existence of setThrew and setTempRet0/getTempRet0 functions at link time. setThrew exists in Emscripten's compiler-rt:

void setThrew(uintptr_t threw, int value) { if (THREW == 0) { THREW = threw; __threwValue = value; } }

Definition in file WebAssemblyLowerEmscriptenEHSjLj.cpp.