porffor 0.16.0-a7bc359af → 0.16.0-a8f23d010
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/compiler/allocators/chunk.js +0 -0
- package/compiler/allocators/solo.js +0 -0
- package/compiler/allocators/static.js +41 -0
- package/compiler/codegen.js +43 -156
- package/compiler/opt.js +3 -3
- package/compiler/prefs.js +1 -1
- package/package.json +1 -1
File without changes
|
File without changes
|
@@ -0,0 +1,41 @@
|
|
1
|
+
import { Valtype } from '../wasmSpec.js';
|
2
|
+
import { number } from './embedding.js';
|
3
|
+
import { log } from './log.js';
|
4
|
+
import Prefs from './prefs.js';
|
5
|
+
|
6
|
+
let pages = new Set();
|
7
|
+
export const setup = () => {
|
8
|
+
pages = new Set();
|
9
|
+
};
|
10
|
+
|
11
|
+
const getAllocType = itemType => {
|
12
|
+
switch (itemType) {
|
13
|
+
case 'i8': return 'bytestring';
|
14
|
+
case 'i16': return 'string';
|
15
|
+
|
16
|
+
default: return 'array';
|
17
|
+
}
|
18
|
+
};
|
19
|
+
|
20
|
+
export const alloc = ({ scope }, name, itemType) => {
|
21
|
+
const reason = Prefs.scopedPageNames ? `${getAllocType(itemType)}: ${scope.name}/${name}` : `${getAllocType(itemType)}: ${name}`;
|
22
|
+
|
23
|
+
if (pages.has(reason)) return number(pages.get(reason).ind, Valtype.i32);
|
24
|
+
|
25
|
+
if (reason.startsWith('array:')) pages.hasArray = true;
|
26
|
+
if (reason.startsWith('string:')) pages.hasString = true;
|
27
|
+
if (reason.startsWith('bytestring:')) pages.hasByteString = true;
|
28
|
+
if (reason.includes('string:')) pages.hasAnyString = true;
|
29
|
+
|
30
|
+
const ind = pages.size;
|
31
|
+
pages.set(reason, { ind, type });
|
32
|
+
|
33
|
+
scope.pages ??= new Map();
|
34
|
+
scope.pages.set(reason, { ind, type });
|
35
|
+
|
36
|
+
if (Prefs.allocLog) log('alloc', `allocated new page of memory (${ind}) | ${reason} (type: ${type})`);
|
37
|
+
|
38
|
+
return number(ind, Valtype.i32);
|
39
|
+
};
|
40
|
+
|
41
|
+
export const getStaticPages = () => pages;
|
package/compiler/codegen.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Blocktype, Opcodes, Valtype,
|
1
|
+
import { Blocktype, Opcodes, Valtype, ValtypeSize } from './wasmSpec.js';
|
2
2
|
import { ieee754_binary64, signedLEB128, unsignedLEB128, encodeVector } from './encoding.js';
|
3
3
|
import { operatorOpcode } from './expression.js';
|
4
4
|
import { BuiltinFuncs, BuiltinVars, importedFuncs, NULL, UNDEFINED } from './builtins.js';
|
@@ -181,12 +181,6 @@ const generate = (scope, decl, global = false, name = undefined, valueUnused = f
|
|
181
181
|
continue;
|
182
182
|
}
|
183
183
|
|
184
|
-
if (asm[0] === 'memory') {
|
185
|
-
allocPage(scope, 'asm instrinsic');
|
186
|
-
// todo: add to store/load offset insts
|
187
|
-
continue;
|
188
|
-
}
|
189
|
-
|
190
184
|
let inst = Opcodes[asm[0].replace('.', '_')];
|
191
185
|
if (inst == null) throw new Error(`inline asm: inst ${asm[0]} not found`);
|
192
186
|
|
@@ -433,57 +427,6 @@ const concatStrings = (scope, left, right, global, name, assign = false, bytestr
|
|
433
427
|
const rightLength = localTmp(scope, 'concat_right_length', Valtype.i32);
|
434
428
|
const leftLength = localTmp(scope, 'concat_left_length', Valtype.i32);
|
435
429
|
|
436
|
-
if (assign && Prefs.aotPointerOpt) {
|
437
|
-
const pointer = scope.arrays?.get(name ?? '$undeclared');
|
438
|
-
|
439
|
-
return [
|
440
|
-
// setup right
|
441
|
-
...right,
|
442
|
-
Opcodes.i32_to_u,
|
443
|
-
[ Opcodes.local_set, rightPointer ],
|
444
|
-
|
445
|
-
// calculate length
|
446
|
-
...number(0, Valtype.i32), // base 0 for store later
|
447
|
-
|
448
|
-
...number(pointer, Valtype.i32),
|
449
|
-
[ Opcodes.i32_load, 0, ...unsignedLEB128(0) ],
|
450
|
-
[ Opcodes.local_tee, leftLength ],
|
451
|
-
|
452
|
-
[ Opcodes.local_get, rightPointer ],
|
453
|
-
[ Opcodes.i32_load, 0, ...unsignedLEB128(0) ],
|
454
|
-
[ Opcodes.local_tee, rightLength ],
|
455
|
-
|
456
|
-
[ Opcodes.i32_add ],
|
457
|
-
|
458
|
-
// store length
|
459
|
-
[ Opcodes.i32_store, Math.log2(ValtypeSize.i32) - 1, ...unsignedLEB128(pointer) ],
|
460
|
-
|
461
|
-
// copy right
|
462
|
-
// dst = out pointer + length size + current length * sizeof valtype
|
463
|
-
...number(pointer + ValtypeSize.i32, Valtype.i32),
|
464
|
-
|
465
|
-
[ Opcodes.local_get, leftLength ],
|
466
|
-
...number(bytestrings ? ValtypeSize.i8 : ValtypeSize.i16, Valtype.i32),
|
467
|
-
[ Opcodes.i32_mul ],
|
468
|
-
[ Opcodes.i32_add ],
|
469
|
-
|
470
|
-
// src = right pointer + length size
|
471
|
-
[ Opcodes.local_get, rightPointer ],
|
472
|
-
...number(ValtypeSize.i32, Valtype.i32),
|
473
|
-
[ Opcodes.i32_add ],
|
474
|
-
|
475
|
-
// size = right length * sizeof valtype
|
476
|
-
[ Opcodes.local_get, rightLength ],
|
477
|
-
...number(bytestrings ? ValtypeSize.i8 : ValtypeSize.i16, Valtype.i32),
|
478
|
-
[ Opcodes.i32_mul ],
|
479
|
-
|
480
|
-
[ ...Opcodes.memory_copy, 0x00, 0x00 ],
|
481
|
-
|
482
|
-
// return new string (page)
|
483
|
-
...number(pointer)
|
484
|
-
];
|
485
|
-
}
|
486
|
-
|
487
430
|
const leftPointer = localTmp(scope, 'concat_left_pointer', Valtype.i32);
|
488
431
|
|
489
432
|
// alloc/assign array
|
@@ -2396,19 +2339,12 @@ const generateAssign = (scope, decl, _global, _name, valueUnused = false) => {
|
|
2396
2339
|
|
2397
2340
|
// hack: .length setter
|
2398
2341
|
if (decl.left.type === 'MemberExpression' && decl.left.property.name === 'length') {
|
2399
|
-
const name = decl.left.object.name;
|
2400
|
-
const pointer = scope.arrays?.get(name);
|
2401
|
-
|
2402
|
-
const aotPointer = Prefs.aotPointerOpt && pointer != null;
|
2403
|
-
|
2404
2342
|
const newValueTmp = localTmp(scope, '__length_setter_tmp');
|
2405
2343
|
const pointerTmp = op === '=' ? null : localTmp(scope, '__member_setter_ptr_tmp', Valtype.i32);
|
2406
2344
|
|
2407
2345
|
return [
|
2408
|
-
...(
|
2409
|
-
|
2410
|
-
Opcodes.i32_to_u
|
2411
|
-
]),
|
2346
|
+
...generate(scope, decl.left.object),
|
2347
|
+
Opcodes.i32_to_u,
|
2412
2348
|
...(!pointerTmp ? [] : [ [ Opcodes.local_tee, pointerTmp ] ]),
|
2413
2349
|
|
2414
2350
|
...(op === '=' ? generate(scope, decl.right) : performOp(scope, op, [
|
@@ -2419,7 +2355,7 @@ const generateAssign = (scope, decl, _global, _name, valueUnused = false) => {
|
|
2419
2355
|
[ Opcodes.local_tee, newValueTmp ],
|
2420
2356
|
|
2421
2357
|
Opcodes.i32_to_u,
|
2422
|
-
[ Opcodes.i32_store, Math.log2(ValtypeSize.i32) - 1,
|
2358
|
+
[ Opcodes.i32_store, Math.log2(ValtypeSize.i32) - 1, 0 ],
|
2423
2359
|
|
2424
2360
|
[ Opcodes.local_get, newValueTmp ]
|
2425
2361
|
];
|
@@ -2427,21 +2363,14 @@ const generateAssign = (scope, decl, _global, _name, valueUnused = false) => {
|
|
2427
2363
|
|
2428
2364
|
// arr[i]
|
2429
2365
|
if (decl.left.type === 'MemberExpression' && decl.left.computed) {
|
2430
|
-
const name = decl.left.object.name;
|
2431
|
-
const pointer = scope.arrays?.get(name);
|
2432
|
-
|
2433
|
-
const aotPointer = Prefs.aotPointerOpt && pointer != null;
|
2434
|
-
|
2435
2366
|
const newValueTmp = localTmp(scope, '__member_setter_val_tmp');
|
2436
2367
|
const pointerTmp = op === '=' ? -1 : localTmp(scope, '__member_setter_ptr_tmp', Valtype.i32);
|
2437
2368
|
|
2438
2369
|
return [
|
2439
2370
|
...typeSwitch(scope, getNodeType(scope, decl.left.object), {
|
2440
2371
|
[TYPES.array]: [
|
2441
|
-
...(
|
2442
|
-
|
2443
|
-
Opcodes.i32_to_u
|
2444
|
-
]),
|
2372
|
+
...generate(scope, decl.left.object),
|
2373
|
+
Opcodes.i32_to_u,
|
2445
2374
|
|
2446
2375
|
// get index as valtype
|
2447
2376
|
...generate(scope, decl.left.property),
|
@@ -2450,39 +2379,22 @@ const generateAssign = (scope, decl, _global, _name, valueUnused = false) => {
|
|
2450
2379
|
// turn into byte offset by * valtypeSize (4 for i32, 8 for i64/f64)
|
2451
2380
|
...number(ValtypeSize[valtype] + 1, Valtype.i32),
|
2452
2381
|
[ Opcodes.i32_mul ],
|
2453
|
-
|
2382
|
+
[ Opcodes.i32_add ],
|
2454
2383
|
...(op === '=' ? [] : [ [ Opcodes.local_tee, pointerTmp ] ]),
|
2455
2384
|
|
2456
2385
|
...(op === '=' ? generate(scope, decl.right) : performOp(scope, op, [
|
2457
2386
|
[ Opcodes.local_get, pointerTmp ],
|
2458
|
-
[ Opcodes.load, 0,
|
2387
|
+
[ Opcodes.load, 0, ValtypeSize.i32 ]
|
2459
2388
|
], generate(scope, decl.right), [
|
2460
2389
|
[ Opcodes.local_get, pointerTmp ],
|
2461
|
-
[ Opcodes.i32_load8_u, 0,
|
2390
|
+
[ Opcodes.i32_load8_u, 0, ValtypeSize.i32 + ValtypeSize[valtype] ]
|
2462
2391
|
], getNodeType(scope, decl.right), false, name, true)),
|
2463
2392
|
[ Opcodes.local_tee, newValueTmp ],
|
2464
2393
|
|
2465
|
-
[ Opcodes.store, 0,
|
2394
|
+
[ Opcodes.store, 0, ValtypeSize.i32 ]
|
2466
2395
|
],
|
2467
2396
|
|
2468
2397
|
default: internalThrow(scope, 'TypeError', `Cannot assign member with non-array`)
|
2469
|
-
|
2470
|
-
// [TYPES.string]: [
|
2471
|
-
// // turn into byte offset by * sizeof i16
|
2472
|
-
// ...number(ValtypeSize.i16, Valtype.i32),
|
2473
|
-
// [ Opcodes.i32_mul ],
|
2474
|
-
// ...(aotPointer ? [] : [ [ Opcodes.i32_add ] ]),
|
2475
|
-
// ...(op === '=' ? [] : [ [ Opcodes.local_tee, pointerTmp ] ]),
|
2476
|
-
|
2477
|
-
// ...(op === '=' ? generate(scope, decl.right) : performOp(scope, op, [
|
2478
|
-
// [ Opcodes.local_get, pointerTmp ],
|
2479
|
-
// [ Opcodes.load, Math.log2(ValtypeSize[valtype]) - 1, ...unsignedLEB128((aotPointer ? pointer : 0) + ValtypeSize.i32) ]
|
2480
|
-
// ], generate(scope, decl.right), number(TYPES.string, Valtype.i32), getNodeType(scope, decl.right))),
|
2481
|
-
// [ Opcodes.local_tee, newValueTmp ],
|
2482
|
-
|
2483
|
-
// Opcodes.i32_to_u,
|
2484
|
-
// [ StoreOps.i16, Math.log2(ValtypeSize.i16) - 1, ...unsignedLEB128((aotPointer ? pointer : 0) + ValtypeSize.i32) ]
|
2485
|
-
// ]
|
2486
2398
|
}, Blocktype.void),
|
2487
2399
|
|
2488
2400
|
[ Opcodes.local_get, newValueTmp ]
|
@@ -3204,16 +3116,6 @@ const allocPage = (scope, reason, type) => {
|
|
3204
3116
|
return ind;
|
3205
3117
|
};
|
3206
3118
|
|
3207
|
-
// todo: add scope.pages
|
3208
|
-
const freePage = reason => {
|
3209
|
-
const { ind } = pages.get(reason);
|
3210
|
-
pages.delete(reason);
|
3211
|
-
|
3212
|
-
if (Prefs.allocLog) log('alloc', `freed page of memory (${ind}) | ${reason}`);
|
3213
|
-
|
3214
|
-
return ind;
|
3215
|
-
};
|
3216
|
-
|
3217
3119
|
const itemTypeToValtype = {
|
3218
3120
|
i32: 'i32',
|
3219
3121
|
i64: 'i64',
|
@@ -3288,7 +3190,7 @@ const makeArray = (scope, decl, global = false, name = '$undeclared', initEmpty
|
|
3288
3190
|
const valtype = itemTypeToValtype[itemType];
|
3289
3191
|
const length = elements.length;
|
3290
3192
|
|
3291
|
-
if (
|
3193
|
+
if (Prefs.data && firstAssign && useRawElements) {
|
3292
3194
|
// if length is 0 memory/data will just be 0000... anyway
|
3293
3195
|
if (length !== 0) {
|
3294
3196
|
let bytes = compileBytes(length, 'i32');
|
@@ -3356,7 +3258,7 @@ const makeArray = (scope, decl, global = false, name = '$undeclared', initEmpty
|
|
3356
3258
|
return [ out, pointer ];
|
3357
3259
|
};
|
3358
3260
|
|
3359
|
-
const storeArray = (scope, array, index, element
|
3261
|
+
const storeArray = (scope, array, index, element) => {
|
3360
3262
|
if (!Array.isArray(element)) element = generate(scope, element);
|
3361
3263
|
if (typeof index === 'number') index = number(index);
|
3362
3264
|
|
@@ -3368,26 +3270,25 @@ const storeArray = (scope, array, index, element, aotPointer = null) => {
|
|
3368
3270
|
Opcodes.i32_to_u,
|
3369
3271
|
...number(ValtypeSize[valtype] + 1, Valtype.i32),
|
3370
3272
|
[ Opcodes.i32_mul ],
|
3371
|
-
|
3372
|
-
|
3373
|
-
|
3374
|
-
|
3375
|
-
]),
|
3273
|
+
|
3274
|
+
...array,
|
3275
|
+
Opcodes.i32_to_u,
|
3276
|
+
[ Opcodes.i32_add ],
|
3376
3277
|
[ Opcodes.local_set, offset ],
|
3377
3278
|
|
3378
3279
|
// store value
|
3379
3280
|
[ Opcodes.local_get, offset ],
|
3380
3281
|
...generate(scope, element),
|
3381
|
-
[ Opcodes.store, 0,
|
3282
|
+
[ Opcodes.store, 0, ValtypeSize.i32 ],
|
3382
3283
|
|
3383
3284
|
// store type
|
3384
3285
|
[ Opcodes.local_get, offset ],
|
3385
3286
|
...getNodeType(scope, element),
|
3386
|
-
[ Opcodes.i32_store8, 0,
|
3287
|
+
[ Opcodes.i32_store8, 0, ValtypeSize.i32 + ValtypeSize[valtype] ]
|
3387
3288
|
];
|
3388
3289
|
};
|
3389
3290
|
|
3390
|
-
const loadArray = (scope, array, index
|
3291
|
+
const loadArray = (scope, array, index) => {
|
3391
3292
|
if (typeof index === 'number') index = number(index);
|
3392
3293
|
|
3393
3294
|
const offset = localTmp(scope, '#loadArray_offset', Valtype.i32);
|
@@ -3398,20 +3299,19 @@ const loadArray = (scope, array, index, aotPointer = null) => {
|
|
3398
3299
|
Opcodes.i32_to_u,
|
3399
3300
|
...number(ValtypeSize[valtype] + 1, Valtype.i32),
|
3400
3301
|
[ Opcodes.i32_mul ],
|
3401
|
-
|
3402
|
-
|
3403
|
-
|
3404
|
-
|
3405
|
-
]),
|
3302
|
+
|
3303
|
+
...array,
|
3304
|
+
Opcodes.i32_to_u,
|
3305
|
+
[ Opcodes.i32_add ],
|
3406
3306
|
[ Opcodes.local_set, offset ],
|
3407
3307
|
|
3408
3308
|
// load value
|
3409
3309
|
[ Opcodes.local_get, offset ],
|
3410
|
-
[ Opcodes.load, 0,
|
3310
|
+
[ Opcodes.load, 0, ValtypeSize.i32 ],
|
3411
3311
|
|
3412
3312
|
// load type
|
3413
3313
|
[ Opcodes.local_get, offset ],
|
3414
|
-
[ Opcodes.i32_load8_u, 0,
|
3314
|
+
[ Opcodes.i32_load8_u, 0, ValtypeSize.i32 + ValtypeSize[valtype] ]
|
3415
3315
|
];
|
3416
3316
|
};
|
3417
3317
|
|
@@ -3462,9 +3362,6 @@ const withType = (scope, wasm, type) => [
|
|
3462
3362
|
|
3463
3363
|
const generateMember = (scope, decl, _global, _name) => {
|
3464
3364
|
const name = decl.object.name;
|
3465
|
-
const pointer = scope.arrays?.get(name);
|
3466
|
-
|
3467
|
-
const aotPointer = Prefs.aotPointerOpt && pointer;
|
3468
3365
|
|
3469
3366
|
// hack: .name
|
3470
3367
|
if (decl.property.name === 'name') {
|
@@ -3505,12 +3402,10 @@ const generateMember = (scope, decl, _global, _name) => {
|
|
3505
3402
|
if (Prefs.fastLength) {
|
3506
3403
|
// presume valid length object
|
3507
3404
|
return [
|
3508
|
-
...(
|
3509
|
-
|
3510
|
-
Opcodes.i32_to_u
|
3511
|
-
]),
|
3405
|
+
...generate(scope, decl.object),
|
3406
|
+
Opcodes.i32_to_u,
|
3512
3407
|
|
3513
|
-
[ Opcodes.i32_load, Math.log2(ValtypeSize.i32) - 1,
|
3408
|
+
[ Opcodes.i32_load, Math.log2(ValtypeSize.i32) - 1, 0 ],
|
3514
3409
|
Opcodes.i32_from_u
|
3515
3410
|
];
|
3516
3411
|
}
|
@@ -3519,12 +3414,10 @@ const generateMember = (scope, decl, _global, _name) => {
|
|
3519
3414
|
const known = knownType(scope, type);
|
3520
3415
|
if (known != null) {
|
3521
3416
|
if ([ TYPES.string, TYPES.bytestring, TYPES.array ].includes(known)) return [
|
3522
|
-
...(
|
3523
|
-
|
3524
|
-
Opcodes.i32_to_u
|
3525
|
-
]),
|
3417
|
+
...generate(scope, decl.object),
|
3418
|
+
Opcodes.i32_to_u,
|
3526
3419
|
|
3527
|
-
[ Opcodes.i32_load, Math.log2(ValtypeSize.i32) - 1,
|
3420
|
+
[ Opcodes.i32_load, Math.log2(ValtypeSize.i32) - 1, 0 ],
|
3528
3421
|
Opcodes.i32_from_u
|
3529
3422
|
];
|
3530
3423
|
|
@@ -3534,12 +3427,10 @@ const generateMember = (scope, decl, _global, _name) => {
|
|
3534
3427
|
return [
|
3535
3428
|
...typeIsOneOf(getNodeType(scope, decl.object), [ TYPES.string, TYPES.bytestring, TYPES.array ]),
|
3536
3429
|
[ Opcodes.if, valtypeBinary ],
|
3537
|
-
...(
|
3538
|
-
|
3539
|
-
Opcodes.i32_to_u
|
3540
|
-
]),
|
3430
|
+
...generate(scope, decl.object),
|
3431
|
+
Opcodes.i32_to_u,
|
3541
3432
|
|
3542
|
-
[ Opcodes.i32_load, Math.log2(ValtypeSize.i32) - 1,
|
3433
|
+
[ Opcodes.i32_load, Math.log2(ValtypeSize.i32) - 1, 0 ],
|
3543
3434
|
Opcodes.i32_from_u,
|
3544
3435
|
|
3545
3436
|
...setLastType(scope, TYPES.number),
|
@@ -3591,7 +3482,7 @@ const generateMember = (scope, decl, _global, _name) => {
|
|
3591
3482
|
|
3592
3483
|
return typeSwitch(scope, getNodeType(scope, decl.object), {
|
3593
3484
|
[TYPES.array]: [
|
3594
|
-
...loadArray(scope, object, property
|
3485
|
+
...loadArray(scope, object, property),
|
3595
3486
|
...setLastType(scope)
|
3596
3487
|
],
|
3597
3488
|
|
@@ -3608,14 +3499,12 @@ const generateMember = (scope, decl, _global, _name) => {
|
|
3608
3499
|
...number(ValtypeSize.i16, Valtype.i32),
|
3609
3500
|
[ Opcodes.i32_mul ],
|
3610
3501
|
|
3611
|
-
...
|
3612
|
-
|
3613
|
-
|
3614
|
-
[ Opcodes.i32_add ]
|
3615
|
-
]),
|
3502
|
+
...object,
|
3503
|
+
Opcodes.i32_to_u,
|
3504
|
+
[ Opcodes.i32_add ],
|
3616
3505
|
|
3617
3506
|
// load current string ind {arg}
|
3618
|
-
[ Opcodes.i32_load16_u, Math.log2(ValtypeSize.i16) - 1,
|
3507
|
+
[ Opcodes.i32_load16_u, Math.log2(ValtypeSize.i16) - 1, ValtypeSize.i32 ],
|
3619
3508
|
|
3620
3509
|
// store to new string ind 0
|
3621
3510
|
[ Opcodes.i32_store16, Math.log2(ValtypeSize.i16) - 1, ...unsignedLEB128(newPointer + ValtypeSize.i32) ],
|
@@ -3634,14 +3523,12 @@ const generateMember = (scope, decl, _global, _name) => {
|
|
3634
3523
|
...property,
|
3635
3524
|
Opcodes.i32_to_u,
|
3636
3525
|
|
3637
|
-
...
|
3638
|
-
|
3639
|
-
|
3640
|
-
[ Opcodes.i32_add ]
|
3641
|
-
]),
|
3526
|
+
...object,
|
3527
|
+
Opcodes.i32_to_u,
|
3528
|
+
[ Opcodes.i32_add ],
|
3642
3529
|
|
3643
3530
|
// load current string ind {arg}
|
3644
|
-
[ Opcodes.i32_load8_u, 0, ...unsignedLEB128(
|
3531
|
+
[ Opcodes.i32_load8_u, 0, ...unsignedLEB128(ValtypeSize.i32) ],
|
3645
3532
|
|
3646
3533
|
// store to new string ind 0
|
3647
3534
|
[ Opcodes.i32_store8, 0, ...unsignedLEB128(newPointer + ValtypeSize.i32) ],
|
package/compiler/opt.js
CHANGED
@@ -172,14 +172,14 @@ export default (funcs, globals, pages, tags, exceptions) => {
|
|
172
172
|
}
|
173
173
|
}
|
174
174
|
|
175
|
-
if (inst[inst.length - 1] === 'string_only' && !pages.hasAnyString &&
|
175
|
+
if (inst[inst.length - 1] === 'string_only' && !pages.hasAnyString && Prefs.rmUnusedTypes) {
|
176
176
|
// remove this inst
|
177
177
|
wasm.splice(i, 1);
|
178
178
|
if (i > 0) i--;
|
179
179
|
inst = wasm[i];
|
180
180
|
}
|
181
181
|
|
182
|
-
if (inst[inst.length - 1] === 'string_only|start' && !pages.hasAnyString&&
|
182
|
+
if (inst[inst.length - 1] === 'string_only|start' && !pages.hasAnyString && Prefs.rmUnusedTypes) {
|
183
183
|
let j = i;
|
184
184
|
for (; j < wasm.length; j++) {
|
185
185
|
const op = wasm[j];
|
@@ -193,7 +193,7 @@ export default (funcs, globals, pages, tags, exceptions) => {
|
|
193
193
|
inst = wasm[i];
|
194
194
|
}
|
195
195
|
|
196
|
-
if (inst[0] === Opcodes.if && typeof inst[2] === 'string' &&
|
196
|
+
if (inst[0] === Opcodes.if && typeof inst[2] === 'string' && Prefs.rmUnusedTypes) {
|
197
197
|
// remove unneeded typeswitch checks
|
198
198
|
|
199
199
|
const type = inst[2].split('|')[1];
|
package/compiler/prefs.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
const onByDefault = [ 'bytestring', 'treeshakeWasmImports', 'alwaysMemory', 'indirectCalls', 'optUnused' ];
|
1
|
+
const onByDefault = [ 'bytestring', 'treeshakeWasmImports', 'alwaysMemory', 'indirectCalls', 'optUnused', 'data', 'rmUnusedTypes' ];
|
2
2
|
|
3
3
|
let cache = {};
|
4
4
|
const obj = new Proxy({}, {
|
package/package.json
CHANGED