sbpf_assembler.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. let imports = {};
  2. imports['__wbindgen_placeholder__'] = module.exports;
  3. function debugString(val) {
  4. // primitive types
  5. const type = typeof val;
  6. if (type == 'number' || type == 'boolean' || val == null) {
  7. return `${val}`;
  8. }
  9. if (type == 'string') {
  10. return `"${val}"`;
  11. }
  12. if (type == 'symbol') {
  13. const description = val.description;
  14. if (description == null) {
  15. return 'Symbol';
  16. } else {
  17. return `Symbol(${description})`;
  18. }
  19. }
  20. if (type == 'function') {
  21. const name = val.name;
  22. if (typeof name == 'string' && name.length > 0) {
  23. return `Function(${name})`;
  24. } else {
  25. return 'Function';
  26. }
  27. }
  28. // objects
  29. if (Array.isArray(val)) {
  30. const length = val.length;
  31. let debug = '[';
  32. if (length > 0) {
  33. debug += debugString(val[0]);
  34. }
  35. for(let i = 1; i < length; i++) {
  36. debug += ', ' + debugString(val[i]);
  37. }
  38. debug += ']';
  39. return debug;
  40. }
  41. // Test for built-in
  42. const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
  43. let className;
  44. if (builtInMatches && builtInMatches.length > 1) {
  45. className = builtInMatches[1];
  46. } else {
  47. // Failed to match the standard '[object ClassName]'
  48. return toString.call(val);
  49. }
  50. if (className == 'Object') {
  51. // we're a user defined class or Object
  52. // JSON.stringify avoids problems with cycles, and is generally much
  53. // easier than looping through ownProperties of `val`.
  54. try {
  55. return 'Object(' + JSON.stringify(val) + ')';
  56. } catch (_) {
  57. return 'Object';
  58. }
  59. }
  60. // errors
  61. if (val instanceof Error) {
  62. return `${val.name}: ${val.message}\n${val.stack}`;
  63. }
  64. // TODO we could test for more things here, like `Set`s and `Map`s.
  65. return className;
  66. }
  67. let WASM_VECTOR_LEN = 0;
  68. let cachedUint8ArrayMemory0 = null;
  69. function getUint8ArrayMemory0() {
  70. if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
  71. cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
  72. }
  73. return cachedUint8ArrayMemory0;
  74. }
  75. const cachedTextEncoder = new TextEncoder();
  76. if (!('encodeInto' in cachedTextEncoder)) {
  77. cachedTextEncoder.encodeInto = function (arg, view) {
  78. const buf = cachedTextEncoder.encode(arg);
  79. view.set(buf);
  80. return {
  81. read: arg.length,
  82. written: buf.length
  83. };
  84. }
  85. }
  86. function passStringToWasm0(arg, malloc, realloc) {
  87. if (realloc === undefined) {
  88. const buf = cachedTextEncoder.encode(arg);
  89. const ptr = malloc(buf.length, 1) >>> 0;
  90. getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
  91. WASM_VECTOR_LEN = buf.length;
  92. return ptr;
  93. }
  94. let len = arg.length;
  95. let ptr = malloc(len, 1) >>> 0;
  96. const mem = getUint8ArrayMemory0();
  97. let offset = 0;
  98. for (; offset < len; offset++) {
  99. const code = arg.charCodeAt(offset);
  100. if (code > 0x7F) break;
  101. mem[ptr + offset] = code;
  102. }
  103. if (offset !== len) {
  104. if (offset !== 0) {
  105. arg = arg.slice(offset);
  106. }
  107. ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
  108. const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
  109. const ret = cachedTextEncoder.encodeInto(arg, view);
  110. offset += ret.written;
  111. ptr = realloc(ptr, len, offset, 1) >>> 0;
  112. }
  113. WASM_VECTOR_LEN = offset;
  114. return ptr;
  115. }
  116. let cachedDataViewMemory0 = null;
  117. function getDataViewMemory0() {
  118. if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
  119. cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
  120. }
  121. return cachedDataViewMemory0;
  122. }
  123. let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
  124. cachedTextDecoder.decode();
  125. function decodeText(ptr, len) {
  126. return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
  127. }
  128. function getStringFromWasm0(ptr, len) {
  129. ptr = ptr >>> 0;
  130. return decodeText(ptr, len);
  131. }
  132. function takeFromExternrefTable0(idx) {
  133. const value = wasm.__wbindgen_export_2.get(idx);
  134. wasm.__externref_table_dealloc(idx);
  135. return value;
  136. }
  137. function getArrayU8FromWasm0(ptr, len) {
  138. ptr = ptr >>> 0;
  139. return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
  140. }
  141. /**
  142. * @param {string} source
  143. * @returns {Uint8Array}
  144. */
  145. exports.assemble = function(source) {
  146. const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
  147. const len0 = WASM_VECTOR_LEN;
  148. const ret = wasm.assemble(ptr0, len0);
  149. if (ret[3]) {
  150. throw takeFromExternrefTable0(ret[2]);
  151. }
  152. var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
  153. wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
  154. return v2;
  155. };
  156. exports.__wbg_new_19c25a3f2fa63a02 = function() {
  157. const ret = new Object();
  158. return ret;
  159. };
  160. exports.__wbg_new_1f3a344cf3123716 = function() {
  161. const ret = new Array();
  162. return ret;
  163. };
  164. exports.__wbg_set_3f1d0b984ed272ed = function(arg0, arg1, arg2) {
  165. arg0[arg1] = arg2;
  166. };
  167. exports.__wbg_set_90f6c0f7bd8c0415 = function(arg0, arg1, arg2) {
  168. arg0[arg1 >>> 0] = arg2;
  169. };
  170. exports.__wbg_wbindgendebugstring_99ef257a3ddda34d = function(arg0, arg1) {
  171. const ret = debugString(arg1);
  172. const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
  173. const len1 = WASM_VECTOR_LEN;
  174. getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
  175. getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
  176. };
  177. exports.__wbg_wbindgenthrow_451ec1a8469d7eb6 = function(arg0, arg1) {
  178. throw new Error(getStringFromWasm0(arg0, arg1));
  179. };
  180. exports.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
  181. // Cast intrinsic for `Ref(String) -> Externref`.
  182. const ret = getStringFromWasm0(arg0, arg1);
  183. return ret;
  184. };
  185. exports.__wbindgen_init_externref_table = function() {
  186. const table = wasm.__wbindgen_export_2;
  187. const offset = table.grow(4);
  188. table.set(0, undefined);
  189. table.set(offset + 0, undefined);
  190. table.set(offset + 1, null);
  191. table.set(offset + 2, true);
  192. table.set(offset + 3, false);
  193. ;
  194. };
  195. const wasmPath = `${__dirname}/sbpf_assembler_bg.wasm`;
  196. const wasmBytes = require('fs').readFileSync(wasmPath);
  197. const wasmModule = new WebAssembly.Module(wasmBytes);
  198. const wasm = exports.__wasm = new WebAssembly.Instance(wasmModule, imports).exports;
  199. wasm.__wbindgen_start();