|
13 | 13 | ///
|
14 | 14 | /// To handle exceptions and setjmp/longjmps, this scheme relies on JavaScript's
|
15 | 15 | /// try and catch syntax and relevant exception-related libraries implemented
|
16 |
| -/// in JavaScript glue code that will be produced by Emscripten. This is similar |
17 |
| -/// to the current Emscripten asm.js exception handling in fastcomp. For |
18 |
| -/// fastcomp's EH / SjLj scheme, see these files in fastcomp LLVM branch: |
19 |
| -/// (Location: https://github.com/kripken/emscripten-fastcomp) |
20 |
| -/// lib/Target/JSBackend/NaCl/LowerEmExceptionsPass.cpp |
21 |
| -/// lib/Target/JSBackend/NaCl/LowerEmSetjmp.cpp |
22 |
| -/// lib/Target/JSBackend/JSBackend.cpp |
23 |
| -/// lib/Target/JSBackend/CallHandlers.h |
| 16 | +/// in JavaScript glue code that will be produced by Emscripten. |
24 | 17 | ///
|
25 | 18 | /// * Exception handling
|
26 | 19 | /// This pass lowers invokes and landingpads into library functions in JS glue
|
|
50 | 43 | /// In detail, this pass does following things:
|
51 | 44 | ///
|
52 | 45 | /// 1) Assumes the existence of global variables: __THREW__, __threwValue
|
53 |
| -/// __THREW__ and __threwValue will be set in invoke wrappers |
54 |
| -/// in JS glue code. For what invoke wrappers are, refer to 3). These |
55 |
| -/// variables are used for both exceptions and setjmp/longjmps. |
| 46 | +/// __THREW__ and __threwValue are defined in compiler-rt in Emscripten. |
| 47 | +/// These variables are used for both exceptions and setjmp/longjmps. |
56 | 48 | /// __THREW__ indicates whether an exception or a longjmp occurred or not. 0
|
57 | 49 | /// means nothing occurred, 1 means an exception occurred, and other numbers
|
58 | 50 | /// mean a longjmp occurred. In the case of longjmp, __threwValue variable
|
|
61 | 53 | /// * Exception handling
|
62 | 54 | ///
|
63 | 55 | /// 2) We assume the existence of setThrew and setTempRet0/getTempRet0 functions
|
64 |
| -/// at link time. |
65 |
| -/// The global variables in 1) will exist in wasm address space, |
66 |
| -/// but their values should be set in JS code, so these functions |
67 |
| -/// as interfaces to JS glue code. These functions are equivalent to the |
68 |
| -/// following JS functions, which actually exist in asm.js version of JS |
69 |
| -/// library. |
| 56 | +/// at link time. setThrew exists in Emscripten's compiler-rt: |
70 | 57 | ///
|
71 |
| -/// function setThrew(threw, value) { |
| 58 | +/// void setThrew(int threw, int value) { |
72 | 59 | /// if (__THREW__ == 0) {
|
73 | 60 | /// __THREW__ = threw;
|
74 | 61 | /// __threwValue = value;
|
75 | 62 | /// }
|
76 | 63 | /// }
|
77 | 64 | //
|
78 | 65 | /// setTempRet0 is called from __cxa_find_matching_catch() in JS glue code.
|
79 |
| -/// |
80 | 66 | /// In exception handling, getTempRet0 indicates the type of an exception
|
81 | 67 | /// caught, and in setjmp/longjmp, it means the second argument to longjmp
|
82 | 68 | /// function.
|
|
105 | 91 | /// Module["dynCall_vi"](index,a1); // This calls original callee
|
106 | 92 | /// } catch(e) {
|
107 | 93 | /// if (typeof e !== 'number' && e !== 'longjmp') throw e;
|
108 |
| -/// asm["setThrew"](1, 0); // setThrew is called here |
| 94 | +/// _setThrew(1, 0); // setThrew is called here |
109 | 95 | /// }
|
110 | 96 | /// }
|
111 | 97 | /// If an exception is thrown, __THREW__ will be set to true in a wrapper,
|
|
149 | 135 | /// setjmpTableSize = 4;
|
150 | 136 | /// setjmpTable = (int *) malloc(40);
|
151 | 137 | /// setjmpTable[0] = 0;
|
152 |
| -/// setjmpTable and setjmpTableSize are used in saveSetjmp() function in JS |
153 |
| -/// code. |
| 138 | +/// setjmpTable and setjmpTableSize are used to call saveSetjmp() function in |
| 139 | +/// Emscripten compiler-rt. |
154 | 140 | ///
|
155 | 141 | /// 3) Lower
|
156 | 142 | /// setjmp(buf)
|
|
160 | 146 | /// For each dynamic setjmp call, setjmpTable stores its ID (a number which
|
161 | 147 | /// is incrementally assigned from 0) and its label (a unique number that
|
162 | 148 | /// represents each callsite of setjmp). When we need more entries in
|
163 |
| -/// setjmpTable, it is reallocated in saveSetjmp() in JS code and it will |
164 |
| -/// return the new table address, and assign the new table size in |
165 |
| -/// setTempRet0(). saveSetjmp also stores the setjmp's ID into the buffer |
166 |
| -/// buf. A BB with setjmp is split into two after setjmp call in order to |
167 |
| -/// make the post-setjmp BB the possible destination of longjmp BB. |
| 149 | +/// setjmpTable, it is reallocated in saveSetjmp() in Emscripten's |
| 150 | +/// compiler-rt and it will return the new table address, and assign the new |
| 151 | +/// table size in setTempRet0(). saveSetjmp also stores the setjmp's ID into |
| 152 | +/// the buffer buf. A BB with setjmp is split into two after setjmp call in |
| 153 | +/// order to make the post-setjmp BB the possible destination of longjmp BB. |
168 | 154 | ///
|
169 | 155 | ///
|
170 | 156 | /// 4) Lower every call that might longjmp into
|
@@ -505,7 +491,7 @@ bool WebAssemblyLowerEmscriptenEHSjLj::canLongjmp(Module &M,
|
505 | 491 | if (CalleeName == "setjmp" || CalleeName == "malloc" || CalleeName == "free")
|
506 | 492 | return false;
|
507 | 493 |
|
508 |
| - // There are functions in JS glue code |
| 494 | + // There are functions in Emscripten's JS glue code or compiler-rt |
509 | 495 | if (CalleeName == "__resumeException" || CalleeName == "llvm_eh_typeid_for" ||
|
510 | 496 | CalleeName == "saveSetjmp" || CalleeName == "testSetjmp" ||
|
511 | 497 | CalleeName == "getTempRet0" || CalleeName == "setTempRet0")
|
|
0 commit comments