porffor 0.30.10 → 0.30.11
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/assemble.js +14 -3
- package/compiler/prefs.js +22 -30
- package/compiler/wrap.js +11 -30
- package/package.json +1 -1
- package/runner/index.js +1 -1
package/compiler/assemble.js
CHANGED
@@ -309,7 +309,8 @@ export default (funcs, globals, tags, pages, data, flags, noTreeshake = false) =
|
|
309
309
|
|
310
310
|
// todo: move const, call transforms here too?
|
311
311
|
|
312
|
-
const
|
312
|
+
const makeAssembled = Prefs.d;
|
313
|
+
let wasm = [], wasmNonFlat = [];
|
313
314
|
for (let i = 0; i < x.wasm.length; i++) {
|
314
315
|
let o = x.wasm[i];
|
315
316
|
|
@@ -323,10 +324,20 @@ export default (funcs, globals, tags, pages, data, flags, noTreeshake = false) =
|
|
323
324
|
unsignedLEB128_into(n, o);
|
324
325
|
}
|
325
326
|
|
326
|
-
|
327
|
+
for (let j = 0; j < o.length; j++) {
|
328
|
+
const x = o[j];
|
329
|
+
if (x == null || !(x <= 0xff)) continue;
|
330
|
+
wasm.push(x);
|
331
|
+
}
|
332
|
+
|
333
|
+
if (makeAssembled) wasmNonFlat.push(o);
|
334
|
+
}
|
335
|
+
|
336
|
+
if (makeAssembled) {
|
337
|
+
x.assembled = { localDecl, wasm, wasmNonFlat };
|
327
338
|
}
|
328
339
|
|
329
|
-
return encodeVector([ ...encodeVector(localDecl), ...wasm
|
340
|
+
return encodeVector([ ...encodeVector(localDecl), ...wasm, Opcodes.end ]);
|
330
341
|
}))
|
331
342
|
);
|
332
343
|
|
package/compiler/prefs.js
CHANGED
@@ -1,35 +1,27 @@
|
|
1
1
|
const onByDefault = [ 'bytestring', 'treeshakeWasmImports', 'alwaysMemory', 'indirectCalls', 'optUnused', 'data', 'passiveData', 'rmUnusedTypes' ];
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
})();
|
21
|
-
|
22
|
-
// do not cache in web demo as args are changed live
|
23
|
-
if (!globalThis.document) cache[p] = ret;
|
24
|
-
return ret;
|
25
|
-
},
|
26
|
-
|
27
|
-
set(_, p, v) {
|
28
|
-
cache[p] = v;
|
29
|
-
return true;
|
3
|
+
const nameToKey = x => x.replace(/[a-z]\-[a-z]/g, y => `${y[0]}${y[2].toUpperCase()}`);
|
4
|
+
|
5
|
+
let prefs = {};
|
6
|
+
const getPrefs = () => {
|
7
|
+
prefs = {};
|
8
|
+
for (const x of onByDefault) prefs[x] = true;
|
9
|
+
|
10
|
+
for (const x of process.argv) {
|
11
|
+
if (x[0] !== '-') continue;
|
12
|
+
|
13
|
+
let flag = x.slice(x[1] === '-' ? 2 : 1);
|
14
|
+
if (flag.startsWith('no-')) {
|
15
|
+
prefs[nameToKey(flag.slice(3))] = false;
|
16
|
+
} else {
|
17
|
+
const [ name, value ] = flag.split('=');
|
18
|
+
prefs[nameToKey(name)] = value ?? true;
|
19
|
+
}
|
30
20
|
}
|
31
|
-
}
|
21
|
+
};
|
22
|
+
getPrefs();
|
32
23
|
|
33
|
-
export
|
24
|
+
export default prefs;
|
34
25
|
|
35
|
-
export
|
26
|
+
export const uncache = () => getPrefs();
|
27
|
+
globalThis.argvChanged = uncache;
|
package/compiler/wrap.js
CHANGED
@@ -326,7 +326,8 @@ export default (source, flags = [ 'module' ], customImports = {}, print = str =>
|
|
326
326
|
max = func.wasm.length;
|
327
327
|
}
|
328
328
|
|
329
|
-
const decomp = decompile(func.wasm.slice(min, max), func.name, 0, func.locals, func.params, func.returns, funcs, globals, exceptions)
|
329
|
+
const decomp = decompile(func.wasm.slice(min, max), func.name, 0, func.locals, func.params, func.returns, funcs, globals, exceptions)
|
330
|
+
.slice(0, -1).split('\n').filter(x => !x.startsWith('\x1B[90m;;'));
|
330
331
|
|
331
332
|
const noAnsi = s => s.replace(/\u001b\[[0-9]+m/g, '');
|
332
333
|
let longest = 0;
|
@@ -342,35 +343,18 @@ export default (source, flags = [ 'module' ], customImports = {}, print = str =>
|
|
342
343
|
if (min != 0) console.log('\x1B[90m...\x1B[0m');
|
343
344
|
console.log(decomp.join('\n'));
|
344
345
|
if (max > func.wasm.length) console.log('\x1B[90m...\x1B[0m\n');
|
345
|
-
}
|
346
|
+
};
|
346
347
|
|
347
348
|
const backtrace = (funcInd, blobOffset) => {
|
348
349
|
if (funcInd == null || blobOffset == null ||
|
349
350
|
Number.isNaN(funcInd) || Number.isNaN(blobOffset)) return false;
|
350
351
|
|
351
|
-
// convert blob offset -> function wasm offset
|
352
|
-
// this is not good code and is somewhat duplicated
|
353
|
-
// I just want it to work for debugging, I don't care about perf/yes
|
352
|
+
// convert blob offset -> function wasm offset
|
354
353
|
const func = funcs.find(x => x.index === funcInd);
|
355
354
|
if (!func) return false;
|
356
355
|
|
357
|
-
const
|
358
|
-
|
359
|
-
let localDecl = [], typeCount = 0, lastType;
|
360
|
-
for (let i = 0; i < locals.length; i++) {
|
361
|
-
const local = locals[i];
|
362
|
-
if (i !== 0 && local.type !== lastType) {
|
363
|
-
localDecl.push(encodeLocal(typeCount, lastType));
|
364
|
-
typeCount = 0;
|
365
|
-
}
|
366
|
-
|
367
|
-
typeCount++;
|
368
|
-
lastType = local.type;
|
369
|
-
}
|
370
|
-
|
371
|
-
if (typeCount !== 0) localDecl.push(encodeLocal(typeCount, lastType));
|
372
|
-
|
373
|
-
const toFind = encodeVector(localDecl).concat(func.wasm.flat().filter(x => x != null && x <= 0xff).slice(0, 60));
|
356
|
+
const { wasm: assembledWasmFlat, wasmNonFlat: assembledWasmOps, localDecl } = func.assembled;
|
357
|
+
const toFind = encodeVector(localDecl).concat(assembledWasmFlat.slice(0, 100));
|
374
358
|
|
375
359
|
let i = 0;
|
376
360
|
for (; i < wasm.length; i++) {
|
@@ -390,24 +374,21 @@ export default (source, flags = [ 'module' ], customImports = {}, print = str =>
|
|
390
374
|
return false;
|
391
375
|
}
|
392
376
|
|
393
|
-
const offset = (blobOffset - i)
|
377
|
+
const offset = (blobOffset - i) - encodeVector(localDecl).length;
|
394
378
|
|
395
379
|
let cumLen = 0;
|
396
380
|
i = 0;
|
397
|
-
for (; i <
|
398
|
-
cumLen +=
|
381
|
+
for (; i < assembledWasmOps.length; i++) {
|
382
|
+
cumLen += assembledWasmOps[i].filter(x => x != null && x <= 0xff).length;
|
399
383
|
if (cumLen === offset) break;
|
400
384
|
}
|
401
385
|
|
402
|
-
if (cumLen !== offset)
|
386
|
+
if (cumLen !== offset) {
|
403
387
|
printDecomp(-1, func, funcs, globals, exceptions);
|
404
388
|
return false;
|
405
389
|
}
|
406
390
|
|
407
|
-
i
|
408
|
-
|
409
|
-
printDecomp(i, func, funcs, globals, exceptions);
|
410
|
-
|
391
|
+
printDecomp(i + 1, func, funcs, globals, exceptions);
|
411
392
|
return true;
|
412
393
|
};
|
413
394
|
|
package/package.json
CHANGED