porffor 0.16.0-0e7f638da → 0.16.0-0e931a1fa
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/codegen.js +3 -3
- package/compiler/havoc.js +1 -1
- package/compiler/index.js +3 -16
- package/compiler/pgo.js +10 -11
- package/package.json +2 -2
package/compiler/codegen.js
CHANGED
@@ -3270,7 +3270,7 @@ const makeArray = (scope, decl, global = false, name = '$undeclared', initEmpty
|
|
3270
3270
|
firstAssign = true;
|
3271
3271
|
|
3272
3272
|
// todo: can we just have 1 undeclared array? probably not? but this is not really memory efficient
|
3273
|
-
const uniqueName = name === '$undeclared' ? name +
|
3273
|
+
const uniqueName = name === '$undeclared' ? name + Math.random().toString().slice(2) : name;
|
3274
3274
|
|
3275
3275
|
let page;
|
3276
3276
|
if (Prefs.scopedPageNames) page = allocPage(scope, `${getAllocType(itemType)}: ${scope.name}/${uniqueName}`, itemType);
|
@@ -3658,7 +3658,7 @@ const generateMember = (scope, decl, _global, _name) => {
|
|
3658
3658
|
});
|
3659
3659
|
};
|
3660
3660
|
|
3661
|
-
const randId = () => Math.random().toString(16).slice(
|
3661
|
+
const randId = () => Math.random().toString(16).slice(0, -4);
|
3662
3662
|
|
3663
3663
|
const objectHack = node => {
|
3664
3664
|
if (!node) return node;
|
@@ -3710,7 +3710,7 @@ const generateFunc = (scope, decl) => {
|
|
3710
3710
|
if (decl.async) return todo(scope, 'async functions are not supported');
|
3711
3711
|
if (decl.generator) return todo(scope, 'generator functions are not supported');
|
3712
3712
|
|
3713
|
-
const name = decl.id ? decl.id.name : `
|
3713
|
+
const name = decl.id ? decl.id.name : `anonymous_${randId()}`;
|
3714
3714
|
const params = decl.params ?? [];
|
3715
3715
|
|
3716
3716
|
// TODO: share scope/locals between !!!
|
package/compiler/havoc.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
// havoc: wasm rewrite library (it wreaks havoc upon wasm bytecode
|
1
|
+
// havoc: wasm rewrite library (it wreaks havoc upon wasm bytecode)
|
2
2
|
import { Opcodes, Valtype } from './wasmSpec.js';
|
3
3
|
|
4
4
|
export const localsToConsts = (func, targets, consts, { localKeys }) => {
|
package/compiler/index.js
CHANGED
@@ -158,23 +158,10 @@ export default (code, flags) => {
|
|
158
158
|
|
159
159
|
if (process.version) {
|
160
160
|
if (Prefs.native) {
|
161
|
-
const cleanup = () => {
|
162
|
-
try {
|
163
|
-
fs.unlinkSync(outFile);
|
164
|
-
} catch {}
|
165
|
-
};
|
166
|
-
|
167
|
-
process.on('exit', cleanup);
|
168
|
-
process.on('beforeExit', cleanup);
|
169
|
-
process.on('SIGINT', () => {
|
170
|
-
cleanup();
|
171
|
-
process.exit();
|
172
|
-
});
|
173
|
-
|
174
161
|
const runArgs = process.argv.slice(2).filter(x => !x.startsWith('-'));
|
175
|
-
|
176
|
-
|
177
|
-
|
162
|
+
process.on('beforeExit', () => { fs.unlinkSync(outFile); });
|
163
|
+
|
164
|
+
execSync([ outFile, ...runArgs.slice(1) ].join(' '), { stdio: 'inherit' });
|
178
165
|
}
|
179
166
|
|
180
167
|
process.exit();
|
package/compiler/pgo.js
CHANGED
@@ -11,7 +11,7 @@ export const setup = () => {
|
|
11
11
|
|
12
12
|
// enable these prefs by default for pgo
|
13
13
|
Prefs.typeswitchUniqueTmp = Prefs.typeswitchUniqueTmp === false ? false : true;
|
14
|
-
Prefs.cyclone = Prefs.cyclone === false ? false : true
|
14
|
+
Prefs.cyclone = Prefs.cyclone === false ? false : true;;
|
15
15
|
};
|
16
16
|
|
17
17
|
export const run = obj => {
|
@@ -87,10 +87,9 @@ export const run = obj => {
|
|
87
87
|
localData[activeFunc][i].push(n);
|
88
88
|
},
|
89
89
|
w: (ind, outPtr) => { // readArgv
|
90
|
-
const
|
91
|
-
const args = process.argv.slice(pgoInd).filter(x => !x.startsWith('-'));
|
90
|
+
const args = process.argv.slice(process.argv.indexOf('--pgo')).filter(x => !x.startsWith('-'));
|
92
91
|
const str = args[ind - 1];
|
93
|
-
if (
|
92
|
+
if (!str) {
|
94
93
|
if (Prefs.pgoLog) console.log('\nPGO warning: script was expecting arguments, please specify args to use for PGO after --pgo arg');
|
95
94
|
return -1;
|
96
95
|
}
|
@@ -131,18 +130,16 @@ export const run = obj => {
|
|
131
130
|
func.localValues = localValues;
|
132
131
|
|
133
132
|
let counts = new Array(10).fill(0);
|
134
|
-
const consistents = localData[i].map(
|
135
|
-
if (
|
136
|
-
if (x.length === 0 || !x.every((y, i) => i < 1 ? true : y === x[i - 1])) return false; // not consistent
|
133
|
+
const consistents = localData[i].map(x => {
|
134
|
+
if (x.length === 0 || !x.every((y, i) => i < 1 ? true : y === x[i - 1])) return false;
|
137
135
|
|
138
136
|
counts[0]++;
|
139
137
|
return x[0];
|
140
138
|
});
|
141
139
|
|
142
140
|
const integerOnlyF64s = localData[i].map((x, j) => {
|
143
|
-
if (j < func.params.length) return false; // param
|
144
141
|
if (localValues[j].type === Valtype.i32) return false; // already i32
|
145
|
-
if (x.length === 0 || !x.every(y => Number.isInteger(y))) return false;
|
142
|
+
if (x.length === 0 || !x.every(y => Number.isInteger(y))) return false;
|
146
143
|
|
147
144
|
counts[1]++;
|
148
145
|
return true;
|
@@ -153,14 +150,14 @@ export const run = obj => {
|
|
153
150
|
|
154
151
|
log += ` ${func.name}: identified ${counts[0]}/${total} locals as consistent${Prefs.verbosePgo ? ':' : ''}\n`;
|
155
152
|
if (Prefs.verbosePgo) {
|
156
|
-
for (let j =
|
153
|
+
for (let j = 0; j < localData[i].length; j++) {
|
157
154
|
log += ` ${consistents[j] !== false ? '\u001b[92m' : '\u001b[91m'}${localKeys[j]}\u001b[0m: ${new Set(localData[i][j]).size} unique values set\n`;
|
158
155
|
}
|
159
156
|
}
|
160
157
|
|
161
158
|
log += ` ${func.name}: identified ${counts[1]}/${localValues.reduce((acc, x) => acc + (x.type === Valtype.f64 ? 1 : 0), 0)} f64 locals as integer usage only${Prefs.verbosePgo ? ':' : ''}\n`;
|
162
159
|
if (Prefs.verbosePgo) {
|
163
|
-
for (let j =
|
160
|
+
for (let j = 0; j < localData[i].length; j++) {
|
164
161
|
if (localValues[j].type !== Valtype.f64) continue;
|
165
162
|
log += ` ${integerOnlyF64s[j] ? '\u001b[92m' : '\u001b[91m'}${localKeys[j]}\u001b[0m\n`;
|
166
163
|
}
|
@@ -180,6 +177,7 @@ export const run = obj => {
|
|
180
177
|
for (let i = 0; i < x.integerOnlyF64s.length; i++) {
|
181
178
|
const c = x.integerOnlyF64s[i];
|
182
179
|
if (c === false) continue;
|
180
|
+
if (i < x.params.length) continue;
|
183
181
|
|
184
182
|
targets.push(i);
|
185
183
|
}
|
@@ -192,6 +190,7 @@ export const run = obj => {
|
|
192
190
|
for (let i = 0; i < x.consistents.length; i++) {
|
193
191
|
const c = x.consistents[i];
|
194
192
|
if (c === false) continue;
|
193
|
+
if (i < x.params.length) continue;
|
195
194
|
|
196
195
|
targets.push(i);
|
197
196
|
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "porffor",
|
3
3
|
"description": "a basic experimental wip aot optimizing js -> wasm engine/compiler/runtime in js",
|
4
|
-
"version": "0.16.0-
|
4
|
+
"version": "0.16.0-0e931a1fa",
|
5
5
|
"author": "CanadaHonk",
|
6
6
|
"license": "MIT",
|
7
7
|
"scripts": {
|
@@ -28,5 +28,5 @@
|
|
28
28
|
"bugs": {
|
29
29
|
"url": "https://github.com/CanadaHonk/porffor/issues"
|
30
30
|
},
|
31
|
-
"homepage": "https://porffor.
|
31
|
+
"homepage": "https://porffor.goose.icu"
|
32
32
|
}
|