source: imaps-frontend/node_modules/@webassemblyjs/helper-wasm-bytecode/lib/index.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 15.5 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6Object.defineProperty(exports, "getSectionForNode", {
7 enumerable: true,
8 get: function get() {
9 return _section.getSectionForNode;
10 }
11});
12exports["default"] = void 0;
13
14var _section = require("./section");
15
16var illegalop = "illegal";
17var magicModuleHeader = [0x00, 0x61, 0x73, 0x6d];
18var moduleVersion = [0x01, 0x00, 0x00, 0x00];
19
20function invertMap(obj) {
21 var keyModifierFn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (k) {
22 return k;
23 };
24 var result = {};
25 var keys = Object.keys(obj);
26
27 for (var i = 0, length = keys.length; i < length; i++) {
28 result[keyModifierFn(obj[keys[i]])] = keys[i];
29 }
30
31 return result;
32}
33
34function createSymbolObject(name
35/*: string */
36, object
37/*: string */
38)
39/*: Symbol*/
40{
41 var numberOfArgs
42 /*: number*/
43 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
44 return {
45 name: name,
46 object: object,
47 numberOfArgs: numberOfArgs
48 };
49}
50
51function createSymbol(name
52/*: string */
53)
54/*: Symbol*/
55{
56 var numberOfArgs
57 /*: number*/
58 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
59 return {
60 name: name,
61 numberOfArgs: numberOfArgs
62 };
63}
64
65var types = {
66 func: 0x60,
67 result: 0x40
68};
69var exportTypes = {
70 0x00: "Func",
71 0x01: "Table",
72 0x02: "Memory",
73 0x03: "Global"
74};
75var exportTypesByName = invertMap(exportTypes);
76var valtypes = {
77 // numtype
78 0x7f: "i32",
79 0x7e: "i64",
80 0x7d: "f32",
81 0x7c: "f64",
82 // vectype
83 0x7b: "v128",
84 // reftype
85 0x70: "anyfunc",
86 0x6f: "externref"
87};
88var valtypesByString = invertMap(valtypes);
89var tableTypes = {
90 0x70: "anyfunc",
91 0x6f: "externref"
92};
93var blockTypes = Object.assign({}, valtypes, {
94 // https://webassembly.github.io/spec/core/binary/types.html#binary-blocktype
95 0x40: null,
96 // https://webassembly.github.io/spec/core/binary/types.html#binary-valtype
97 0x7f: "i32",
98 0x7e: "i64",
99 0x7d: "f32",
100 0x7c: "f64"
101});
102var globalTypes = {
103 0x00: "const",
104 0x01: "var"
105};
106var globalTypesByString = invertMap(globalTypes);
107var importTypes = {
108 0x00: "func",
109 0x01: "table",
110 0x02: "memory",
111 0x03: "global"
112};
113var sections = {
114 custom: 0,
115 type: 1,
116 "import": 2,
117 func: 3,
118 table: 4,
119 memory: 5,
120 global: 6,
121 "export": 7,
122 start: 8,
123 element: 9,
124 code: 10,
125 data: 11
126};
127var symbolsByByte = {
128 0x00: createSymbol("unreachable"),
129 0x01: createSymbol("nop"),
130 0x02: createSymbol("block"),
131 0x03: createSymbol("loop"),
132 0x04: createSymbol("if"),
133 0x05: createSymbol("else"),
134 0x06: illegalop,
135 0x07: illegalop,
136 0x08: illegalop,
137 0x09: illegalop,
138 0x0a: illegalop,
139 0x0b: createSymbol("end"),
140 0x0c: createSymbol("br", 1),
141 0x0d: createSymbol("br_if", 1),
142 0x0e: createSymbol("br_table"),
143 0x0f: createSymbol("return"),
144 0x10: createSymbol("call", 1),
145 0x11: createSymbol("call_indirect", 2),
146 0x12: illegalop,
147 0x13: illegalop,
148 0x14: illegalop,
149 0x15: illegalop,
150 0x16: illegalop,
151 0x17: illegalop,
152 0x18: illegalop,
153 0x19: illegalop,
154 0x1a: createSymbol("drop"),
155 0x1b: createSymbol("select"),
156 0x1c: illegalop,
157 0x1d: illegalop,
158 0x1e: illegalop,
159 0x1f: illegalop,
160 0x20: createSymbol("get_local", 1),
161 0x21: createSymbol("set_local", 1),
162 0x22: createSymbol("tee_local", 1),
163 0x23: createSymbol("get_global", 1),
164 0x24: createSymbol("set_global", 1),
165 0x25: createSymbol("table.get", 1),
166 0x26: createSymbol("table.set", 1),
167 0x27: illegalop,
168 0x28: createSymbolObject("load", "u32", 1),
169 0x29: createSymbolObject("load", "u64", 1),
170 0x2a: createSymbolObject("load", "f32", 1),
171 0x2b: createSymbolObject("load", "f64", 1),
172 0x2c: createSymbolObject("load8_s", "u32", 1),
173 0x2d: createSymbolObject("load8_u", "u32", 1),
174 0x2e: createSymbolObject("load16_s", "u32", 1),
175 0x2f: createSymbolObject("load16_u", "u32", 1),
176 0x30: createSymbolObject("load8_s", "u64", 1),
177 0x31: createSymbolObject("load8_u", "u64", 1),
178 0x32: createSymbolObject("load16_s", "u64", 1),
179 0x33: createSymbolObject("load16_u", "u64", 1),
180 0x34: createSymbolObject("load32_s", "u64", 1),
181 0x35: createSymbolObject("load32_u", "u64", 1),
182 0x36: createSymbolObject("store", "u32", 1),
183 0x37: createSymbolObject("store", "u64", 1),
184 0x38: createSymbolObject("store", "f32", 1),
185 0x39: createSymbolObject("store", "f64", 1),
186 0x3a: createSymbolObject("store8", "u32", 1),
187 0x3b: createSymbolObject("store16", "u32", 1),
188 0x3c: createSymbolObject("store8", "u64", 1),
189 0x3d: createSymbolObject("store16", "u64", 1),
190 0x3e: createSymbolObject("store32", "u64", 1),
191 0x3f: createSymbolObject("current_memory"),
192 0x40: createSymbolObject("grow_memory"),
193 0x41: createSymbolObject("const", "i32", 1),
194 0x42: createSymbolObject("const", "i64", 1),
195 0x43: createSymbolObject("const", "f32", 1),
196 0x44: createSymbolObject("const", "f64", 1),
197 0x45: createSymbolObject("eqz", "i32"),
198 0x46: createSymbolObject("eq", "i32"),
199 0x47: createSymbolObject("ne", "i32"),
200 0x48: createSymbolObject("lt_s", "i32"),
201 0x49: createSymbolObject("lt_u", "i32"),
202 0x4a: createSymbolObject("gt_s", "i32"),
203 0x4b: createSymbolObject("gt_u", "i32"),
204 0x4c: createSymbolObject("le_s", "i32"),
205 0x4d: createSymbolObject("le_u", "i32"),
206 0x4e: createSymbolObject("ge_s", "i32"),
207 0x4f: createSymbolObject("ge_u", "i32"),
208 0x50: createSymbolObject("eqz", "i64"),
209 0x51: createSymbolObject("eq", "i64"),
210 0x52: createSymbolObject("ne", "i64"),
211 0x53: createSymbolObject("lt_s", "i64"),
212 0x54: createSymbolObject("lt_u", "i64"),
213 0x55: createSymbolObject("gt_s", "i64"),
214 0x56: createSymbolObject("gt_u", "i64"),
215 0x57: createSymbolObject("le_s", "i64"),
216 0x58: createSymbolObject("le_u", "i64"),
217 0x59: createSymbolObject("ge_s", "i64"),
218 0x5a: createSymbolObject("ge_u", "i64"),
219 0x5b: createSymbolObject("eq", "f32"),
220 0x5c: createSymbolObject("ne", "f32"),
221 0x5d: createSymbolObject("lt", "f32"),
222 0x5e: createSymbolObject("gt", "f32"),
223 0x5f: createSymbolObject("le", "f32"),
224 0x60: createSymbolObject("ge", "f32"),
225 0x61: createSymbolObject("eq", "f64"),
226 0x62: createSymbolObject("ne", "f64"),
227 0x63: createSymbolObject("lt", "f64"),
228 0x64: createSymbolObject("gt", "f64"),
229 0x65: createSymbolObject("le", "f64"),
230 0x66: createSymbolObject("ge", "f64"),
231 0x67: createSymbolObject("clz", "i32"),
232 0x68: createSymbolObject("ctz", "i32"),
233 0x69: createSymbolObject("popcnt", "i32"),
234 0x6a: createSymbolObject("add", "i32"),
235 0x6b: createSymbolObject("sub", "i32"),
236 0x6c: createSymbolObject("mul", "i32"),
237 0x6d: createSymbolObject("div_s", "i32"),
238 0x6e: createSymbolObject("div_u", "i32"),
239 0x6f: createSymbolObject("rem_s", "i32"),
240 0x70: createSymbolObject("rem_u", "i32"),
241 0x71: createSymbolObject("and", "i32"),
242 0x72: createSymbolObject("or", "i32"),
243 0x73: createSymbolObject("xor", "i32"),
244 0x74: createSymbolObject("shl", "i32"),
245 0x75: createSymbolObject("shr_s", "i32"),
246 0x76: createSymbolObject("shr_u", "i32"),
247 0x77: createSymbolObject("rotl", "i32"),
248 0x78: createSymbolObject("rotr", "i32"),
249 0x79: createSymbolObject("clz", "i64"),
250 0x7a: createSymbolObject("ctz", "i64"),
251 0x7b: createSymbolObject("popcnt", "i64"),
252 0x7c: createSymbolObject("add", "i64"),
253 0x7d: createSymbolObject("sub", "i64"),
254 0x7e: createSymbolObject("mul", "i64"),
255 0x7f: createSymbolObject("div_s", "i64"),
256 0x80: createSymbolObject("div_u", "i64"),
257 0x81: createSymbolObject("rem_s", "i64"),
258 0x82: createSymbolObject("rem_u", "i64"),
259 0x83: createSymbolObject("and", "i64"),
260 0x84: createSymbolObject("or", "i64"),
261 0x85: createSymbolObject("xor", "i64"),
262 0x86: createSymbolObject("shl", "i64"),
263 0x87: createSymbolObject("shr_s", "i64"),
264 0x88: createSymbolObject("shr_u", "i64"),
265 0x89: createSymbolObject("rotl", "i64"),
266 0x8a: createSymbolObject("rotr", "i64"),
267 0x8b: createSymbolObject("abs", "f32"),
268 0x8c: createSymbolObject("neg", "f32"),
269 0x8d: createSymbolObject("ceil", "f32"),
270 0x8e: createSymbolObject("floor", "f32"),
271 0x8f: createSymbolObject("trunc", "f32"),
272 0x90: createSymbolObject("nearest", "f32"),
273 0x91: createSymbolObject("sqrt", "f32"),
274 0x92: createSymbolObject("add", "f32"),
275 0x93: createSymbolObject("sub", "f32"),
276 0x94: createSymbolObject("mul", "f32"),
277 0x95: createSymbolObject("div", "f32"),
278 0x96: createSymbolObject("min", "f32"),
279 0x97: createSymbolObject("max", "f32"),
280 0x98: createSymbolObject("copysign", "f32"),
281 0x99: createSymbolObject("abs", "f64"),
282 0x9a: createSymbolObject("neg", "f64"),
283 0x9b: createSymbolObject("ceil", "f64"),
284 0x9c: createSymbolObject("floor", "f64"),
285 0x9d: createSymbolObject("trunc", "f64"),
286 0x9e: createSymbolObject("nearest", "f64"),
287 0x9f: createSymbolObject("sqrt", "f64"),
288 0xa0: createSymbolObject("add", "f64"),
289 0xa1: createSymbolObject("sub", "f64"),
290 0xa2: createSymbolObject("mul", "f64"),
291 0xa3: createSymbolObject("div", "f64"),
292 0xa4: createSymbolObject("min", "f64"),
293 0xa5: createSymbolObject("max", "f64"),
294 0xa6: createSymbolObject("copysign", "f64"),
295 0xa7: createSymbolObject("wrap/i64", "i32"),
296 0xa8: createSymbolObject("trunc_s/f32", "i32"),
297 0xa9: createSymbolObject("trunc_u/f32", "i32"),
298 0xaa: createSymbolObject("trunc_s/f64", "i32"),
299 0xab: createSymbolObject("trunc_u/f64", "i32"),
300 0xac: createSymbolObject("extend_s/i32", "i64"),
301 0xad: createSymbolObject("extend_u/i32", "i64"),
302 0xae: createSymbolObject("trunc_s/f32", "i64"),
303 0xaf: createSymbolObject("trunc_u/f32", "i64"),
304 0xb0: createSymbolObject("trunc_s/f64", "i64"),
305 0xb1: createSymbolObject("trunc_u/f64", "i64"),
306 0xb2: createSymbolObject("convert_s/i32", "f32"),
307 0xb3: createSymbolObject("convert_u/i32", "f32"),
308 0xb4: createSymbolObject("convert_s/i64", "f32"),
309 0xb5: createSymbolObject("convert_u/i64", "f32"),
310 0xb6: createSymbolObject("demote/f64", "f32"),
311 0xb7: createSymbolObject("convert_s/i32", "f64"),
312 0xb8: createSymbolObject("convert_u/i32", "f64"),
313 0xb9: createSymbolObject("convert_s/i64", "f64"),
314 0xba: createSymbolObject("convert_u/i64", "f64"),
315 0xbb: createSymbolObject("promote/f32", "f64"),
316 0xbc: createSymbolObject("reinterpret/f32", "i32"),
317 0xbd: createSymbolObject("reinterpret/f64", "i64"),
318 0xbe: createSymbolObject("reinterpret/i32", "f32"),
319 0xbf: createSymbolObject("reinterpret/i64", "f64"),
320 0xc0: createSymbolObject("extend8_s", "i32"),
321 0xc1: createSymbolObject("extend16_s", "i32"),
322 0xc2: createSymbolObject("extend8_s", "i64"),
323 0xc3: createSymbolObject("extend16_s", "i64"),
324 0xc4: createSymbolObject("extend32_s", "i64"),
325 0xd0: createSymbol("ref.null"),
326 0xd1: createSymbol("ref.is_null"),
327 0xd2: createSymbol("ref.func", 1),
328 0xfc0a: createSymbol("memory.copy"),
329 0xfc0b: createSymbol("memory.fill"),
330 // Table instructions
331 // https://webassembly.github.io/spec/core/binary/instructions.html#table-instructions
332 0xfc0c: createSymbol("table.init", 2),
333 0xfc0d: createSymbol("elem.drop", 1),
334 0xfc0e: createSymbol("table.copy", 2),
335 0xfc0f: createSymbol("table.grow", 1),
336 0xfc10: createSymbol("table.size", 1),
337 0xfc11: createSymbol("table.fill", 1),
338 // Atomic Memory Instructions
339 0xfe00: createSymbol("memory.atomic.notify", 1),
340 0xfe01: createSymbol("memory.atomic.wait32", 1),
341 0xfe02: createSymbol("memory.atomic.wait64", 1),
342 0xfe10: createSymbolObject("atomic.load", "i32", 1),
343 0xfe11: createSymbolObject("atomic.load", "i64", 1),
344 0xfe12: createSymbolObject("atomic.load8_u", "i32", 1),
345 0xfe13: createSymbolObject("atomic.load16_u", "i32", 1),
346 0xfe14: createSymbolObject("atomic.load8_u", "i64", 1),
347 0xfe15: createSymbolObject("atomic.load16_u", "i64", 1),
348 0xfe16: createSymbolObject("atomic.load32_u", "i64", 1),
349 0xfe17: createSymbolObject("atomic.store", "i32", 1),
350 0xfe18: createSymbolObject("atomic.store", "i64", 1),
351 0xfe19: createSymbolObject("atomic.store8_u", "i32", 1),
352 0xfe1a: createSymbolObject("atomic.store16_u", "i32", 1),
353 0xfe1b: createSymbolObject("atomic.store8_u", "i64", 1),
354 0xfe1c: createSymbolObject("atomic.store16_u", "i64", 1),
355 0xfe1d: createSymbolObject("atomic.store32_u", "i64", 1),
356 0xfe1e: createSymbolObject("atomic.rmw.add", "i32", 1),
357 0xfe1f: createSymbolObject("atomic.rmw.add", "i64", 1),
358 0xfe20: createSymbolObject("atomic.rmw8_u.add_u", "i32", 1),
359 0xfe21: createSymbolObject("atomic.rmw16_u.add_u", "i32", 1),
360 0xfe22: createSymbolObject("atomic.rmw8_u.add_u", "i64", 1),
361 0xfe23: createSymbolObject("atomic.rmw16_u.add_u", "i64", 1),
362 0xfe24: createSymbolObject("atomic.rmw32_u.add_u", "i64", 1),
363 0xfe25: createSymbolObject("atomic.rmw.sub", "i32", 1),
364 0xfe26: createSymbolObject("atomic.rmw.sub", "i64", 1),
365 0xfe27: createSymbolObject("atomic.rmw8_u.sub_u", "i32", 1),
366 0xfe28: createSymbolObject("atomic.rmw16_u.sub_u", "i32", 1),
367 0xfe29: createSymbolObject("atomic.rmw8_u.sub_u", "i64", 1),
368 0xfe2a: createSymbolObject("atomic.rmw16_u.sub_u", "i64", 1),
369 0xfe2b: createSymbolObject("atomic.rmw32_u.sub_u", "i64", 1),
370 0xfe2c: createSymbolObject("atomic.rmw.and", "i32", 1),
371 0xfe2d: createSymbolObject("atomic.rmw.and", "i64", 1),
372 0xfe2e: createSymbolObject("atomic.rmw8_u.and_u", "i32", 1),
373 0xfe2f: createSymbolObject("atomic.rmw16_u.and_u", "i32", 1),
374 0xfe30: createSymbolObject("atomic.rmw8_u.and_u", "i64", 1),
375 0xfe31: createSymbolObject("atomic.rmw16_u.and_u", "i64", 1),
376 0xfe32: createSymbolObject("atomic.rmw32_u.and_u", "i64", 1),
377 0xfe33: createSymbolObject("atomic.rmw.or", "i32", 1),
378 0xfe34: createSymbolObject("atomic.rmw.or", "i64", 1),
379 0xfe35: createSymbolObject("atomic.rmw8_u.or_u", "i32", 1),
380 0xfe36: createSymbolObject("atomic.rmw16_u.or_u", "i32", 1),
381 0xfe37: createSymbolObject("atomic.rmw8_u.or_u", "i64", 1),
382 0xfe38: createSymbolObject("atomic.rmw16_u.or_u", "i64", 1),
383 0xfe39: createSymbolObject("atomic.rmw32_u.or_u", "i64", 1),
384 0xfe3a: createSymbolObject("atomic.rmw.xor", "i32", 1),
385 0xfe3b: createSymbolObject("atomic.rmw.xor", "i64", 1),
386 0xfe3c: createSymbolObject("atomic.rmw8_u.xor_u", "i32", 1),
387 0xfe3d: createSymbolObject("atomic.rmw16_u.xor_u", "i32", 1),
388 0xfe3e: createSymbolObject("atomic.rmw8_u.xor_u", "i64", 1),
389 0xfe3f: createSymbolObject("atomic.rmw16_u.xor_u", "i64", 1),
390 0xfe40: createSymbolObject("atomic.rmw32_u.xor_u", "i64", 1),
391 0xfe41: createSymbolObject("atomic.rmw.xchg", "i32", 1),
392 0xfe42: createSymbolObject("atomic.rmw.xchg", "i64", 1),
393 0xfe43: createSymbolObject("atomic.rmw8_u.xchg_u", "i32", 1),
394 0xfe44: createSymbolObject("atomic.rmw16_u.xchg_u", "i32", 1),
395 0xfe45: createSymbolObject("atomic.rmw8_u.xchg_u", "i64", 1),
396 0xfe46: createSymbolObject("atomic.rmw16_u.xchg_u", "i64", 1),
397 0xfe47: createSymbolObject("atomic.rmw32_u.xchg_u", "i64", 1),
398 0xfe48: createSymbolObject("atomic.rmw.cmpxchg", "i32", 1),
399 0xfe49: createSymbolObject("atomic.rmw.cmpxchg", "i64", 1),
400 0xfe4a: createSymbolObject("atomic.rmw8_u.cmpxchg_u", "i32", 1),
401 0xfe4b: createSymbolObject("atomic.rmw16_u.cmpxchg_u", "i32", 1),
402 0xfe4c: createSymbolObject("atomic.rmw8_u.cmpxchg_u", "i64", 1),
403 0xfe4d: createSymbolObject("atomic.rmw16_u.cmpxchg_u", "i64", 1),
404 0xfe4e: createSymbolObject("atomic.rmw32_u.cmpxchg_u", "i64", 1)
405};
406var symbolsByName = invertMap(symbolsByByte, function (obj) {
407 if (typeof obj.object === "string") {
408 return "".concat(obj.object, ".").concat(obj.name);
409 }
410
411 return obj.name;
412});
413var _default = {
414 symbolsByByte: symbolsByByte,
415 sections: sections,
416 magicModuleHeader: magicModuleHeader,
417 moduleVersion: moduleVersion,
418 types: types,
419 valtypes: valtypes,
420 exportTypes: exportTypes,
421 blockTypes: blockTypes,
422 tableTypes: tableTypes,
423 globalTypes: globalTypes,
424 importTypes: importTypes,
425 valtypesByString: valtypesByString,
426 globalTypesByString: globalTypesByString,
427 exportTypesByName: exportTypesByName,
428 symbolsByName: symbolsByName
429};
430exports["default"] = _default;
Note: See TracBrowser for help on using the repository browser.