relink.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. function foo(stdlib, imports, heap)
  6. {
  7. "use asm";
  8. var fr = stdlib.Math.fround;
  9. var a = 3;
  10. var impa = +imports.c;
  11. var I32 =stdlib.Int32Array;
  12. var HEAP32 = new stdlib.Int32Array(heap);
  13. const b = 3.5;
  14. var inf = stdlib.Infinity;
  15. var I8=stdlib.Int8Array;
  16. var len = stdlib.byteLength;
  17. var ln2 = stdlib.Math.LN2;
  18. var i8= new I8(heap);
  19. var c = fr(4);
  20. var sn = stdlib.Math.sin;
  21. var impFunc = imports.bar;
  22. var impb = imports.d|0;
  23. var U8 =stdlib.Uint8Array;
  24. var HEAPU8 =new stdlib.Uint8Array(heap);
  25. function ch(b2)
  26. {
  27. if(len(b2) & 0xffffff || len(b2) <= 0xffffff || len(b2) > 0x80000000)
  28. return false;
  29. HEAP32=new I32(b2);
  30. i8=new I8(b2);
  31. HEAPU8=new U8(b2);
  32. heap=b2;
  33. return true
  34. }
  35. function f(param)
  36. {
  37. param = param|0;
  38. var e = 0.;
  39. a = (a+param)|0;
  40. a = (impb+a)|0;
  41. impa = +(impa+b);
  42. c = fr(c+c);
  43. impFunc(+c);
  44. e = +sn(+impa);
  45. a = (a + (HEAPU8[a|0]|0))|0;
  46. return +e;
  47. }
  48. function g(b)
  49. {
  50. b = b|0;
  51. impa = +table1[b&3](b);
  52. i8[a|0] = impb|0;
  53. impa = +(impa + ln2);
  54. return +impa;
  55. }
  56. var table1 = [f, g, f, g];
  57. return {fExp:f, gExp:g, ch:ch};
  58. }
  59. this['byteLength'] = Function.prototype.call.bind(Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'byteLength').get);
  60. var buffer = new ArrayBuffer(1<<24);
  61. var module1 = foo(this, {bar: function f(c){print("import func, val " + c)}, c: 4.5, d: 12}, buffer);
  62. var module2 = foo(this, {bar: function f(c){print("import2 func, val " + c)}, c: 5.5, d: 13}, new ArrayBuffer(1<<25));
  63. print(Math.round(module1.gExp(2)));
  64. print(Math.round(module1.fExp(1)));
  65. function testFunc(m)
  66. {
  67. print("testFunc");
  68. print(Math.round(m.fExp(1)));
  69. print(Math.round(m.gExp(2)));
  70. print(m.ch(new ArrayBuffer(1<<25)));
  71. print(Math.round(m.gExp(2)));
  72. }
  73. testFunc(module1);
  74. var module3 = foo(this, {bar: function f(c){print("import3 func, val " + c)}, c: 6.5, d: 14}, new ArrayBuffer(1<<25));
  75. testFunc(module2);
  76. testFunc(module3);
  77. testFunc(module1);
  78. testFunc(module2);
  79. testFunc(module3);