webruby 0.2.2 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (245) hide show
  1. checksums.yaml +4 -4
  2. data/lib/webruby/config.rb +4 -9
  3. data/lib/webruby/rake/files.rake +2 -2
  4. data/modules/emscripten/AUTHORS +9 -1
  5. data/modules/emscripten/CONTRIBUTING.markdown +5 -0
  6. data/modules/emscripten/ChangeLog +435 -0
  7. data/modules/emscripten/cmake/Modules/FindOpenAL.cmake +26 -0
  8. data/modules/emscripten/cmake/Platform/Emscripten.cmake +9 -2
  9. data/modules/emscripten/em++ +0 -2
  10. data/modules/emscripten/emcc +92 -32
  11. data/modules/emscripten/emlink.py +16 -13
  12. data/modules/emscripten/emmake +1 -1
  13. data/modules/emscripten/emrun +918 -0
  14. data/modules/emscripten/emrun.bat +2 -0
  15. data/modules/emscripten/emscripten.py +545 -20
  16. data/modules/emscripten/src/analyzer.js +6 -1
  17. data/modules/emscripten/src/compiler.js +25 -16
  18. data/modules/emscripten/src/emrun_postjs.js +20 -0
  19. data/modules/emscripten/{tests → src}/hello_world.js +0 -0
  20. data/modules/emscripten/src/intertyper.js +45 -16
  21. data/modules/emscripten/src/jsifier.js +78 -48
  22. data/modules/emscripten/src/library.js +381 -96
  23. data/modules/emscripten/src/library_browser.js +50 -53
  24. data/modules/emscripten/src/library_egl.js +66 -24
  25. data/modules/emscripten/src/library_fs.js +122 -90
  26. data/modules/emscripten/src/library_gl.js +739 -353
  27. data/modules/emscripten/src/library_glfw.js +9 -3
  28. data/modules/emscripten/src/library_glut.js +10 -5
  29. data/modules/emscripten/src/library_idbfs.js +14 -14
  30. data/modules/emscripten/src/library_memfs.js +65 -41
  31. data/modules/emscripten/src/library_nodefs.js +61 -9
  32. data/modules/emscripten/src/library_openal.js +4 -4
  33. data/modules/emscripten/src/library_path.js +9 -13
  34. data/modules/emscripten/src/library_sdl.js +301 -64
  35. data/modules/emscripten/src/library_sockfs.js +7 -5
  36. data/modules/emscripten/src/modules.js +62 -22
  37. data/modules/emscripten/src/parseTools.js +135 -102
  38. data/modules/emscripten/src/postamble.js +3 -4
  39. data/modules/emscripten/src/preamble.js +49 -29
  40. data/modules/emscripten/src/proxyClient.js +1 -1
  41. data/modules/emscripten/src/proxyWorker.js +10 -10
  42. data/modules/emscripten/src/relooper/Relooper.cpp +15 -4
  43. data/modules/emscripten/src/runtime.js +32 -8
  44. data/modules/emscripten/src/settings.js +25 -8
  45. data/modules/emscripten/src/shell.html +6 -3
  46. data/modules/emscripten/src/shell.js +13 -11
  47. data/modules/emscripten/src/simd.js +602 -432
  48. data/modules/emscripten/src/struct_info.json +22 -2
  49. data/modules/emscripten/src/utility.js +32 -17
  50. data/modules/emscripten/system/include/SDL/SDL_events.h +1 -0
  51. data/modules/emscripten/system/include/compat/ctype.h +17 -0
  52. data/modules/emscripten/system/include/compat/wchar.h +23 -0
  53. data/modules/emscripten/system/include/compat/wctype.h +23 -0
  54. data/modules/emscripten/system/include/emscripten/emmintrin.h +87 -0
  55. data/modules/emscripten/system/include/emscripten/emscripten.h +30 -4
  56. data/modules/emscripten/system/include/emscripten/vector.h +29 -1
  57. data/modules/emscripten/system/include/emscripten/xmmintrin.h +131 -0
  58. data/modules/emscripten/system/include/libcxx/CREDITS.TXT +9 -1
  59. data/modules/emscripten/system/include/libcxx/__bit_reference +8 -8
  60. data/modules/emscripten/system/include/libcxx/__config +95 -17
  61. data/modules/emscripten/system/include/libcxx/__debug +25 -4
  62. data/modules/emscripten/system/include/libcxx/__functional_03 +7 -7
  63. data/modules/emscripten/system/include/libcxx/__functional_base +169 -9
  64. data/modules/emscripten/system/include/libcxx/__functional_base_03 +1 -1
  65. data/modules/emscripten/system/include/libcxx/__hash_table +25 -25
  66. data/modules/emscripten/system/include/libcxx/__locale +21 -19
  67. data/modules/emscripten/system/include/libcxx/__mutex_base +2 -33
  68. data/modules/emscripten/system/include/libcxx/__split_buffer +9 -9
  69. data/modules/emscripten/system/include/libcxx/__std_stream +14 -0
  70. data/modules/emscripten/system/include/libcxx/__tree +35 -26
  71. data/modules/emscripten/system/include/libcxx/__tuple +15 -15
  72. data/modules/emscripten/system/include/libcxx/__tuple_03 +2 -2
  73. data/modules/emscripten/system/include/libcxx/__undef_min_max +8 -0
  74. data/modules/emscripten/system/include/libcxx/algorithm +121 -110
  75. data/modules/emscripten/system/include/libcxx/array +15 -15
  76. data/modules/emscripten/system/include/libcxx/bitset +4 -4
  77. data/modules/emscripten/system/include/libcxx/chrono +51 -17
  78. data/modules/emscripten/system/include/libcxx/cmath +25 -23
  79. data/modules/emscripten/system/include/libcxx/codecvt +21 -18
  80. data/modules/emscripten/system/include/libcxx/complex +48 -7
  81. data/modules/emscripten/system/include/libcxx/cstddef +1 -1
  82. data/modules/emscripten/system/include/libcxx/cstdio +8 -1
  83. data/modules/emscripten/system/include/libcxx/cstdlib +1 -1
  84. data/modules/emscripten/system/include/libcxx/cwchar +1 -1
  85. data/modules/emscripten/system/include/libcxx/deque +26 -12
  86. data/modules/emscripten/system/include/libcxx/dynarray +311 -0
  87. data/modules/emscripten/system/include/libcxx/exception +4 -4
  88. data/modules/emscripten/system/include/libcxx/ext/__hash +3 -3
  89. data/modules/emscripten/system/include/libcxx/ext/hash_map +19 -15
  90. data/modules/emscripten/system/include/libcxx/ext/hash_set +7 -3
  91. data/modules/emscripten/system/include/libcxx/forward_list +33 -7
  92. data/modules/emscripten/system/include/libcxx/fstream +4 -4
  93. data/modules/emscripten/system/include/libcxx/functional +200 -170
  94. data/modules/emscripten/system/include/libcxx/future +83 -39
  95. data/modules/emscripten/system/include/libcxx/initializer_list +24 -11
  96. data/modules/emscripten/system/include/libcxx/iomanip +147 -0
  97. data/modules/emscripten/system/include/libcxx/ios +24 -16
  98. data/modules/emscripten/system/include/libcxx/iosfwd +19 -19
  99. data/modules/emscripten/system/include/libcxx/istream +13 -8
  100. data/modules/emscripten/system/include/libcxx/iterator +108 -417
  101. data/modules/emscripten/system/include/libcxx/limits +8 -4
  102. data/modules/emscripten/system/include/libcxx/list +28 -8
  103. data/modules/emscripten/system/include/libcxx/locale +153 -390
  104. data/modules/emscripten/system/include/libcxx/map +280 -100
  105. data/modules/emscripten/system/include/libcxx/memory +49 -97
  106. data/modules/emscripten/system/include/libcxx/mutex +2 -2
  107. data/modules/emscripten/system/include/libcxx/new +43 -14
  108. data/modules/emscripten/system/include/libcxx/numeric +2 -2
  109. data/modules/emscripten/system/include/libcxx/optional +697 -0
  110. data/modules/emscripten/system/include/libcxx/ostream +17 -8
  111. data/modules/emscripten/system/include/libcxx/queue +5 -5
  112. data/modules/emscripten/system/include/libcxx/random +53 -51
  113. data/modules/emscripten/system/include/libcxx/ratio +11 -11
  114. data/modules/emscripten/system/include/libcxx/readme.txt +1 -1
  115. data/modules/emscripten/system/include/libcxx/regex +23 -20
  116. data/modules/emscripten/system/include/libcxx/scoped_allocator +1 -1
  117. data/modules/emscripten/system/include/libcxx/set +166 -2
  118. data/modules/emscripten/system/include/libcxx/shared_mutex +419 -0
  119. data/modules/emscripten/system/include/libcxx/sstream +4 -4
  120. data/modules/emscripten/system/include/libcxx/stack +3 -3
  121. data/modules/emscripten/system/include/libcxx/streambuf +5 -5
  122. data/modules/emscripten/system/include/libcxx/string +372 -324
  123. data/modules/emscripten/system/include/libcxx/support/ibm/limits.h +99 -0
  124. data/modules/emscripten/system/include/libcxx/support/ibm/support.h +54 -0
  125. data/modules/emscripten/system/include/libcxx/support/ibm/xlocale.h +326 -0
  126. data/modules/emscripten/system/include/libcxx/support/win32/limits_win32.h +6 -6
  127. data/modules/emscripten/system/include/libcxx/support/win32/locale_win32.h +15 -15
  128. data/modules/emscripten/system/include/libcxx/support/win32/math_win32.h +2 -0
  129. data/modules/emscripten/system/include/libcxx/support/win32/support.h +6 -1
  130. data/modules/emscripten/system/include/libcxx/system_error +14 -8
  131. data/modules/emscripten/system/include/libcxx/thread +7 -8
  132. data/modules/emscripten/system/include/libcxx/tuple +29 -88
  133. data/modules/emscripten/system/include/libcxx/type_traits +253 -209
  134. data/modules/emscripten/system/include/libcxx/typeindex +3 -3
  135. data/modules/emscripten/system/include/libcxx/unordered_map +162 -101
  136. data/modules/emscripten/system/include/libcxx/unordered_set +79 -2
  137. data/modules/emscripten/system/include/libcxx/utility +20 -20
  138. data/modules/emscripten/system/include/libcxx/valarray +23 -23
  139. data/modules/emscripten/system/include/libcxx/vector +114 -91
  140. data/modules/emscripten/system/lib/libc/musl/src/regex/regcomp.c +3352 -0
  141. data/modules/emscripten/system/lib/libc/musl/src/regex/regerror.c +35 -0
  142. data/modules/emscripten/system/lib/libc/musl/src/regex/regexec.c +1011 -0
  143. data/modules/emscripten/system/lib/libc/musl/src/regex/tre-mem.c +158 -0
  144. data/modules/emscripten/system/lib/libc/musl/src/regex/tre.h +231 -0
  145. data/modules/emscripten/system/lib/libcextra.symbols +7 -0
  146. data/modules/emscripten/system/lib/libcxx/CREDITS.TXT +9 -1
  147. data/modules/emscripten/system/lib/libcxx/algorithm.cpp +1 -0
  148. data/modules/emscripten/system/lib/libcxx/debug.cpp +66 -42
  149. data/modules/emscripten/system/lib/libcxx/exception.cpp +88 -16
  150. data/modules/emscripten/system/lib/libcxx/future.cpp +6 -0
  151. data/modules/emscripten/system/lib/libcxx/ios.cpp +7 -2
  152. data/modules/emscripten/system/lib/libcxx/iostream.cpp +8 -8
  153. data/modules/emscripten/system/lib/libcxx/locale.cpp +38 -11
  154. data/modules/emscripten/system/lib/libcxx/mutex.cpp +3 -0
  155. data/modules/emscripten/system/lib/libcxx/new.cpp +44 -10
  156. data/modules/emscripten/system/lib/libcxx/optional.cpp +25 -0
  157. data/modules/emscripten/system/lib/libcxx/random.cpp +26 -0
  158. data/modules/emscripten/system/lib/libcxx/readme.txt +1 -1
  159. data/modules/emscripten/system/lib/libcxx/shared_mutex.cpp +101 -0
  160. data/modules/emscripten/system/lib/libcxx/stdexcept.cpp +11 -7
  161. data/modules/emscripten/system/lib/libcxx/string.cpp +3 -1
  162. data/modules/emscripten/system/lib/libcxx/strstream.cpp +7 -7
  163. data/modules/emscripten/system/lib/libcxx/support/win32/locale_win32.cpp +12 -13
  164. data/modules/emscripten/system/lib/libcxx/support/win32/support.cpp +33 -36
  165. data/modules/emscripten/system/lib/libcxx/symbols +187 -168
  166. data/modules/emscripten/system/lib/libcxx/system_error.cpp +1 -0
  167. data/modules/emscripten/system/lib/libcxx/thread.cpp +7 -3
  168. data/modules/emscripten/system/lib/libcxx/typeinfo.cpp +9 -6
  169. data/modules/emscripten/system/lib/libcxx/valarray.cpp +2 -0
  170. data/modules/emscripten/third_party/lzma.js/doit.bat +4 -0
  171. data/modules/emscripten/third_party/lzma.js/doit.sh +9 -2
  172. data/modules/emscripten/tools/cache.py +5 -7
  173. data/modules/emscripten/tools/cache.pyc +0 -0
  174. data/modules/emscripten/tools/eliminator/asm-eliminator-test-output.js +7 -0
  175. data/modules/emscripten/tools/eliminator/asm-eliminator-test.js +9 -1
  176. data/modules/emscripten/tools/eliminator/eliminator-test-output.js +3 -0
  177. data/modules/emscripten/tools/eliminator/eliminator-test.js +9 -1
  178. data/modules/emscripten/tools/file_packager.py +93 -50
  179. data/modules/emscripten/tools/js-optimizer.js +98 -48
  180. data/modules/emscripten/tools/js_optimizer.py +4 -4
  181. data/modules/emscripten/tools/js_optimizer.pyc +0 -0
  182. data/modules/emscripten/tools/jsrun.py +1 -1
  183. data/modules/emscripten/tools/jsrun.pyc +0 -0
  184. data/modules/emscripten/tools/response_file.py +6 -0
  185. data/modules/emscripten/tools/response_file.pyc +0 -0
  186. data/modules/emscripten/tools/settings_template_readonly.py +2 -0
  187. data/modules/emscripten/tools/shared.py +88 -34
  188. data/modules/emscripten/tools/shared.pyc +0 -0
  189. data/modules/emscripten/tools/split.py +21 -13
  190. data/modules/mruby/build_config.rb +7 -1
  191. data/modules/mruby/doc/compile/README.md +5 -9
  192. data/modules/mruby/include/mrbconf.h +5 -2
  193. data/modules/mruby/include/mruby/array.h +1 -0
  194. data/modules/mruby/include/mruby/compile.h +2 -4
  195. data/modules/mruby/include/mruby/dump.h +7 -16
  196. data/modules/mruby/include/mruby/hash.h +1 -1
  197. data/modules/mruby/include/mruby/irep.h +14 -2
  198. data/modules/mruby/include/mruby/khash.h +8 -7
  199. data/modules/mruby/include/mruby/string.h +1 -0
  200. data/modules/mruby/include/mruby/value.h +5 -2
  201. data/modules/mruby/include/mruby.h +12 -13
  202. data/modules/mruby/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c +16 -6
  203. data/modules/mruby/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c +18 -30
  204. data/modules/mruby/mrbgems/mruby-fiber/src/fiber.c +21 -0
  205. data/modules/mruby/mrbgems/mruby-math/src/math.c +1 -1
  206. data/modules/mruby/mrbgems/mruby-random/src/random.c +144 -47
  207. data/modules/mruby/mrbgems/mruby-random/test/random.rb +44 -0
  208. data/modules/mruby/mrbgems/mruby-struct/src/struct.c +5 -5
  209. data/modules/mruby/mrblib/numeric.rb +99 -33
  210. data/modules/mruby/src/array.c +11 -4
  211. data/modules/mruby/src/backtrace.c +2 -2
  212. data/modules/mruby/src/class.c +49 -30
  213. data/modules/mruby/src/codegen.c +131 -79
  214. data/modules/mruby/src/debug.c +1 -1
  215. data/modules/mruby/src/dump.c +213 -163
  216. data/modules/mruby/src/error.c +17 -17
  217. data/modules/mruby/src/error.h +1 -1
  218. data/modules/mruby/src/etc.c +10 -0
  219. data/modules/mruby/src/gc.c +35 -17
  220. data/modules/mruby/src/hash.c +5 -5
  221. data/modules/mruby/src/kernel.c +36 -14
  222. data/modules/mruby/src/load.c +238 -296
  223. data/modules/mruby/src/numeric.c +18 -98
  224. data/modules/mruby/src/object.c +3 -5
  225. data/modules/mruby/src/parse.y +63 -56
  226. data/modules/mruby/src/proc.c +8 -5
  227. data/modules/mruby/src/re.h +0 -1
  228. data/modules/mruby/src/state.c +65 -27
  229. data/modules/mruby/src/string.c +3 -31
  230. data/modules/mruby/src/symbol.c +3 -3
  231. data/modules/mruby/src/variable.c +12 -5
  232. data/modules/mruby/src/vm.c +90 -72
  233. data/modules/mruby/tasks/mruby_build.rake +10 -1
  234. data/modules/mruby/tasks/toolchains/gcc.rake +12 -2
  235. data/modules/mruby/tasks/toolchains/{vs2012.rake → visualcpp.rake} +1 -1
  236. data/modules/mruby/test/driver.c +3 -3
  237. data/modules/mruby/test/t/array.rb +5 -5
  238. data/modules/mruby/test/t/class.rb +14 -1
  239. data/modules/mruby/test/t/kernel.rb +4 -0
  240. data/modules/mruby/test/t/module.rb +4 -4
  241. data/modules/mruby/test/t/nameerror.rb +1 -1
  242. data/modules/mruby/tools/mrbc/mrbc.c +23 -17
  243. data/modules/mruby/travis_config.rb +10 -1
  244. metadata +28 -5
  245. data/modules/mruby/tasks/toolchains/vs2010.rake +0 -3
