porffor 0.18.11 → 0.18.13
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/builtins/porffor.d.ts +2 -0
- package/compiler/builtins.js +1 -1
- package/compiler/wrap.js +39 -22
- package/package.json +1 -1
- package/runner/index.js +1 -1
package/compiler/builtins.js
CHANGED
@@ -1177,7 +1177,7 @@ export const BuiltinFuncs = function() {
|
|
1177
1177
|
[ Opcodes.global_get, 0 ],
|
1178
1178
|
[ Opcodes.local_get, 0 ],
|
1179
1179
|
[ Opcodes.i32_add ],
|
1180
|
-
[ Opcodes.global_set, 0 ]
|
1180
|
+
[ Opcodes.global_set, 0 ],
|
1181
1181
|
[ Opcodes.end ],
|
1182
1182
|
|
1183
1183
|
// return currentPtr
|
package/compiler/wrap.js
CHANGED
@@ -147,6 +147,36 @@ export default (source, flags = [ 'module' ], customImports = {}, print = str =>
|
|
147
147
|
times.push(performance.now() - t1);
|
148
148
|
if (Prefs.profileCompiler) console.log(bold(`compiled in ${times[0].toFixed(2)}ms`));
|
149
149
|
|
150
|
+
const printDecomp = (middleIndex, func, funcs, globals, exceptions) => {
|
151
|
+
console.log(`\x1B[35m\x1B[1mporffor backtrace\u001b[0m`);
|
152
|
+
console.log('\x1B[4m' + func.name + '\x1B[0m');
|
153
|
+
|
154
|
+
const surrounding = Prefs.backtraceSurrounding ?? 5;
|
155
|
+
let min = middleIndex - surrounding;
|
156
|
+
let max = middleIndex + surrounding + 1;
|
157
|
+
if (Prefs.backtraceEntireFunc || middleIndex == -1) {
|
158
|
+
min = 0;
|
159
|
+
max = func.wasm.length;
|
160
|
+
}
|
161
|
+
|
162
|
+
const decomp = decompile(func.wasm.slice(min, max), '', 0, func.locals, func.params, func.returns, funcs, globals, exceptions).slice(0, -1).split('\n');
|
163
|
+
|
164
|
+
const noAnsi = s => s.replace(/\u001b\[[0-9]+m/g, '');
|
165
|
+
let longest = 0;
|
166
|
+
for (let j = 0; j < decomp.length; j++) {
|
167
|
+
longest = Math.max(longest, noAnsi(decomp[j]).length);
|
168
|
+
}
|
169
|
+
|
170
|
+
if (middleIndex != -1) {
|
171
|
+
const middle = Math.floor(decomp.length / 2);
|
172
|
+
decomp[middle] = `\x1B[47m\x1B[30m${noAnsi(decomp[middle])}${'\u00a0'.repeat(longest - noAnsi(decomp[middle]).length)}\x1B[0m`;
|
173
|
+
}
|
174
|
+
|
175
|
+
if (min != 0) console.log('\x1B[90m...\x1B[0m');
|
176
|
+
console.log(decomp.join('\n'));
|
177
|
+
if (max >= func.wasm.length) console.log('\x1B[90m...\x1B[0m\n');
|
178
|
+
}
|
179
|
+
|
150
180
|
const backtrace = (funcInd, blobOffset) => {
|
151
181
|
if (funcInd == null || blobOffset == null ||
|
152
182
|
Number.isNaN(funcInd) || Number.isNaN(blobOffset)) return false;
|
@@ -188,7 +218,10 @@ export default (source, flags = [ 'module' ], customImports = {}, print = str =>
|
|
188
218
|
if (!mismatch) break;
|
189
219
|
}
|
190
220
|
|
191
|
-
if (i === wasm.length)
|
221
|
+
if (i === wasm.length) {
|
222
|
+
printDecomp(-1, func, funcs, globals, exceptions);
|
223
|
+
return false;
|
224
|
+
}
|
192
225
|
|
193
226
|
const offset = (blobOffset - i) + encodeVector(localDecl).length;
|
194
227
|
|
@@ -199,30 +232,14 @@ export default (source, flags = [ 'module' ], customImports = {}, print = str =>
|
|
199
232
|
if (cumLen === offset) break;
|
200
233
|
}
|
201
234
|
|
202
|
-
if (cumLen !== offset)
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
console.log(`\x1B[35m\x1B[1mporffor backtrace\u001b[0m`);
|
207
|
-
|
208
|
-
console.log('\x1B[4m' + func.name + '\x1B[0m');
|
209
|
-
|
210
|
-
const surrounding = 6;
|
211
|
-
|
212
|
-
const decomp = decompile(func.wasm.slice(i - surrounding, i + surrounding + 1), '', 0, func.locals, func.params, func.returns, funcs, globals, exceptions).slice(0, -1).split('\n');
|
213
|
-
|
214
|
-
const noAnsi = s => s.replace(/\u001b\[[0-9]+m/g, '');
|
215
|
-
let longest = 0;
|
216
|
-
for (let j = 0; j < decomp.length; j++) {
|
217
|
-
longest = Math.max(longest, noAnsi(decomp[j]).length);
|
235
|
+
if (cumLen !== offset) {
|
236
|
+
printDecomp(-1, func, funcs, globals, exceptions);
|
237
|
+
return false;
|
218
238
|
}
|
219
239
|
|
220
|
-
|
221
|
-
decomp[middle] = `\x1B[47m\x1B[30m${noAnsi(decomp[middle])}${'\u00a0'.repeat(longest - noAnsi(decomp[middle]).length)}\x1B[0m`;
|
240
|
+
i -= 1;
|
222
241
|
|
223
|
-
|
224
|
-
console.log(decomp.join('\n'));
|
225
|
-
console.log('\x1B[90m...\x1B[0m\n');
|
242
|
+
printDecomp(i, func, funcs, globals, exceptions);
|
226
243
|
|
227
244
|
return true;
|
228
245
|
};
|
package/package.json
CHANGED