porffor 0.16.0-0e931a1fa → 0.16.0-21627938
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 +16 -3
- package/compiler/pgo.js +11 -10
- package/compiler/wrap.js +1 -1
- 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 + randId() : 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(1, -2).padEnd(12, '0');
|
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 hence "havoc")
|
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,10 +158,23 @@ export default (code, flags) => {
|
|
158
158
|
|
159
159
|
if (process.version) {
|
160
160
|
if (Prefs.native) {
|
161
|
-
const
|
162
|
-
|
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
|
+
});
|
163
173
|
|
164
|
-
|
174
|
+
const runArgs = process.argv.slice(2).filter(x => !x.startsWith('-'));
|
175
|
+
try {
|
176
|
+
execSync([ outFile, ...runArgs.slice(1) ].join(' '), { stdio: 'inherit' });
|
177
|
+
} catch {}
|
165
178
|
}
|
166
179
|
|
167
180
|
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,9 +87,10 @@ export const run = obj => {
|
|
87
87
|
localData[activeFunc][i].push(n);
|
88
88
|
},
|
89
89
|
w: (ind, outPtr) => { // readArgv
|
90
|
-
const
|
90
|
+
const pgoInd = process.argv.indexOf('--pgo');
|
91
|
+
const args = process.argv.slice(pgoInd).filter(x => !x.startsWith('-'));
|
91
92
|
const str = args[ind - 1];
|
92
|
-
if (!str) {
|
93
|
+
if (pgoInd === -1 || !str) {
|
93
94
|
if (Prefs.pgoLog) console.log('\nPGO warning: script was expecting arguments, please specify args to use for PGO after --pgo arg');
|
94
95
|
return -1;
|
95
96
|
}
|
@@ -130,16 +131,18 @@ export const run = obj => {
|
|
130
131
|
func.localValues = localValues;
|
131
132
|
|
132
133
|
let counts = new Array(10).fill(0);
|
133
|
-
const consistents = localData[i].map(x => {
|
134
|
-
if (
|
134
|
+
const consistents = localData[i].map((x, j) => {
|
135
|
+
if (j < func.params.length) return false; // param
|
136
|
+
if (x.length === 0 || !x.every((y, i) => i < 1 ? true : y === x[i - 1])) return false; // not consistent
|
135
137
|
|
136
138
|
counts[0]++;
|
137
139
|
return x[0];
|
138
140
|
});
|
139
141
|
|
140
142
|
const integerOnlyF64s = localData[i].map((x, j) => {
|
143
|
+
if (j < func.params.length) return false; // param
|
141
144
|
if (localValues[j].type === Valtype.i32) return false; // already i32
|
142
|
-
if (x.length === 0 || !x.every(y => Number.isInteger(y))) return false;
|
145
|
+
if (x.length === 0 || !x.every(y => Number.isInteger(y))) return false; // not all integer values
|
143
146
|
|
144
147
|
counts[1]++;
|
145
148
|
return true;
|
@@ -150,14 +153,14 @@ export const run = obj => {
|
|
150
153
|
|
151
154
|
log += ` ${func.name}: identified ${counts[0]}/${total} locals as consistent${Prefs.verbosePgo ? ':' : ''}\n`;
|
152
155
|
if (Prefs.verbosePgo) {
|
153
|
-
for (let j =
|
156
|
+
for (let j = func.params.length; j < localData[i].length; j++) {
|
154
157
|
log += ` ${consistents[j] !== false ? '\u001b[92m' : '\u001b[91m'}${localKeys[j]}\u001b[0m: ${new Set(localData[i][j]).size} unique values set\n`;
|
155
158
|
}
|
156
159
|
}
|
157
160
|
|
158
161
|
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`;
|
159
162
|
if (Prefs.verbosePgo) {
|
160
|
-
for (let j =
|
163
|
+
for (let j = func.params.length; j < localData[i].length; j++) {
|
161
164
|
if (localValues[j].type !== Valtype.f64) continue;
|
162
165
|
log += ` ${integerOnlyF64s[j] ? '\u001b[92m' : '\u001b[91m'}${localKeys[j]}\u001b[0m\n`;
|
163
166
|
}
|
@@ -177,7 +180,6 @@ export const run = obj => {
|
|
177
180
|
for (let i = 0; i < x.integerOnlyF64s.length; i++) {
|
178
181
|
const c = x.integerOnlyF64s[i];
|
179
182
|
if (c === false) continue;
|
180
|
-
if (i < x.params.length) continue;
|
181
183
|
|
182
184
|
targets.push(i);
|
183
185
|
}
|
@@ -190,7 +192,6 @@ export const run = obj => {
|
|
190
192
|
for (let i = 0; i < x.consistents.length; i++) {
|
191
193
|
const c = x.consistents[i];
|
192
194
|
if (c === false) continue;
|
193
|
-
if (i < x.params.length) continue;
|
194
195
|
|
195
196
|
targets.push(i);
|
196
197
|
|
package/compiler/wrap.js
CHANGED
@@ -128,7 +128,7 @@ export default (source, flags = [ 'module' ], customImports = {}, print = str =>
|
|
128
128
|
|
129
129
|
if (source.includes?.('export ')) flags.push('module');
|
130
130
|
|
131
|
-
fs.writeFileSync('out.wasm', Buffer.from(wasm));
|
131
|
+
// fs.writeFileSync('out.wasm', Buffer.from(wasm));
|
132
132
|
|
133
133
|
times.push(performance.now() - t1);
|
134
134
|
if (Prefs.profileCompiler) console.log(bold(`compiled in ${times[0].toFixed(2)}ms`));
|
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-021627938",
|
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.dev"
|
32
32
|
}
|