@@ -25,6 +25,7 @@ var SHADOW_FLIP = { i64: 'double', double: 'i64' }; //, i32: 'float', float: 'i3
25
25
  // Analyzer
26
26
 
27
27
  function analyzer(data, sidePass) {
28
+ //B.start('analyzer');
28
29
  var mainPass = !sidePass;
29
30
 
30
31
  var item = { items: data };
@@ -417,7 +418,7 @@ function analyzer(data, sidePass) {
417
418
  toAdd.push({
418
419
  intertype: 'value',
419
420
  assignTo: element.ident,
420
- type: element.bits,
421
+ type: 'i' + element.bits,
421
422
  ident: 'tempRet' + (j - 1)
422
423
  });
423
424
  assert(j<10); // TODO: dynamically create more than 10 tempRet-s
@@ -1661,11 +1662,13 @@ function analyzer(data, sidePass) {
1661
1662
  function stackAnalyzer() {
1662
1663
  data.functions.forEach(function(func) {
1663
1664
  var lines = func.labels[0].lines;
1665
+ var hasAlloca = false;
1664
1666
  for (var i = 0; i < lines.length; i++) {
1665
1667
  var item = lines[i];
1666
1668
  if (!item.assignTo || item.intertype != 'alloca' || !isNumber(item.ident)) break;
1667
1669
  item.allocatedSize = func.variables[item.assignTo].impl === VAR_EMULATED ?
1668
1670
  calcAllocatedSize(item.allocatedType)*item.ident: 0;
1671
+ hasAlloca = true;
1669
1672
  if (USE_TYPED_ARRAYS === 2) {
1670
1673
  // We need to keep the stack aligned
1671
1674
  item.allocatedSize = Runtime.forceAlign(item.allocatedSize, Runtime.STACK_ALIGN);
@@ -1681,6 +1684,7 @@ function analyzer(data, sidePass) {
1681
1684
  }
1682
1685
  func.initialStack = index;
1683
1686
  func.otherStackAllocations = false;
1687
+ if (func.initialStack === 0 && hasAlloca) func.otherStackAllocations = true; // a single alloca of zero still requires us to emit stack support code
1684
1688
  while (func.initialStack == 0) { // one-time loop with possible abort in the middle
1685
1689
  // If there is no obvious need for stack management, perhaps we don't need it
1686
1690
  // (we try to optimize that way with SKIP_STACK_IN_SMALL). However,
@@ -1761,6 +1765,7 @@ function analyzer(data, sidePass) {
1761
1765
  stackAnalyzer();
1762
1766
  relooper();
1763
1767
 
1768
+ //B.stop('analyzer');
1764
1769
  return item;
1765
1770
  }
1766
1771
 
@@ -206,12 +206,12 @@ if (phase == 'pre') {
206
206
  if (VERBOSE) printErr('VERBOSE is on, this generates a lot of output and can slow down compilation');
207
207
 
208
208
  // Load struct and define information.
209
- try {
209
+ //try {
210
210
  var temp = JSON.parse(read(STRUCT_INFO));
211
- } catch(e) {
212
- printErr('cannot load struct info at ' + STRUCT_INFO + ' : ' + e + ', trying in current dir');
213
- temp = JSON.parse(read('struct_info.compiled.json'));
214
- }
211
+ //} catch(e) {
212
+ // printErr('cannot load struct info at ' + STRUCT_INFO + ' : ' + e + ', trying in current dir');
213
+ // temp = JSON.parse(read('struct_info.compiled.json'));
214
+ //}
215
215
  C_STRUCTS = temp.structs;
216
216
  C_DEFINES = temp.defines;
217
217
 
@@ -224,12 +224,12 @@ load('analyzer.js');
224
224
  load('jsifier.js');
225
225
  if (phase == 'funcs' && RELOOP) { // XXX handle !singlePhase
226
226
  RelooperModule = { TOTAL_MEMORY: ceilPowerOfTwo(2*RELOOPER_BUFFER_SIZE) };
227
- try {
227
+ //try {
228
228
  load(RELOOPER);
229
- } catch(e) {
230
- printErr('cannot load relooper at ' + RELOOPER + ' : ' + e + ', trying in current dir');
231
- load('relooper.js');
232
- }
229
+ //} catch(e) {
230
+ // printErr('cannot load relooper at ' + RELOOPER + ' : ' + e + ', trying in current dir');
231
+ // load('relooper.js');
232
+ //}
233
233
  assert(typeof Relooper != 'undefined');
234
234
  }
235
235
  globalEval(processMacros(preprocess(read('runtime.js'))));
@@ -267,7 +267,7 @@ function compile(raw) {
267
267
  function runPhase(currPhase) {
268
268
  //printErr('// JS compiler in action, phase ' + currPhase + typeof lines + (lines === null));
269
269
  phase = currPhase;
270
- if (phase != 'pre') {
270
+ if (phase != 'pre' && phase != 'glue') {
271
271
  if (singlePhase) PassManager.load(read(forwardedDataFile));
272
272
 
273
273
  if (phase == 'funcs') {
@@ -285,6 +285,7 @@ function compile(raw) {
285
285
 
286
286
  //dumpInterProf();
287
287
  //printErr(phase + ' paths (fast, slow): ' + [fastPaths, slowPaths]);
288
+ B.print(phase);
288
289
 
289
290
  phase = null;
290
291
 
@@ -308,12 +309,20 @@ function compile(raw) {
308
309
  }
309
310
  }
310
311
 
311
- if (ll_file) {
312
- if (ll_file.indexOf(String.fromCharCode(10)) == -1) {
313
- compile(read(ll_file));
314
- } else {
315
- compile(ll_file); // we are given raw .ll
312
+ B = new Benchmarker();
313
+
314
+ try {
315
+ if (ll_file) {
316
+ if (phase === 'glue') {
317
+ compile(';');
318
+ } else if (ll_file.indexOf(String.fromCharCode(10)) == -1) {
319
+ compile(read(ll_file));
320
+ } else {
321
+ compile(ll_file); // we are given raw .ll
322
+ }
316
323
  }
324
+ } catch(err) {
325
+ printErr('aborting from js compiler due to exception: ' + err + ' | ' + err.stack);
317
326
  }
318
327
 
319
328
  //var M = keys(tokenCacheMisses).map(function(m) { return [m, misses[m]] }).sort(function(a, b) { return a[1] - b[1] });
@@ -0,0 +1,20 @@
1
+ function emrun_register_handlers() {
2
+ function post(msg) {
3
+ var http = new XMLHttpRequest();
4
+ http.open("POST", "stdio.html", true);
5
+ http.send(msg);
6
+ }
7
+ // If the address contains localhost, we can assume we're running the test runner and should post stdout logs.
8
+ if (document.URL.search("localhost") != -1) {
9
+ var emrun_http_sequence_number = 1;
10
+ var prevExit = Module['exit'];
11
+ var prevPrint = Module['print'];
12
+ var prevErr = Module['printErr'];
13
+ Module['exit'] = function emrun_exit(returncode) { post('^exit^'+returncode); prevExit(returncode); }
14
+ Module['print'] = function emrun_print(text) { post('^out^'+(emrun_http_sequence_number++)+'^'+text); prevPrint(text); }
15
+ Module['printErr'] = function emrun_printErr(text) { post('^err^'+(emrun_http_sequence_number++)+'^'+text); prevErr(text); }
16
+ }
17
+ // Notify emrun web server that this browser has successfully launched the page.
18
+ post('^pageload^');
19
+ }
20
+ emrun_register_handlers();
File without changes
@@ -153,6 +153,7 @@ var NSW_NUW = set('nsw', 'nuw');
153
153
  // Intertyper
154
154
 
155
155
  function intertyper(lines, sidePass, baseLineNums) {
156
+ //B.start('intertyper');
156
157
  var mainPass = !sidePass;
157
158
  baseLineNums = baseLineNums || [[0,0]]; // each pair [#0,#1] means "starting from line #0, the base line num is #1"
158
159
 
@@ -470,8 +471,8 @@ function intertyper(lines, sidePass, baseLineNums) {
470
471
  item.tokens[1] = item.tokens[1].tokens[0];
471
472
  }
472
473
  var subTokens = item.tokens[1].tokens;
473
- if (subTokens) {
474
- subTokens.push({text:','});
474
+ if (subTokens && subTokens.length > 0) {
475
+ subTokens.push({text:','}); // XXX we should avoid altering tokens like that
475
476
  while (subTokens[0]) {
476
477
  var stop = 1;
477
478
  while ([','].indexOf(subTokens[stop].text) == -1) stop ++;
@@ -523,6 +524,27 @@ function intertyper(lines, sidePass, baseLineNums) {
523
524
  }
524
525
  });
525
526
  }
527
+ } else if (ident == '_llvm_used') {
528
+ var chunk = item.tokens[1].tokens;
529
+ var funcs = [];
530
+ var part = [];
531
+
532
+ for (var i = 0; i < chunk.length; i++) {
533
+ if (chunk[i].text == ',') {
534
+ var call = parseLLVMFunctionCall(part);
535
+ EXPORTED_FUNCTIONS[call.ident] = 0;
536
+ part = [];
537
+ } else {
538
+ part.push(chunk[i]);
539
+ }
540
+ }
541
+ if (part.length > 0) {
542
+ var call = parseLLVMFunctionCall(part);
543
+ EXPORTED_FUNCTIONS[call.ident] = 0;
544
+ }
545
+
546
+ ret.type = 'i32';
547
+ ret.value = { intertype: 'value', ident: '0', value: '0', type: ret.type };
526
548
  } else if (!external) {
527
549
  if (item.tokens[1] && item.tokens[1].text != ';') {
528
550
  if (item.tokens[1].text == 'c') {
@@ -537,6 +559,7 @@ function intertyper(lines, sidePass, baseLineNums) {
537
559
  ret.value = { intertype: 'value', ident: '0', value: '0', type: ret.type };
538
560
  }
539
561
  }
562
+
540
563
  return ret;
541
564
  }
542
565
  }
@@ -615,7 +638,8 @@ function intertyper(lines, sidePass, baseLineNums) {
615
638
  // 'bitcast'
616
639
  function bitcastHandler(item) {
617
640
  item.intertype = 'bitcast';
618
- item.type = item.tokens[4].text; // The final type
641
+ var last = getTokenIndexByText(item.tokens, ';');
642
+ item.type = item.tokens[Math.min(last, item.tokens.length-1)].text; // The final type
619
643
  Types.needAnalysis[item.type] = 0;
620
644
  var to = getTokenIndexByText(item.tokens, 'to');
621
645
  item.params = [parseLLVMSegment(item.tokens.slice(1, to))];
@@ -659,9 +683,10 @@ function intertyper(lines, sidePass, baseLineNums) {
659
683
  var tokensLeft = item.tokens.slice(2);
660
684
  item.ident = eatLLVMIdent(tokensLeft);
661
685
  if (item.ident == 'asm') {
686
+ warnOnce('inline JavaScript using asm() has some oddities due to how gcc asm() syntax works. use EM_ASM where possible (see emscripten.h)');
662
687
  if (ASM_JS) {
663
688
  Types.hasInlineJS = true;
664
- warnOnce('inline JavaScript (asm, EM_ASM) will cause the code to no longer fall in the asm.js subset of JavaScript, which can reduce performance - consider using emscripten_run_script');
689
+ warnOnce('inline JavaScript using asm() will cause the code to no longer fall in the asm.js subset of JavaScript, which can reduce performance - consider using emscripten_run_script');
665
690
  }
666
691
  assert(TARGET_LE32, 'inline js is only supported in le32');
667
692
  // Inline assembly is just JavaScript that we paste into the code
@@ -671,15 +696,20 @@ function intertyper(lines, sidePass, baseLineNums) {
671
696
  assert((item.tokens[5].text.match(/=/g) || []).length <= 1, 'we only support at most 1 exported variable from inline js: ' + item.ident);
672
697
  var i = 0;
673
698
  var params = [], args = [];
674
- splitTokenList(tokensLeft[3].tokens).map(function(element) {
675
- var ident = toNiceIdent(element[1].text);
676
- var type = element[0].text;
677
- params.push('$' + (i++));
678
- args.push(ident);
699
+ if (tokensLeft[3].tokens) {
700
+ splitTokenList(tokensLeft[3].tokens).map(function(element) {
701
+ var ident = toNiceIdent(element[1].text);
702
+ var type = element[0].text;
703
+ params.push('$' + (i++));
704
+ args.push(ident);
705
+ });
706
+ }
707
+ item.ident = expandLLVMString(item.ident).replace(/(#[^\n]*)/g, function(m) {
708
+ return '/* ' + m.substr(1) + ' */'; // fix asm comments to js comments
679
709
  });
680
710
  if (item.assignTo) item.ident = 'return ' + item.ident;
681
711
  item.ident = '(function(' + params + ') { ' + item.ident + ' })(' + args + ');';
682
- return { forward: null, ret: item, item: item };
712
+ return { ret: item, item: item };
683
713
  }
684
714
  if (item.ident.substr(-2) == '()') {
685
715
  // See comment in isStructType()
@@ -702,13 +732,12 @@ function intertyper(lines, sidePass, baseLineNums) {
702
732
  if (item.indent == 2) {
703
733
  // standalone call - not in assign
704
734
  item.standalone = true;
705
- return { forward: null, ret: item, item: item };
735
+ return { ret: item, item: item };
706
736
  }
707
- return { forward: item, ret: null, item: item };
737
+ return { ret: null, item: item };
708
738
  }
709
739
  function callHandler(item) {
710
740
  var result = makeCall.call(this, item, 'call');
711
- if (result.forward) this.forwardItem(result.forward, 'Reintegrator');
712
741
  return result.ret;
713
742
  }
714
743
  function invokeHandler(item) {
@@ -718,10 +747,9 @@ function intertyper(lines, sidePass, baseLineNums) {
718
747
  finalResults.push({
719
748
  intertype: 'branch',
720
749
  label: result.item.toLabel,
721
- lineNum: (result.forward ? item.parentLineNum : item.lineNum) + 0.5
750
+ lineNum: item.lineNum + 0.5
722
751
  });
723
752
  }
724
- if (result.forward) this.forwardItem(result.forward, 'Reintegrator');
725
753
  return result.ret;
726
754
  }
727
755
  function atomicHandler(item) {
@@ -838,7 +866,7 @@ function intertyper(lines, sidePass, baseLineNums) {
838
866
  item.variant = item.tokens[1].text;
839
867
  item.tokens.splice(1, 1);
840
868
  }
841
- if (item.tokens[1].text == 'exact') item.tokens.splice(1, 1); // TODO: Implement trap values
869
+ while (item.tokens[1].text in LLVM.MATHOP_IGNORABLES) item.tokens.splice(1, 1);
842
870
  var segments = splitTokenList(item.tokens.slice(1));
843
871
  item.params = [];
844
872
  for (var i = 1; i <= 4; i++) {
@@ -1184,6 +1212,7 @@ function intertyper(lines, sidePass, baseLineNums) {
1184
1212
  finalResults.push(item);
1185
1213
  if (item.tokens) item.tokens = null; // We do not need tokens, past the intertyper. Clean them up as soon as possible here.
1186
1214
  });
1215
+ //B.stop('intertyper');
1187
1216
  return finalResults;
1188
1217
  }
1189
1218
 
@@ -20,6 +20,7 @@ var functionStubSigs = {};
20
20
 
21
21
  // JSifier
22
22
  function JSify(data, functionsOnly, givenFunctions) {
23
+ //B.start('jsifier');
23
24
  var mainPass = !functionsOnly;
24
25
 
25
26
  var itemsDict = { type: [], GlobalVariableStub: [], functionStub: [], function: [], GlobalVariable: [], GlobalVariablePostSet: [] };
@@ -27,7 +28,7 @@ function JSify(data, functionsOnly, givenFunctions) {
27
28
  if (mainPass) {
28
29
  var shellFile = SHELL_FILE ? SHELL_FILE : (BUILD_AS_SHARED_LIB || SIDE_MODULE ? 'shell_sharedlib.js' : 'shell.js');
29
30
 
30
- if (phase == 'pre') {
31
+ if (phase == 'pre' || phase == 'glue') {
31
32
  // We will start to print out the data, but must do so carefully - we are
32
33
  // dealing with potentially *huge* strings. Convenient replacements and
33
34
  // manipulations may create in-memory copies, and we may OOM.
@@ -67,9 +68,11 @@ function JSify(data, functionsOnly, givenFunctions) {
67
68
 
68
69
  // Add additional necessary items for the main pass. We can now do this since types are parsed (types can be used through
69
70
  // generateStructInfo in library.js)
71
+ //B.start('jsifier-libload');
70
72
  LibraryManager.load();
73
+ //B.stop('jsifier-libload');
71
74
 
72
- if (phase == 'pre') {
75
+ if (phase == 'pre' || phase == 'glue') {
73
76
  var libFuncsToInclude;
74
77
  if (INCLUDE_FULL_LIBRARY) {
75
78
  assert(!(BUILD_AS_SHARED_LIB || SIDE_MODULE), 'Cannot have both INCLUDE_FULL_LIBRARY and BUILD_AS_SHARED_LIB/SIDE_MODULE set.')
@@ -471,7 +474,7 @@ function JSify(data, functionsOnly, givenFunctions) {
471
474
  }
472
475
  }
473
476
  if (SIDE_MODULE) return ';'; // we import into the side module js library stuff from the outside parent
474
- if ((!ASM_JS || phase == 'pre') &&
477
+ if ((!ASM_JS || phase == 'pre' || phase == 'glue') &&
475
478
  (EXPORT_ALL || (ident in EXPORTED_FUNCTIONS))) {
476
479
  contentText += '\nModule["' + ident + '"] = ' + ident + ';';
477
480
  }
@@ -487,10 +490,19 @@ function JSify(data, functionsOnly, givenFunctions) {
487
490
  } else {
488
491
  // If this is not linkable, anything not in the library is definitely missing
489
492
  var cancel = false;
493
+ if (item.ident in DEAD_FUNCTIONS) {
494
+ if (LibraryManager.library[shortident + '__asm']) {
495
+ warn('cannot kill asm library function ' + item.ident);
496
+ } else {
497
+ LibraryManager.library[shortident] = new Function("Module['printErr']('dead function: " + shortident + "'); abort(-1);");
498
+ delete LibraryManager.library[shortident + '__inline'];
499
+ delete LibraryManager.library[shortident + '__deps'];
500
+ }
501
+ }
490
502
  if (!LINKABLE && !LibraryManager.library.hasOwnProperty(shortident) && !LibraryManager.library.hasOwnProperty(shortident + '__inline')) {
491
503
  if (ERROR_ON_UNDEFINED_SYMBOLS) error('unresolved symbol: ' + shortident);
492
- if (VERBOSE || WARN_ON_UNDEFINED_SYMBOLS) printErr('warning: unresolved symbol: ' + shortident);
493
- if (ASM_JS || item.ident in DEAD_FUNCTIONS) {
504
+ else if (VERBOSE || WARN_ON_UNDEFINED_SYMBOLS) warn('unresolved symbol: ' + shortident);
505
+ if (ASM_JS) {
494
506
  // emit a stub that will fail during runtime. this allows asm validation to succeed.
495
507
  LibraryManager.library[shortident] = new Function("Module['printErr']('missing function: " + shortident + "'); abort(-1);");
496
508
  } else {
@@ -504,6 +516,7 @@ function JSify(data, functionsOnly, givenFunctions) {
504
516
  // function splitter
505
517
  function functionSplitter(item) {
506
518
  item.lines.forEach(function(line) {
519
+ //B.start('jsifier-handle-' + line.intertype);
507
520
  Framework.currItem = line;
508
521
  line.funcData = item; // TODO: remove all these, access it globally
509
522
  switch (line.intertype) {
@@ -538,8 +551,11 @@ function JSify(data, functionsOnly, givenFunctions) {
538
551
  //if (ASM_JS) assert(line.JS.indexOf('var ') < 0, dump(line));
539
552
  if (line.assignTo) makeAssign(line);
540
553
  Framework.currItem = null;
554
+ //B.stop('jsifier-handle-' + line.intertype);
541
555
  });
556
+ //B.start('jsifier-frec');
542
557
  functionReconstructor(item);
558
+ //B.stop('jsifier-frec');
543
559
  }
544
560
 
545
561
  // function for filtering functions for label debugging
@@ -749,20 +765,14 @@ function JSify(data, functionsOnly, givenFunctions) {
749
765
  if (func.setjmpTable && !ASM_JS) {
750
766
  ret += ' } catch(e) { if (!e.longjmp || !(e.id in mySetjmpIds)) throw(e); setjmpTable[setjmpLabels[e.id]](e.value) }';
751
767
  }
752
- if (ASM_JS && func.returnType !== 'void') {
753
- // Add a return
754
- if (func.returnType in Runtime.FLOAT_TYPES) {
755
- ret += ' return +0;\n';
756
- } else {
757
- ret += ' return 0;\n';
758
- }
759
- }
768
+ if (ASM_JS && func.returnType !== 'void') ret += ' return ' + asmInitializer(func.returnType) + ';\n'; // Add a return
760
769
  } else {
761
770
  ret += (SHOW_LABELS ? indent + '/* ' + block.entries[0] + ' */' : '') + '\n' + getLabelLines(block.labels[0]);
762
771
  }
763
772
  ret += '\n';
764
773
  } else {
765
774
  // Reloop multiple blocks using the compiled relooper
775
+ //B.start('jsifier-reloop');
766
776
 
767
777
  //Relooper.setDebug(1);
768
778
  Relooper.init();
@@ -812,6 +822,7 @@ function JSify(data, functionsOnly, givenFunctions) {
812
822
  }
813
823
  ret += Relooper.render(blockMap[block.entries[0]]);
814
824
  Relooper.cleanup();
825
+ //B.stop('jsifier-reloop');
815
826
  }
816
827
  return ret;
817
828
  }
@@ -824,11 +835,7 @@ function JSify(data, functionsOnly, givenFunctions) {
824
835
  var lastReturn = func.JS.lastIndexOf('return ');
825
836
  if ((lastCurly < 0 && lastReturn < 0) || // no control flow, no return
826
837
  (lastCurly >= 0 && lastReturn < lastCurly)) { // control flow, no return past last join
827
- if (func.returnType in Runtime.FLOAT_TYPES) {
828
- func.JS += ' return +0;\n';
829
- } else {
830
- func.JS += ' return 0;\n';
831
- }
838
+ func.JS += ' return ' + asmInitializer(func.returnType) + ';\n';
832
839
  }
833
840
  }
834
841
  func.JS += '}\n';
@@ -939,11 +946,12 @@ function JSify(data, functionsOnly, givenFunctions) {
939
946
  }
940
947
  if (item.valueType[item.valueType.length-1] === '>') {
941
948
  // vector store TODO: move to makeSetValue?
942
- var base = getVectorBaseType(item.valueType);
943
- return '(' + makeSetValue(item.ident, 0, value + '.x', base, 0, 0, item.align) + ',' +
944
- makeSetValue(item.ident, 4, value + '.y', base, 0, 0, item.align) + ',' +
945
- makeSetValue(item.ident, 8, value + '.z', base, 0, 0, item.align) + ',' +
946
- makeSetValue(item.ident, 12, value + '.w', base, 0, 0, item.align) + ')';
949
+ var native = getVectorNativeType(item.valueType);
950
+ var base = getSIMDName(native);
951
+ return '(' + makeSetValue(item.ident, 0, value + '.x', native, 0, 0, item.align) + ',' +
952
+ makeSetValue(item.ident, 4, value + '.y', native, 0, 0, item.align) + ',' +
953
+ makeSetValue(item.ident, 8, value + '.z', native, 0, 0, item.align) + ',' +
954
+ makeSetValue(item.ident, 12, value + '.w', native, 0, 0, item.align) + ');';
947
955
  }
948
956
  switch (impl) {
949
957
  case VAR_NATIVIZED:
@@ -1314,11 +1322,12 @@ function JSify(data, functionsOnly, givenFunctions) {
1314
1322
  var value = finalizeLLVMParameter(item.pointer);
1315
1323
  if (item.valueType[item.valueType.length-1] === '>') {
1316
1324
  // vector load
1317
- var base = getVectorBaseType(item.valueType);
1318
- return base + '32x4(' + makeGetValue(value, 0, base, 0, item.unsigned, 0, item.align) + ',' +
1319
- makeGetValue(value, 4, base, 0, item.unsigned, 0, item.align) + ',' +
1320
- makeGetValue(value, 8, base, 0, item.unsigned, 0, item.align) + ',' +
1321
- makeGetValue(value, 12, base, 0, item.unsigned, 0, item.align) + ')';
1325
+ var native = getVectorNativeType(item.valueType);
1326
+ var base = getSIMDName(native);
1327
+ return base + '32x4(' + makeGetValue(value, 0, native, 0, item.unsigned, 0, item.align) + ',' +
1328
+ makeGetValue(value, 4, native, 0, item.unsigned, 0, item.align) + ',' +
1329
+ makeGetValue(value, 8, native, 0, item.unsigned, 0, item.align) + ',' +
1330
+ makeGetValue(value, 12, native, 0, item.unsigned, 0, item.align) + ');';
1322
1331
  }
1323
1332
  var impl = item.ident ? getVarImpl(item.funcData, item.ident) : VAR_EMULATED;
1324
1333
  switch (impl) {
@@ -1326,7 +1335,7 @@ function JSify(data, functionsOnly, givenFunctions) {
1326
1335
  if (isNumber(item.ident)) {
1327
1336
  // Direct read from a memory address; this may be an intentional segfault, if not, it is a bug in the source
1328
1337
  if (ASM_JS) {
1329
- return asmCoercion('abort(' + item.ident + ')', item.type);
1338
+ return asmFFICoercion('abort(' + item.ident + ')', item.type);
1330
1339
  } else {
1331
1340
  item.assignTo = null;
1332
1341
  return 'throw "fault on read from ' + item.ident + '";';
@@ -1364,8 +1373,9 @@ function JSify(data, functionsOnly, givenFunctions) {
1364
1373
  function insertelementHandler(item) {
1365
1374
  var base = getVectorBaseType(item.type);
1366
1375
  var ident = ensureVector(item.ident, base);
1376
+ var laneOp = ((base == 'float') ? 'SIMD.float32x4.with' : 'SIMD.int32x4.with');
1367
1377
  //return ident + '.with' + SIMDLane[finalizeLLVMParameter(item.index)] + '(' + finalizeLLVMParameter(item.value) + ')';
1368
- return 'SIMD.with' + SIMDLane[finalizeLLVMParameter(item.index)] + '(' + ident + ',' + finalizeLLVMParameter(item.value) + ')';
1378
+ return laneOp + SIMDLane[finalizeLLVMParameter(item.index)] + '(' + ident + ',' + finalizeLLVMParameter(item.value) + ')';
1369
1379
  }
1370
1380
  function extractelementHandler(item) {
1371
1381
  var base = getVectorBaseType(item.type);
@@ -1480,7 +1490,7 @@ function JSify(data, functionsOnly, givenFunctions) {
1480
1490
  }
1481
1491
 
1482
1492
  params.forEach(function(param, i) {
1483
- var val = finalizeParam(param);
1493
+ var val = finalizeLLVMParameter(param);
1484
1494
  if (!hasVarArgs || useJSArgs || i < normalArgs) {
1485
1495
  args.push(val);
1486
1496
  argsTypes.push(param.type);
@@ -1503,8 +1513,10 @@ function JSify(data, functionsOnly, givenFunctions) {
1503
1513
 
1504
1514
  args = args.map(function(arg, i) { return indexizeFunctions(arg, argsTypes[i]) });
1505
1515
  if (ASM_JS) {
1506
- if (shortident in Functions.libraryFunctions || simpleIdent in Functions.libraryFunctions || byPointerForced || invoke || extCall || funcData.setjmpTable) {
1507
- args = args.map(function(arg, i) { return asmCoercion(arg, argsTypes[i]) });
1516
+ var ffiCall = (shortident in Functions.libraryFunctions || simpleIdent in Functions.libraryFunctions || byPointerForced || invoke || extCall || funcData.setjmpTable) &&
1517
+ !(simpleIdent in JS_MATH_BUILTINS);
1518
+ if (ffiCall) {
1519
+ args = args.map(function(arg, i) { return asmCoercion(arg, ensureValidFFIType(argsTypes[i])) });
1508
1520
  } else {
1509
1521
  args = args.map(function(arg, i) { return asmEnsureFloat(arg, argsTypes[i]) });
1510
1522
  }
@@ -1581,7 +1593,7 @@ function JSify(data, functionsOnly, givenFunctions) {
1581
1593
  returnType = getReturnType(type);
1582
1594
  if (callIdent in Functions.implementedFunctions) {
1583
1595
  // LLVM sometimes bitcasts for no reason. We must call using the exact same type as the actual function is generated as
1584
- var trueType = Functions.getSignatureReturnType(Functions.implementedFunctions[callIdent]);
1596
+ var trueType = Functions.getSignatureType(Functions.implementedFunctions[callIdent][0]);
1585
1597
  if (trueType !== returnType && !isIdenticallyImplemented(trueType, returnType)) {
1586
1598
  if (VERBOSE) warnOnce('Fixing function call based on return type from signature, on ' + [callIdent, returnType, trueType]);
1587
1599
  returnType = trueType;
@@ -1592,6 +1604,15 @@ function JSify(data, functionsOnly, givenFunctions) {
1592
1604
  }
1593
1605
  }
1594
1606
 
1607
+ // we alias llvm memset and such to normal memset. The target has a return value, while the original
1608
+ // does not, so we need to fix that for the actual call target
1609
+ if (ASM_JS) {
1610
+ var sig = LibraryManager.library[simpleIdent + '__sig'];
1611
+ if (sig && sig[0] !== 'v') {
1612
+ returnType = Functions.getSignatureType(sig[0]);
1613
+ }
1614
+ }
1615
+
1595
1616
  if (byPointer) {
1596
1617
  var sig = Functions.getSignature(returnType, argsTypes, hasVarArgs);
1597
1618
  if (ASM_JS) {
@@ -1617,7 +1638,11 @@ function JSify(data, functionsOnly, givenFunctions) {
1617
1638
 
1618
1639
  var ret = callIdent + '(' + args.join(',') + ')';
1619
1640
  if (ASM_JS) { // TODO: do only when needed (library functions and Math.*?) XXX && simpleIdent in Functions.libraryFunctions) {
1620
- ret = asmCoercion(ret, returnType);
1641
+ if (ffiCall) {
1642
+ ret = asmFFICoercion(ret, returnType);
1643
+ } else {
1644
+ ret = asmCoercion(ret, returnType);
1645
+ }
1621
1646
  if (simpleIdent == 'abort' && funcData.returnType != 'void') {
1622
1647
  ret += '; return ' + asmCoercion('0', funcData.returnType); // special case: abort() can happen without return, breaking the return type of asm functions. ensure a return
1623
1648
  }
@@ -1689,7 +1714,7 @@ function JSify(data, functionsOnly, givenFunctions) {
1689
1714
  //
1690
1715
 
1691
1716
  if (!mainPass) {
1692
- if (phase == 'pre' && !Variables.generatedGlobalBase && !BUILD_AS_SHARED_LIB) {
1717
+ if ((phase == 'pre' || phase == 'glue') && !Variables.generatedGlobalBase && !BUILD_AS_SHARED_LIB) {
1693
1718
  Variables.generatedGlobalBase = true;
1694
1719
  // Globals are done, here is the rest of static memory
1695
1720
  assert((TARGET_LE32 && Runtime.GLOBAL_BASE == 8) || (TARGET_X86 && Runtime.GLOBAL_BASE == 4)); // this is assumed in e.g. relocations for linkable modules
@@ -1704,7 +1729,7 @@ function JSify(data, functionsOnly, givenFunctions) {
1704
1729
  var generated = itemsDict.function.concat(itemsDict.type).concat(itemsDict.GlobalVariableStub).concat(itemsDict.GlobalVariable);
1705
1730
  print(generated.map(function(item) { return item.JS; }).join('\n'));
1706
1731
 
1707
- if (phase == 'pre') {
1732
+ if (phase == 'pre' || phase == 'glue') {
1708
1733
  if (memoryInitialization.length > 0) {
1709
1734
  // apply postsets directly into the big memory initialization
1710
1735
  itemsDict.GlobalVariablePostSet = itemsDict.GlobalVariablePostSet.filter(function(item) {
@@ -1727,15 +1752,17 @@ function JSify(data, functionsOnly, givenFunctions) {
1727
1752
  });
1728
1753
  // write out the singleton big memory initialization value
1729
1754
  print('/* memory initializer */ ' + makePointer(memoryInitialization, null, 'ALLOC_NONE', 'i8', 'Runtime.GLOBAL_BASE' + (SIDE_MODULE ? '+H_BASE' : ''), true));
1730
- } else {
1755
+ } else if (phase !== 'glue') {
1731
1756
  print('/* no memory initializer */'); // test purposes
1732
1757
  }
1733
1758
 
1734
- // Define postsets. These will be run in ATINIT, right before global initializers (which might need the postsets). We cannot
1735
- // run them now because the memory initializer might not have been applied yet.
1736
- print('function runPostSets() {\n');
1737
- print(itemsDict.GlobalVariablePostSet.map(function(item) { return item.JS }).join('\n'));
1738
- print('}\n');
1759
+ if (phase !== 'glue') {
1760
+ // Define postsets. These will be run in ATINIT, right before global initializers (which might need the postsets). We cannot
1761
+ // run them now because the memory initializer might not have been applied yet.
1762
+ print('function runPostSets() {\n');
1763
+ print(itemsDict.GlobalVariablePostSet.map(function(item) { return item.JS }).join('\n'));
1764
+ print('}\n');
1765
+ }
1739
1766
 
1740
1767
  if (USE_TYPED_ARRAYS == 2) {
1741
1768
  if (!BUILD_AS_SHARED_LIB && !SIDE_MODULE) {
@@ -1765,7 +1792,7 @@ function JSify(data, functionsOnly, givenFunctions) {
1765
1792
  }
1766
1793
 
1767
1794
  // Print out global variables and postsets TODO: batching
1768
- if (phase == 'pre') {
1795
+ if (phase == 'pre' || phase == 'glue') {
1769
1796
  var legalizedI64sDefault = legalizedI64s;
1770
1797
  legalizedI64s = false;
1771
1798
 
@@ -1832,10 +1859,10 @@ function JSify(data, functionsOnly, givenFunctions) {
1832
1859
  // first row are utilities called from generated code, second are needed from fastLong
1833
1860
  ['i64Add', 'i64Subtract', 'bitshift64Shl', 'bitshift64Lshr', 'bitshift64Ashr',
1834
1861
  'llvm_ctlz_i32', 'llvm_cttz_i32'].forEach(function(func) {
1835
- if (!Functions.libraryFunctions[func]) {
1862
+ if (!Functions.libraryFunctions[func] || (phase == 'glue' && func[0] === 'l' && !addedLibraryItems[func])) { // TODO: one-by-one in fastcomp glue mode
1836
1863
  print(processLibraryFunction(LibraryManager.library[func], func)); // must be first to be close to generated code
1837
1864
  Functions.implementedFunctions['_' + func] = LibraryManager.library[func + '__sig'];
1838
- Functions.libraryFunctions[func] = 1;
1865
+ Functions.libraryFunctions[func] = phase == 'glue' ? 2 : 1; // XXX
1839
1866
  // limited dependency handling
1840
1867
  var deps = LibraryManager.library[func + '__deps'];
1841
1868
  if (deps) {
@@ -1910,8 +1937,6 @@ function JSify(data, functionsOnly, givenFunctions) {
1910
1937
  }
1911
1938
 
1912
1939
  PassManager.serialize();
1913
-
1914
- return null;
1915
1940
  }
1916
1941
 
1917
1942
  // Data
@@ -1941,13 +1966,18 @@ function JSify(data, functionsOnly, givenFunctions) {
1941
1966
  }
1942
1967
  }
1943
1968
 
1969
+ //B.start('jsifier-handle-gv');
1944
1970
  sortGlobals(data.globalVariables).forEach(globalVariableHandler);
1971
+ //B.stop('jsifier-handle-gv');
1945
1972
  data.aliass.forEach(aliasHandler);
1946
1973
  data.functions.forEach(functionSplitter);
1947
1974
  }
1948
1975
 
1976
+ //B.start('jsifier-fc');
1949
1977
  finalCombiner();
1978
+ //B.stop('jsifier-fc');
1950
1979
 
1951
1980
  dprint('framework', 'Big picture: Finishing JSifier, main pass=' + mainPass);
1981
+ //B.stop('jsifier');
1952
1982
  }
1953
1983