porffor 0.60.19 → 0.60.21
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/cyclone.js +30 -3
- package/compiler/index.js +11 -39
- package/jsr.json +1 -1
- package/package.json +1 -1
- package/runtime/index.js +1 -1
package/compiler/cyclone.js
CHANGED
@@ -19,12 +19,16 @@ const f64ToI32Op = {
|
|
19
19
|
// const inv = (obj, keyMap = x => x) => Object.keys(obj).reduce((acc, x) => { acc[keyMap(obj[x])] = x; return acc; }, {});
|
20
20
|
// const invOpcodes = inv(Opcodes);
|
21
21
|
|
22
|
-
export default ({ name, wasm, locals: _locals, params }) => {
|
22
|
+
export default ({ name, wasm, locals: _locals, params }, _globals) => {
|
23
23
|
let locals = Object.values(_locals);
|
24
|
-
const localNames = Object.keys(_locals);
|
24
|
+
// const localNames = Object.keys(_locals);
|
25
25
|
const localValtypes = locals.map(x => x.type);
|
26
26
|
const localNeeded = new Array(locals.length).fill(0);
|
27
27
|
|
28
|
+
let globals = Object.values(_globals);
|
29
|
+
const globalValtypes = globals.map(x => x.type);
|
30
|
+
// const globalNeeded = new Array(globals.length).fill(0);
|
31
|
+
|
28
32
|
// every pass does the same initial low level things
|
29
33
|
// each subsequent pass does it again and does more high-level things
|
30
34
|
const passes = [
|
@@ -467,7 +471,7 @@ export default ({ name, wasm, locals: _locals, params }) => {
|
|
467
471
|
break;
|
468
472
|
}
|
469
473
|
|
470
|
-
case Opcodes.f64_copysign: { //
|
474
|
+
case Opcodes.f64_copysign: { // todo: check behavior
|
471
475
|
if (stack.length < 2) { empty(); break; };
|
472
476
|
const [ b, a ] = pop2();
|
473
477
|
const v = Math.abs(a) * (b > 0 ? 1 : -1);
|
@@ -567,6 +571,29 @@ export default ({ name, wasm, locals: _locals, params }) => {
|
|
567
571
|
break;
|
568
572
|
}
|
569
573
|
|
574
|
+
case Opcodes.global_get: {
|
575
|
+
const x = globals[op[1]];
|
576
|
+
if (x === false) {
|
577
|
+
empty();
|
578
|
+
} else {
|
579
|
+
replaceVal(x, globalValtypes[op[1]]);
|
580
|
+
push(x);
|
581
|
+
}
|
582
|
+
break;
|
583
|
+
}
|
584
|
+
|
585
|
+
case Opcodes.global_set: {
|
586
|
+
if (stack.length < 1) {
|
587
|
+
globals[op[1]] = false;
|
588
|
+
empty();
|
589
|
+
break;
|
590
|
+
}
|
591
|
+
|
592
|
+
const x = peek();
|
593
|
+
globals[op[1]] = x;
|
594
|
+
break;
|
595
|
+
}
|
596
|
+
|
570
597
|
case Opcodes.block:
|
571
598
|
case Opcodes.loop:
|
572
599
|
case Opcodes.try:
|
package/compiler/index.js
CHANGED
@@ -135,7 +135,7 @@ export default (code, module = Prefs.module) => {
|
|
135
135
|
|
136
136
|
for (const x of funcs) {
|
137
137
|
const preOps = x.wasm.length;
|
138
|
-
cyclone(x);
|
138
|
+
cyclone(x, globals);
|
139
139
|
|
140
140
|
if (preOps !== x.wasm.length) console.log(`${x.name}: ${preOps} -> ${x.wasm.length} ops`);
|
141
141
|
}
|
@@ -147,7 +147,7 @@ export default (code, module = Prefs.module) => {
|
|
147
147
|
console.log(`cyclone size diff: ${oldSize - newSize} bytes (${oldSize} -> ${newSize})\n`);
|
148
148
|
} else {
|
149
149
|
for (const x of funcs) {
|
150
|
-
cyclone(x);
|
150
|
+
cyclone(x, globals);
|
151
151
|
}
|
152
152
|
}
|
153
153
|
}
|
@@ -212,46 +212,18 @@ export default (code, module = Prefs.module) => {
|
|
212
212
|
console.log([...pages.keys()].map(x => `\x1B[36m - ${x}\x1B[0m`).join('\n') + '\n');
|
213
213
|
}
|
214
214
|
|
215
|
-
if (Prefs.
|
216
|
-
|
217
|
-
const cO = Prefs._cO ?? 'Oz';
|
215
|
+
if (Prefs.wasmOpt) {
|
216
|
+
if (logProgress) progressStart('wasm-opt...');
|
218
217
|
|
219
|
-
const
|
220
|
-
|
221
|
-
'
|
222
|
-
|
223
|
-
|
224
|
-
'-s', 'EXPORTED_FUNCTIONS=\'["_m"]\'',
|
225
|
-
'-nostartfiles',
|
226
|
-
'-Wl,--no-entry',
|
227
|
-
'-o', tmpFile,
|
228
|
-
'-' + cO,
|
229
|
-
Prefs.d ? '-g' : ''
|
230
|
-
];
|
231
|
-
|
232
|
-
if (Prefs.clangFast) args.push('-flto=thin', '-march=native', '-ffast-math', '-fno-asynchronous-unwind-tables');
|
233
|
-
|
234
|
-
if (Prefs.s) args.push('-s');
|
235
|
-
|
236
|
-
Prefs['2cWasmImports'] = true;
|
237
|
-
const c = toc(out)
|
238
|
-
.replace(`int main()`, `
|
239
|
-
void __wasi_proc_exit(int code) {
|
240
|
-
__builtin_trap();
|
241
|
-
}
|
242
|
-
|
243
|
-
int m()`);
|
244
|
-
Prefs['2cWasmImports'] = false;
|
245
|
-
|
246
|
-
// obvious command escape is obvious
|
247
|
-
execSync(args.join(' '), {
|
248
|
-
stdio: [ 'pipe', 'inherit', 'inherit' ],
|
249
|
-
input: c,
|
250
|
-
encoding: 'utf8'
|
218
|
+
const t4 = performance.now();
|
219
|
+
const newWasm = execSync(`wasm-opt -all -O4 -o -`, {
|
220
|
+
stdio: [ 'pipe', 'pipe', 'pipe' ],
|
221
|
+
input: wasm,
|
222
|
+
encoding: null
|
251
223
|
});
|
224
|
+
wasm = out.wasm = new Uint8Array(newWasm);
|
252
225
|
|
253
|
-
|
254
|
-
fs.unlinkSync(tmpFile);
|
226
|
+
if (logProgress) progressDone('wasm-opt', t4);
|
255
227
|
}
|
256
228
|
|
257
229
|
if (target === 'wasm' && outFile) {
|
package/jsr.json
CHANGED
package/package.json
CHANGED