porffor 0.16.0-79cd8c0c8 → 0.16.0-97bb4f33b
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/cyclone.js +1 -1
- package/compiler/havoc.js +1 -1
- package/compiler/index.js +4 -29
- package/compiler/pgo.js +10 -11
- package/compiler/wrap.js +1 -1
- package/package.json +2 -2
- package/runner/index.js +0 -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/cyclone.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
// cyclone: wasm partial constant evaluator
|
1
|
+
// cyclone: wasm partial constant evaluator
|
2
2
|
import { signedLEB128, ieee754_binary64, read_ieee754_binary64, read_signedLEB128 } from './encoding.js';
|
3
3
|
import { Opcodes, Valtype } from './wasmSpec.js';
|
4
4
|
|
package/compiler/havoc.js
CHANGED
package/compiler/index.js
CHANGED
@@ -27,10 +27,7 @@ const fs = (typeof process?.version !== 'undefined' ? (await import('node:fs'))
|
|
27
27
|
const execSync = (typeof process?.version !== 'undefined' ? (await import('node:child_process')).execSync : undefined);
|
28
28
|
|
29
29
|
export default (code, flags) => {
|
30
|
-
|
31
|
-
if (Prefs.native) target = 'native';
|
32
|
-
|
33
|
-
let outFile = Prefs.o;
|
30
|
+
const target = Prefs.target ?? 'wasm';
|
34
31
|
|
35
32
|
globalThis.valtype = 'f64';
|
36
33
|
const valtypeOpt = process.argv.find(x => x.startsWith('--valtype='));
|
@@ -116,6 +113,8 @@ export default (code, flags) => {
|
|
116
113
|
|
117
114
|
const out = { wasm, funcs, globals, tags, exceptions, pages, data };
|
118
115
|
|
116
|
+
const outFile = Prefs.o;
|
117
|
+
|
119
118
|
if (target === 'wasm' && outFile) {
|
120
119
|
fs.writeFileSync(outFile, Buffer.from(wasm));
|
121
120
|
|
@@ -136,8 +135,6 @@ export default (code, flags) => {
|
|
136
135
|
}
|
137
136
|
|
138
137
|
if (target === 'native') {
|
139
|
-
outFile ??= Prefs.native ? './porffor_tmp' : file.split('/').at(-1).split('.').at(0, -1).join('.');
|
140
|
-
|
141
138
|
let compiler = Prefs.compiler ?? 'clang';
|
142
139
|
const cO = Prefs._cO ?? 'Ofast';
|
143
140
|
|
@@ -156,29 +153,7 @@ export default (code, flags) => {
|
|
156
153
|
|
157
154
|
fs.unlinkSync(tmpfile);
|
158
155
|
|
159
|
-
if (process.version)
|
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
|
-
const runArgs = process.argv.slice(2).filter(x => !x.startsWith('-'));
|
175
|
-
try {
|
176
|
-
execSync([ outFile, ...runArgs.slice(1) ].join(' '), { stdio: 'inherit' });
|
177
|
-
} catch {}
|
178
|
-
}
|
179
|
-
|
180
|
-
process.exit();
|
181
|
-
}
|
156
|
+
if (process.version) process.exit();
|
182
157
|
}
|
183
158
|
|
184
159
|
return out;
|
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/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
|
-
|
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-97bb4f33b",
|
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
|
}
|
package/runner/index.js
CHANGED