@wasmgroundup/emit 0.2.18 → 0.4.0
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/README.md +21 -0
- package/index.js +595 -0
- package/index.test.ts +12 -4
- package/package.json +3 -15
- package/dist/index.d.ts +0 -144
- package/dist/index.js +0 -312
- package/index.ts +0 -435
- package/tsconfig.json +0 -8
- package/wasmgroundup-emit-0.1.0.tgz +0 -0
package/dist/index.d.ts
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
type BytecodeFragment = (number | BytecodeFragment)[];
|
|
2
|
-
declare enum valtype {
|
|
3
|
-
i32 = 127,
|
|
4
|
-
i64 = 126,
|
|
5
|
-
f32 = 125,
|
|
6
|
-
f64 = 124
|
|
7
|
-
}
|
|
8
|
-
declare function blocktype(t?: valtype): number;
|
|
9
|
-
declare function vec<T extends BytecodeFragment>(elements: T): BytecodeFragment;
|
|
10
|
-
declare function section(id: number, contents: BytecodeFragment): (number | BytecodeFragment)[];
|
|
11
|
-
declare function functype(paramTypes: valtype[], resultTypes: valtype[]): BytecodeFragment;
|
|
12
|
-
declare function typesec(functypes: BytecodeFragment): BytecodeFragment;
|
|
13
|
-
declare const typeidx: typeof u32;
|
|
14
|
-
declare function funcsec(typeidxs: BytecodeFragment): BytecodeFragment;
|
|
15
|
-
declare function code(func: BytecodeFragment): BytecodeFragment;
|
|
16
|
-
declare function func(locals: BytecodeFragment, body: BytecodeFragment): BytecodeFragment;
|
|
17
|
-
declare function codesec(codes: BytecodeFragment): BytecodeFragment;
|
|
18
|
-
declare function name(s: string): BytecodeFragment;
|
|
19
|
-
declare function export_(nm: string, exportdesc: BytecodeFragment): BytecodeFragment;
|
|
20
|
-
declare function exportsec(exports: BytecodeFragment): BytecodeFragment;
|
|
21
|
-
declare const funcidx: typeof u32;
|
|
22
|
-
declare const exportdesc: {
|
|
23
|
-
func(idx: number): BytecodeFragment;
|
|
24
|
-
table(idx: number): BytecodeFragment;
|
|
25
|
-
mem(idx: number): BytecodeFragment;
|
|
26
|
-
global(idx: number): BytecodeFragment;
|
|
27
|
-
};
|
|
28
|
-
declare function module(sections: any): BytecodeFragment;
|
|
29
|
-
declare const instr: {
|
|
30
|
-
unreachable: number;
|
|
31
|
-
nop: number;
|
|
32
|
-
block: number;
|
|
33
|
-
loop: number;
|
|
34
|
-
if: number;
|
|
35
|
-
else: number;
|
|
36
|
-
end: number;
|
|
37
|
-
br: number;
|
|
38
|
-
br_if: number;
|
|
39
|
-
br_table: number;
|
|
40
|
-
return: number;
|
|
41
|
-
call: number;
|
|
42
|
-
call_indirect: number;
|
|
43
|
-
drop: number;
|
|
44
|
-
select: number;
|
|
45
|
-
local: {
|
|
46
|
-
get: number;
|
|
47
|
-
set: number;
|
|
48
|
-
tee: number;
|
|
49
|
-
};
|
|
50
|
-
global: {
|
|
51
|
-
get: number;
|
|
52
|
-
set: number;
|
|
53
|
-
tee: number;
|
|
54
|
-
};
|
|
55
|
-
memory: {
|
|
56
|
-
size: number;
|
|
57
|
-
grow: number;
|
|
58
|
-
};
|
|
59
|
-
i32: {
|
|
60
|
-
load: number;
|
|
61
|
-
const: number;
|
|
62
|
-
eqz: number;
|
|
63
|
-
eq: number;
|
|
64
|
-
ne: number;
|
|
65
|
-
lt_s: number;
|
|
66
|
-
lt_u: number;
|
|
67
|
-
gt_s: number;
|
|
68
|
-
gt_u: number;
|
|
69
|
-
le_s: number;
|
|
70
|
-
le_u: number;
|
|
71
|
-
ge_s: number;
|
|
72
|
-
ge_u: number;
|
|
73
|
-
add: number;
|
|
74
|
-
sub: number;
|
|
75
|
-
mul: number;
|
|
76
|
-
};
|
|
77
|
-
i64: {
|
|
78
|
-
store32: number;
|
|
79
|
-
const: number;
|
|
80
|
-
ne: number;
|
|
81
|
-
add: number;
|
|
82
|
-
sub: number;
|
|
83
|
-
mul: number;
|
|
84
|
-
};
|
|
85
|
-
f32: {
|
|
86
|
-
const: number;
|
|
87
|
-
ne: number;
|
|
88
|
-
add: number;
|
|
89
|
-
sub: number;
|
|
90
|
-
mul: number;
|
|
91
|
-
div: number;
|
|
92
|
-
};
|
|
93
|
-
f64: {
|
|
94
|
-
load: number;
|
|
95
|
-
store: number;
|
|
96
|
-
const: number;
|
|
97
|
-
ne: number;
|
|
98
|
-
add: number;
|
|
99
|
-
sub: number;
|
|
100
|
-
mul: number;
|
|
101
|
-
div: number;
|
|
102
|
-
reinterpret_i64: number;
|
|
103
|
-
};
|
|
104
|
-
};
|
|
105
|
-
declare function u32(v: number | bigint): number[];
|
|
106
|
-
declare function i32(v: number | bigint): number[];
|
|
107
|
-
declare function f64(v: number): number[];
|
|
108
|
-
declare function locals(n: number, type: valtype): BytecodeFragment;
|
|
109
|
-
declare function import_(mod: string, nm: string, d: BytecodeFragment): BytecodeFragment;
|
|
110
|
-
declare function importsec(ims: BytecodeFragment): BytecodeFragment;
|
|
111
|
-
declare const importdesc: {
|
|
112
|
-
func(x: BytecodeFragment): BytecodeFragment;
|
|
113
|
-
table(tt: BytecodeFragment): BytecodeFragment;
|
|
114
|
-
mem(mt: BytecodeFragment): BytecodeFragment;
|
|
115
|
-
global(gt: BytecodeFragment): BytecodeFragment;
|
|
116
|
-
};
|
|
117
|
-
declare function memsec(mems: BytecodeFragment[]): (number | BytecodeFragment)[];
|
|
118
|
-
declare function memtype(limits: BytecodeFragment): BytecodeFragment;
|
|
119
|
-
declare const limits: {
|
|
120
|
-
min(n: number): (number | number[])[];
|
|
121
|
-
minmax(n: number, m: number): (number | number[])[];
|
|
122
|
-
};
|
|
123
|
-
declare const mut: {
|
|
124
|
-
const: number;
|
|
125
|
-
var: number;
|
|
126
|
-
};
|
|
127
|
-
declare function globaltype(t: any, m: any): any[];
|
|
128
|
-
declare function global(gt: any, e: any): any[];
|
|
129
|
-
declare function globalsec(globs: BytecodeFragment[]): (number | BytecodeFragment)[];
|
|
130
|
-
declare function tabletype(elemtype: number, limits: BytecodeFragment): (number | BytecodeFragment)[];
|
|
131
|
-
declare function table(tabletype: BytecodeFragment): BytecodeFragment;
|
|
132
|
-
declare function tablesec(tables: BytecodeFragment[]): (number | BytecodeFragment)[];
|
|
133
|
-
declare const elemtype: {
|
|
134
|
-
funcref: number;
|
|
135
|
-
};
|
|
136
|
-
declare const tableidx: typeof u32;
|
|
137
|
-
declare const start: typeof u32;
|
|
138
|
-
declare function startsec(st: BytecodeFragment): (number | BytecodeFragment)[];
|
|
139
|
-
declare function data(x: BytecodeFragment, e: BytecodeFragment, bs: BytecodeFragment[]): BytecodeFragment[];
|
|
140
|
-
declare function datasec(segs: BytecodeFragment[]): (number | BytecodeFragment)[];
|
|
141
|
-
declare function elem(x: BytecodeFragment, e: BytecodeFragment, ys: BytecodeFragment[]): BytecodeFragment[];
|
|
142
|
-
declare function elemsec(segs: BytecodeFragment[]): (number | BytecodeFragment)[];
|
|
143
|
-
declare function memarg(align: number, offset: number): number[][];
|
|
144
|
-
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, memarg, memsec, memtype, module, mut, name, section, start, startsec, table, tableidx, tablesec, tabletype, typeidx, typesec, u32, valtype, vec, };
|
package/dist/index.js
DELETED
|
@@ -1,312 +0,0 @@
|
|
|
1
|
-
const SECTION_ID_TYPE = 1;
|
|
2
|
-
const SECTION_ID_IMPORT = 2;
|
|
3
|
-
const SECTION_ID_FUNCTION = 3;
|
|
4
|
-
const SECTION_ID_TABLE = 4;
|
|
5
|
-
const SECTION_ID_MEMORY = 5;
|
|
6
|
-
const SECTION_ID_GLOBAL = 6;
|
|
7
|
-
const SECTION_ID_EXPORT = 7;
|
|
8
|
-
const SECTION_ID_START = 8;
|
|
9
|
-
const SECTION_ID_ELEMENT = 9;
|
|
10
|
-
const SECTION_ID_CODE = 10;
|
|
11
|
-
const SECTION_ID_DATA = 11;
|
|
12
|
-
const TYPE_FUNCTION = 0x60;
|
|
13
|
-
function stringToBytes(s) {
|
|
14
|
-
const bytes = new TextEncoder().encode(s);
|
|
15
|
-
return Array.from(bytes);
|
|
16
|
-
}
|
|
17
|
-
function int32ToBytes(v) {
|
|
18
|
-
// prettier-ignore
|
|
19
|
-
return [
|
|
20
|
-
v & 0xff,
|
|
21
|
-
(v >> 8) & 0xff,
|
|
22
|
-
(v >> 16) & 0xff,
|
|
23
|
-
(v >> 24) & 0xff,
|
|
24
|
-
];
|
|
25
|
-
}
|
|
26
|
-
function magic() {
|
|
27
|
-
// [0x00, 0x61, 0x73, 0x6d]
|
|
28
|
-
return stringToBytes("\0asm");
|
|
29
|
-
}
|
|
30
|
-
function version() {
|
|
31
|
-
// [0x01, 0x00, 0x00, 0x00]
|
|
32
|
-
return int32ToBytes(1);
|
|
33
|
-
}
|
|
34
|
-
var valtype;
|
|
35
|
-
(function (valtype) {
|
|
36
|
-
valtype[valtype["i32"] = 127] = "i32";
|
|
37
|
-
valtype[valtype["i64"] = 126] = "i64";
|
|
38
|
-
valtype[valtype["f32"] = 125] = "f32";
|
|
39
|
-
valtype[valtype["f64"] = 124] = "f64";
|
|
40
|
-
})(valtype || (valtype = {}));
|
|
41
|
-
// t: valtype
|
|
42
|
-
function blocktype(t) {
|
|
43
|
-
return t ?? 0x40;
|
|
44
|
-
}
|
|
45
|
-
function vec(elements) {
|
|
46
|
-
return [u32(elements.length), ...elements];
|
|
47
|
-
}
|
|
48
|
-
function section(id, contents) {
|
|
49
|
-
const sizeInBytes = contents.flat(Infinity).length;
|
|
50
|
-
return [id, u32(sizeInBytes), contents];
|
|
51
|
-
}
|
|
52
|
-
function functype(paramTypes, resultTypes) {
|
|
53
|
-
return [TYPE_FUNCTION, vec(paramTypes), vec(resultTypes)];
|
|
54
|
-
}
|
|
55
|
-
function typesec(functypes) {
|
|
56
|
-
return section(SECTION_ID_TYPE, vec(functypes));
|
|
57
|
-
}
|
|
58
|
-
const typeidx = u32;
|
|
59
|
-
function funcsec(typeidxs) {
|
|
60
|
-
return section(SECTION_ID_FUNCTION, vec(typeidxs));
|
|
61
|
-
}
|
|
62
|
-
function code(func) {
|
|
63
|
-
const sizeInBytes = func.flat(Infinity).length;
|
|
64
|
-
return [u32(sizeInBytes), func];
|
|
65
|
-
}
|
|
66
|
-
function func(locals, body) {
|
|
67
|
-
return [vec(locals), body];
|
|
68
|
-
}
|
|
69
|
-
function codesec(codes) {
|
|
70
|
-
return section(SECTION_ID_CODE, vec(codes));
|
|
71
|
-
}
|
|
72
|
-
function name(s) {
|
|
73
|
-
return vec(stringToBytes(s));
|
|
74
|
-
}
|
|
75
|
-
function export_(nm, exportdesc) {
|
|
76
|
-
return [name(nm), exportdesc];
|
|
77
|
-
}
|
|
78
|
-
function exportsec(exports) {
|
|
79
|
-
return section(SECTION_ID_EXPORT, vec(exports));
|
|
80
|
-
}
|
|
81
|
-
const funcidx = u32;
|
|
82
|
-
const exportdesc = {
|
|
83
|
-
func(idx) {
|
|
84
|
-
return [0x00, funcidx(idx)];
|
|
85
|
-
},
|
|
86
|
-
table(idx) {
|
|
87
|
-
return [0x01, tableidx(idx)];
|
|
88
|
-
},
|
|
89
|
-
mem(idx) {
|
|
90
|
-
return [0x02, memidx(idx)];
|
|
91
|
-
},
|
|
92
|
-
global(idx) {
|
|
93
|
-
return [0x03, globalidx(idx)];
|
|
94
|
-
},
|
|
95
|
-
};
|
|
96
|
-
function module(sections) {
|
|
97
|
-
return [magic(), version(), sections];
|
|
98
|
-
}
|
|
99
|
-
const instr = {
|
|
100
|
-
unreachable: 0x00,
|
|
101
|
-
nop: 0x01,
|
|
102
|
-
block: 0x02,
|
|
103
|
-
loop: 0x03,
|
|
104
|
-
if: 0x04,
|
|
105
|
-
else: 0x05,
|
|
106
|
-
end: 0x0b,
|
|
107
|
-
br: 0x0c,
|
|
108
|
-
br_if: 0x0d,
|
|
109
|
-
br_table: 0x0e,
|
|
110
|
-
return: 0x0f,
|
|
111
|
-
call: 0x10,
|
|
112
|
-
call_indirect: 0x11,
|
|
113
|
-
drop: 0x1a,
|
|
114
|
-
select: 0x1b,
|
|
115
|
-
local: {
|
|
116
|
-
get: 0x20,
|
|
117
|
-
set: 0x21,
|
|
118
|
-
tee: 0x22,
|
|
119
|
-
},
|
|
120
|
-
global: {
|
|
121
|
-
get: 0x23,
|
|
122
|
-
set: 0x24,
|
|
123
|
-
tee: 0x25,
|
|
124
|
-
},
|
|
125
|
-
memory: {
|
|
126
|
-
size: 0x3f,
|
|
127
|
-
grow: 0x40,
|
|
128
|
-
},
|
|
129
|
-
i32: {
|
|
130
|
-
load: 0x28,
|
|
131
|
-
const: 0x41,
|
|
132
|
-
eqz: 0x45,
|
|
133
|
-
eq: 0x46,
|
|
134
|
-
ne: 0x47,
|
|
135
|
-
lt_s: 0x48,
|
|
136
|
-
lt_u: 0x49,
|
|
137
|
-
gt_s: 0x4a,
|
|
138
|
-
gt_u: 0x4b,
|
|
139
|
-
le_s: 0x4c,
|
|
140
|
-
le_u: 0x4d,
|
|
141
|
-
ge_s: 0x4e,
|
|
142
|
-
ge_u: 0x4f,
|
|
143
|
-
add: 0x6a,
|
|
144
|
-
sub: 0x6b,
|
|
145
|
-
mul: 0x6c,
|
|
146
|
-
},
|
|
147
|
-
i64: {
|
|
148
|
-
store32: 0x3e,
|
|
149
|
-
const: 0x42,
|
|
150
|
-
ne: 0x52,
|
|
151
|
-
add: 0x7c,
|
|
152
|
-
sub: 0x7d,
|
|
153
|
-
mul: 0x7e,
|
|
154
|
-
},
|
|
155
|
-
f32: {
|
|
156
|
-
const: 0x43,
|
|
157
|
-
ne: 0x5c,
|
|
158
|
-
add: 0x92,
|
|
159
|
-
sub: 0x93,
|
|
160
|
-
mul: 0x94,
|
|
161
|
-
div: 0x95,
|
|
162
|
-
},
|
|
163
|
-
f64: {
|
|
164
|
-
load: 0x2b,
|
|
165
|
-
store: 0x39,
|
|
166
|
-
const: 0x44,
|
|
167
|
-
ne: 0x62,
|
|
168
|
-
add: 0xa0,
|
|
169
|
-
sub: 0xa1,
|
|
170
|
-
mul: 0xa2,
|
|
171
|
-
div: 0xa3,
|
|
172
|
-
reinterpret_i64: 0xbf,
|
|
173
|
-
},
|
|
174
|
-
};
|
|
175
|
-
const SEVEN_BIT_MASK_BIG_INT = 127n;
|
|
176
|
-
const CONTINUATION_BIT = 0b10000000;
|
|
177
|
-
function u32(v) {
|
|
178
|
-
let val = BigInt(v);
|
|
179
|
-
let more = true;
|
|
180
|
-
const r = [];
|
|
181
|
-
while (more) {
|
|
182
|
-
const b = Number(val & SEVEN_BIT_MASK_BIG_INT);
|
|
183
|
-
val = val >> 7n;
|
|
184
|
-
more = val !== 0n;
|
|
185
|
-
if (more) {
|
|
186
|
-
r.push(b | CONTINUATION_BIT);
|
|
187
|
-
}
|
|
188
|
-
else {
|
|
189
|
-
r.push(b);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
return r;
|
|
193
|
-
}
|
|
194
|
-
function i32(v) {
|
|
195
|
-
let val = BigInt(v);
|
|
196
|
-
const r = [];
|
|
197
|
-
let more = true;
|
|
198
|
-
while (more) {
|
|
199
|
-
const b = Number(val & 127n);
|
|
200
|
-
const signBitSet = !!(b & 0x40);
|
|
201
|
-
val = val >> 7n;
|
|
202
|
-
if ((val === 0n && !signBitSet) || (val === -1n && signBitSet)) {
|
|
203
|
-
more = false;
|
|
204
|
-
r.push(b);
|
|
205
|
-
}
|
|
206
|
-
else {
|
|
207
|
-
r.push(b | CONTINUATION_BIT);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
return r;
|
|
211
|
-
}
|
|
212
|
-
function f64(v) {
|
|
213
|
-
var buf = new ArrayBuffer(8);
|
|
214
|
-
new Float64Array(buf)[0] = v;
|
|
215
|
-
return Array.from(new Uint8Array(buf));
|
|
216
|
-
}
|
|
217
|
-
function locals(n, type) {
|
|
218
|
-
return [u32(n), type];
|
|
219
|
-
}
|
|
220
|
-
// mod:name nm:name d:importdesc
|
|
221
|
-
function import_(mod, nm, d) {
|
|
222
|
-
return [name(mod), name(nm), d];
|
|
223
|
-
}
|
|
224
|
-
// im*:vec(import)
|
|
225
|
-
function importsec(ims) {
|
|
226
|
-
return section(SECTION_ID_IMPORT, vec(ims));
|
|
227
|
-
}
|
|
228
|
-
const importdesc = {
|
|
229
|
-
// x:typeidx
|
|
230
|
-
func(x) {
|
|
231
|
-
return [0x00, x];
|
|
232
|
-
},
|
|
233
|
-
// tt:tabletype
|
|
234
|
-
table(tt) {
|
|
235
|
-
return [0x01, tt];
|
|
236
|
-
},
|
|
237
|
-
// mt:memtype
|
|
238
|
-
mem(mt) {
|
|
239
|
-
return [0x02, mt];
|
|
240
|
-
},
|
|
241
|
-
// gt:globaltype
|
|
242
|
-
global(gt) {
|
|
243
|
-
return [0x03, gt];
|
|
244
|
-
},
|
|
245
|
-
};
|
|
246
|
-
const memidx = u32;
|
|
247
|
-
function memsec(mems) {
|
|
248
|
-
return section(SECTION_ID_MEMORY, vec(mems));
|
|
249
|
-
}
|
|
250
|
-
// lim:limits
|
|
251
|
-
function memtype(limits) {
|
|
252
|
-
return limits;
|
|
253
|
-
}
|
|
254
|
-
const limits = {
|
|
255
|
-
min(n) {
|
|
256
|
-
return [0x00, u32(n)];
|
|
257
|
-
},
|
|
258
|
-
minmax(n, m) {
|
|
259
|
-
return [0x01, u32(n), u32(m)];
|
|
260
|
-
},
|
|
261
|
-
};
|
|
262
|
-
const globalidx = u32;
|
|
263
|
-
const mut = {
|
|
264
|
-
const: 0x00,
|
|
265
|
-
var: 0x01,
|
|
266
|
-
};
|
|
267
|
-
// t:valtype m:mut
|
|
268
|
-
function globaltype(t, m) {
|
|
269
|
-
return [t, m];
|
|
270
|
-
}
|
|
271
|
-
// gt:globaltype e:expr
|
|
272
|
-
function global(gt, e) {
|
|
273
|
-
return [gt, e];
|
|
274
|
-
}
|
|
275
|
-
// glob*:vec(global)
|
|
276
|
-
function globalsec(globs) {
|
|
277
|
-
return section(SECTION_ID_GLOBAL, vec(globs));
|
|
278
|
-
}
|
|
279
|
-
function tabletype(elemtype, limits) {
|
|
280
|
-
return [elemtype, limits];
|
|
281
|
-
}
|
|
282
|
-
function table(tabletype) {
|
|
283
|
-
return tabletype;
|
|
284
|
-
}
|
|
285
|
-
function tablesec(tables) {
|
|
286
|
-
return section(SECTION_ID_TABLE, vec(tables));
|
|
287
|
-
}
|
|
288
|
-
const elemtype = { funcref: 0x70 };
|
|
289
|
-
const tableidx = u32;
|
|
290
|
-
const start = funcidx;
|
|
291
|
-
// st:start
|
|
292
|
-
function startsec(st) {
|
|
293
|
-
return section(SECTION_ID_START, st);
|
|
294
|
-
}
|
|
295
|
-
// x:memidx e:expr b∗:vec(byte)
|
|
296
|
-
function data(x, e, bs) {
|
|
297
|
-
return [x, e, vec(bs)];
|
|
298
|
-
}
|
|
299
|
-
function datasec(segs) {
|
|
300
|
-
return section(SECTION_ID_DATA, vec(segs));
|
|
301
|
-
}
|
|
302
|
-
// x:tableidx e:expr y∗:vec(funcidx)
|
|
303
|
-
function elem(x, e, ys) {
|
|
304
|
-
return [x, e, vec(ys)];
|
|
305
|
-
}
|
|
306
|
-
function elemsec(segs) {
|
|
307
|
-
return section(SECTION_ID_ELEMENT, vec(segs));
|
|
308
|
-
}
|
|
309
|
-
function memarg(align, offset) {
|
|
310
|
-
return [u32(align), u32(offset)];
|
|
311
|
-
}
|
|
312
|
-
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, memarg, memsec, memtype, module, mut, name, section, start, startsec, table, tableidx, tablesec, tabletype, typeidx, typesec, u32, valtype, vec, };
|