@wasmgroundup/emit 0.2.10 → 0.2.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +23 -2
- package/dist/index.js +57 -5
- package/index.ts +94 -5
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -21,6 +21,8 @@ declare function exportsec(exports: BytecodeFragment): BytecodeFragment;
|
|
|
21
21
|
declare const funcidx: typeof u32;
|
|
22
22
|
declare const exportdesc: {
|
|
23
23
|
func(idx: number): BytecodeFragment;
|
|
24
|
+
table(idx: number): BytecodeFragment;
|
|
25
|
+
mem(idx: number): BytecodeFragment;
|
|
24
26
|
global(idx: number): BytecodeFragment;
|
|
25
27
|
};
|
|
26
28
|
declare function module(sections: any): BytecodeFragment;
|
|
@@ -95,11 +97,30 @@ declare function importsec(ims: BytecodeFragment): BytecodeFragment;
|
|
|
95
97
|
declare const importdesc: {
|
|
96
98
|
func(x: number): BytecodeFragment;
|
|
97
99
|
};
|
|
100
|
+
declare function mem(memtype: any): any;
|
|
101
|
+
declare function memsec(mems: BytecodeFragment[]): (number | BytecodeFragment)[];
|
|
102
|
+
declare const limits: {
|
|
103
|
+
min(n: number): (number | number[])[];
|
|
104
|
+
minmax(n: number, m: number): (number | number[])[];
|
|
105
|
+
};
|
|
98
106
|
declare const mut: {
|
|
99
107
|
const: number;
|
|
100
108
|
var: number;
|
|
101
109
|
};
|
|
102
110
|
declare function globaltype(t: any, m: any): any[];
|
|
103
111
|
declare function global(gt: any, e: any): any[];
|
|
104
|
-
declare function globalsec(globs:
|
|
105
|
-
|
|
112
|
+
declare function globalsec(globs: BytecodeFragment[]): (number | BytecodeFragment)[];
|
|
113
|
+
declare function tabletype(elemtype: number, limits: BytecodeFragment): (number | BytecodeFragment)[];
|
|
114
|
+
declare function table(tabletype: BytecodeFragment): BytecodeFragment;
|
|
115
|
+
declare function tablesec(tables: BytecodeFragment[]): (number | BytecodeFragment)[];
|
|
116
|
+
declare const elemtype: {
|
|
117
|
+
funcref: number;
|
|
118
|
+
};
|
|
119
|
+
declare const tableidx: typeof u32;
|
|
120
|
+
declare const start: typeof u32;
|
|
121
|
+
declare function startsec(st: BytecodeFragment): (number | BytecodeFragment)[];
|
|
122
|
+
declare function data(x: BytecodeFragment, e: BytecodeFragment, bs: BytecodeFragment[]): BytecodeFragment[];
|
|
123
|
+
declare function datasec(segs: BytecodeFragment[]): (number | BytecodeFragment)[];
|
|
124
|
+
declare function elem(x: BytecodeFragment, e: BytecodeFragment, ys: BytecodeFragment[]): BytecodeFragment[];
|
|
125
|
+
declare function elemsec(segs: BytecodeFragment[]): (number | BytecodeFragment)[];
|
|
126
|
+
export { blocktype, BytecodeFragment, code, codesec, data, datasec, elem, elemsec, elemtype, export_, exportdesc, exportsec, f64, func, funcidx, funcsec, functype, global, globalsec, globaltype, i32, import_, importdesc, importsec, instr, limits, locals, mem, memsec, module, mut, name, section, start, startsec, table, tableidx, tablesec, tabletype, typeidx, typesec, u32, valtype, vec, };
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
const SECTION_ID_TYPE = 1;
|
|
2
2
|
const SECTION_ID_IMPORT = 2;
|
|
3
3
|
const SECTION_ID_FUNCTION = 3;
|
|
4
|
+
const SECTION_ID_TABLE = 4;
|
|
5
|
+
const SECTION_ID_MEMORY = 5;
|
|
4
6
|
const SECTION_ID_GLOBAL = 6;
|
|
5
7
|
const SECTION_ID_EXPORT = 7;
|
|
8
|
+
const SECTION_ID_START = 8;
|
|
9
|
+
const SECTION_ID_ELEMENT = 9;
|
|
6
10
|
const SECTION_ID_CODE = 10;
|
|
11
|
+
const SECTION_ID_DATA = 11;
|
|
7
12
|
const TYPE_FUNCTION = 0x60;
|
|
8
13
|
function stringToBytes(s) {
|
|
9
14
|
const bytes = new TextEncoder().encode(s);
|
|
@@ -78,6 +83,12 @@ const exportdesc = {
|
|
|
78
83
|
func(idx) {
|
|
79
84
|
return [0x00, funcidx(idx)];
|
|
80
85
|
},
|
|
86
|
+
table(idx) {
|
|
87
|
+
return [0x01, tableidx(idx)];
|
|
88
|
+
},
|
|
89
|
+
mem(idx) {
|
|
90
|
+
return [0x02, memidx(idx)];
|
|
91
|
+
},
|
|
81
92
|
global(idx) {
|
|
82
93
|
return [0x03, globalidx(idx)];
|
|
83
94
|
},
|
|
@@ -85,10 +96,6 @@ const exportdesc = {
|
|
|
85
96
|
function module(sections) {
|
|
86
97
|
return [magic(), version(), sections];
|
|
87
98
|
}
|
|
88
|
-
var numtype;
|
|
89
|
-
(function (numtype) {
|
|
90
|
-
numtype[numtype["i32"] = 127] = "i32";
|
|
91
|
-
})(numtype || (numtype = {}));
|
|
92
99
|
const instr = {
|
|
93
100
|
nop: 0x01,
|
|
94
101
|
block: 0x02,
|
|
@@ -210,6 +217,21 @@ const importdesc = {
|
|
|
210
217
|
return [0x00, typeidx(x)];
|
|
211
218
|
},
|
|
212
219
|
};
|
|
220
|
+
const memidx = u32;
|
|
221
|
+
function mem(memtype) {
|
|
222
|
+
return memtype;
|
|
223
|
+
}
|
|
224
|
+
function memsec(mems) {
|
|
225
|
+
return section(SECTION_ID_MEMORY, vec(mems));
|
|
226
|
+
}
|
|
227
|
+
const limits = {
|
|
228
|
+
min(n) {
|
|
229
|
+
return [0x00, u32(n)];
|
|
230
|
+
},
|
|
231
|
+
minmax(n, m) {
|
|
232
|
+
return [0x01, u32(n), u32(m)];
|
|
233
|
+
},
|
|
234
|
+
};
|
|
213
235
|
const globalidx = u32;
|
|
214
236
|
const mut = {
|
|
215
237
|
const: 0x00,
|
|
@@ -227,4 +249,34 @@ function global(gt, e) {
|
|
|
227
249
|
function globalsec(globs) {
|
|
228
250
|
return section(SECTION_ID_GLOBAL, vec(globs));
|
|
229
251
|
}
|
|
230
|
-
|
|
252
|
+
function tabletype(elemtype, limits) {
|
|
253
|
+
return [elemtype, limits];
|
|
254
|
+
}
|
|
255
|
+
function table(tabletype) {
|
|
256
|
+
return tabletype;
|
|
257
|
+
}
|
|
258
|
+
function tablesec(tables) {
|
|
259
|
+
return section(SECTION_ID_TABLE, vec(tables));
|
|
260
|
+
}
|
|
261
|
+
const elemtype = { funcref: 0x70 };
|
|
262
|
+
const tableidx = u32;
|
|
263
|
+
const start = funcidx;
|
|
264
|
+
// st:start
|
|
265
|
+
function startsec(st) {
|
|
266
|
+
return section(SECTION_ID_START, st);
|
|
267
|
+
}
|
|
268
|
+
// x:memidx e:expr b∗:vec(byte)
|
|
269
|
+
function data(x, e, bs) {
|
|
270
|
+
return [x, e, vec(bs)];
|
|
271
|
+
}
|
|
272
|
+
function datasec(segs) {
|
|
273
|
+
return section(SECTION_ID_DATA, vec(segs));
|
|
274
|
+
}
|
|
275
|
+
// x:tableidx e:expr y∗:vec(funcidx)
|
|
276
|
+
function elem(x, e, ys) {
|
|
277
|
+
return [x, e, vec(ys)];
|
|
278
|
+
}
|
|
279
|
+
function elemsec(segs) {
|
|
280
|
+
return section(SECTION_ID_ELEMENT, vec(segs));
|
|
281
|
+
}
|
|
282
|
+
export { blocktype, code, codesec, data, datasec, elem, elemsec, elemtype, export_, exportdesc, exportsec, f64, func, funcidx, funcsec, functype, global, globalsec, globaltype, i32, import_, importdesc, importsec, instr, limits, locals, mem, memsec, module, mut, name, section, start, startsec, table, tableidx, tablesec, tabletype, typeidx, typesec, u32, valtype, vec, };
|
package/index.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
const SECTION_ID_TYPE = 1;
|
|
2
2
|
const SECTION_ID_IMPORT = 2;
|
|
3
3
|
const SECTION_ID_FUNCTION = 3;
|
|
4
|
+
const SECTION_ID_TABLE = 4;
|
|
5
|
+
const SECTION_ID_MEMORY = 5;
|
|
4
6
|
const SECTION_ID_GLOBAL = 6;
|
|
5
7
|
const SECTION_ID_EXPORT = 7;
|
|
8
|
+
const SECTION_ID_START = 8;
|
|
9
|
+
const SECTION_ID_ELEMENT = 9;
|
|
6
10
|
const SECTION_ID_CODE = 10;
|
|
11
|
+
const SECTION_ID_DATA = 11;
|
|
7
12
|
|
|
8
13
|
const TYPE_FUNCTION = 0x60;
|
|
9
14
|
|
|
@@ -106,6 +111,12 @@ const exportdesc = {
|
|
|
106
111
|
func(idx: number): BytecodeFragment {
|
|
107
112
|
return [0x00, funcidx(idx)];
|
|
108
113
|
},
|
|
114
|
+
table(idx: number): BytecodeFragment {
|
|
115
|
+
return [0x01, tableidx(idx)];
|
|
116
|
+
},
|
|
117
|
+
mem(idx: number): BytecodeFragment {
|
|
118
|
+
return [0x02, memidx(idx)];
|
|
119
|
+
},
|
|
109
120
|
global(idx: number): BytecodeFragment {
|
|
110
121
|
return [0x03, globalidx(idx)];
|
|
111
122
|
},
|
|
@@ -115,10 +126,6 @@ function module(sections): BytecodeFragment {
|
|
|
115
126
|
return [magic(), version(), sections];
|
|
116
127
|
}
|
|
117
128
|
|
|
118
|
-
enum numtype {
|
|
119
|
-
i32 = 0x7f,
|
|
120
|
-
}
|
|
121
|
-
|
|
122
129
|
const instr = {
|
|
123
130
|
nop: 0x01,
|
|
124
131
|
block: 0x02,
|
|
@@ -258,6 +265,25 @@ const importdesc = {
|
|
|
258
265
|
},
|
|
259
266
|
};
|
|
260
267
|
|
|
268
|
+
const memidx = u32;
|
|
269
|
+
|
|
270
|
+
function mem(memtype) {
|
|
271
|
+
return memtype;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function memsec(mems: BytecodeFragment[]) {
|
|
275
|
+
return section(SECTION_ID_MEMORY, vec(mems));
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
const limits = {
|
|
279
|
+
min(n: number) {
|
|
280
|
+
return [0x00, u32(n)];
|
|
281
|
+
},
|
|
282
|
+
minmax(n: number, m: number) {
|
|
283
|
+
return [0x01, u32(n), u32(m)];
|
|
284
|
+
},
|
|
285
|
+
};
|
|
286
|
+
|
|
261
287
|
const globalidx = u32;
|
|
262
288
|
|
|
263
289
|
const mut = {
|
|
@@ -276,15 +302,69 @@ function global(gt, e) {
|
|
|
276
302
|
}
|
|
277
303
|
|
|
278
304
|
// glob*:vec(global)
|
|
279
|
-
function globalsec(globs) {
|
|
305
|
+
function globalsec(globs: BytecodeFragment[]) {
|
|
280
306
|
return section(SECTION_ID_GLOBAL, vec(globs));
|
|
281
307
|
}
|
|
282
308
|
|
|
309
|
+
function tabletype(elemtype: number, limits: BytecodeFragment) {
|
|
310
|
+
return [elemtype, limits];
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function table(tabletype: BytecodeFragment) {
|
|
314
|
+
return tabletype;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function tablesec(tables: BytecodeFragment[]) {
|
|
318
|
+
return section(SECTION_ID_TABLE, vec(tables));
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const elemtype = { funcref: 0x70 };
|
|
322
|
+
|
|
323
|
+
const tableidx = u32;
|
|
324
|
+
|
|
325
|
+
const start = funcidx;
|
|
326
|
+
|
|
327
|
+
// st:start
|
|
328
|
+
function startsec(st: BytecodeFragment) {
|
|
329
|
+
return section(SECTION_ID_START, st);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// x:memidx e:expr b∗:vec(byte)
|
|
333
|
+
function data(
|
|
334
|
+
x: BytecodeFragment,
|
|
335
|
+
e: BytecodeFragment,
|
|
336
|
+
bs: BytecodeFragment[],
|
|
337
|
+
) {
|
|
338
|
+
return [x, e, vec(bs)];
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function datasec(segs: BytecodeFragment[]) {
|
|
342
|
+
return section(SECTION_ID_DATA, vec(segs));
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// x:tableidx e:expr y∗:vec(funcidx)
|
|
346
|
+
function elem(
|
|
347
|
+
x: BytecodeFragment,
|
|
348
|
+
e: BytecodeFragment,
|
|
349
|
+
ys: BytecodeFragment[],
|
|
350
|
+
) {
|
|
351
|
+
return [x, e, vec(ys)];
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
function elemsec(segs: BytecodeFragment[]) {
|
|
355
|
+
return section(SECTION_ID_ELEMENT, vec(segs));
|
|
356
|
+
}
|
|
357
|
+
|
|
283
358
|
export {
|
|
284
359
|
blocktype,
|
|
285
360
|
BytecodeFragment,
|
|
286
361
|
code,
|
|
287
362
|
codesec,
|
|
363
|
+
data,
|
|
364
|
+
datasec,
|
|
365
|
+
elem,
|
|
366
|
+
elemsec,
|
|
367
|
+
elemtype,
|
|
288
368
|
export_,
|
|
289
369
|
exportdesc,
|
|
290
370
|
exportsec,
|
|
@@ -301,11 +381,20 @@ export {
|
|
|
301
381
|
importdesc,
|
|
302
382
|
importsec,
|
|
303
383
|
instr,
|
|
384
|
+
limits,
|
|
304
385
|
locals,
|
|
386
|
+
mem,
|
|
387
|
+
memsec,
|
|
305
388
|
module,
|
|
306
389
|
mut,
|
|
307
390
|
name,
|
|
308
391
|
section,
|
|
392
|
+
start,
|
|
393
|
+
startsec,
|
|
394
|
+
table,
|
|
395
|
+
tableidx,
|
|
396
|
+
tablesec,
|
|
397
|
+
tabletype,
|
|
309
398
|
typeidx,
|
|
310
399
|
typesec,
|
|
311
400
|
u32,
|