Description
Bug description
In a transform's afterCompile
stage, I should be able to get information about the module's exports. Indeed, the number of exports seems to be correct, and they have addresses. But for some reason I can't quite figure out - their names are blank.
However, if I generate binary from the module, then reload it - then I get the information I was looking for. But this seems rather inefficient and unnecessary.
Steps to reproduce
Make a new AssemblyScript project, containing at least one exported function.
Add a myTransform.js
file:
import { Transform } from "assemblyscript/dist/transform.js";
import binaryen from "binaryen";
import console from "console";
export default class MyTransform extends Transform {
afterCompile(module) {
// Uncomment this to workaround the issue
// module = binaryen.readBinary(module.emitBinary());
const n = module.getNumExports();
for (let i = 0; i < n; ++i) {
const ref = module.getExportByIndex(i);
const info = binaryen.getExportInfo(ref);
console.log(ref, info);
}
}
}
Add the transform in asconfig.json
, or compile with --transform ./myTransform.js
, as per the docs.
Compile, and note that the output is something like the following:
5532704 { kind: 0, name: '', value: '' }
5533280 { kind: 0, name: '', value: '' }
5746088 { kind: 0, name: '', value: '' }
5747704 { kind: 0, name: '', value: '' }
5749368 { kind: 0, name: '', value: '' }
5751000 { kind: 0, name: '', value: '' }
5751160 { kind: 0, name: '', value: '' }
5754088 { kind: 0, name: '', value: '' }
5753920 { kind: 0, name: '', value: '' }
Then, uncomment the line indicated to workaround the bug, and it compile again. This time, the information is presented correctly:
5551080 { kind: 0, name: 'myFunction1', value: '0' }
5551256 { kind: 0, name: 'myFunction2', value: '1' }
5551416 { kind: 0, name: '__new', value: '58' }
5551592 { kind: 0, name: '__pin', value: '59' }
5551720 { kind: 0, name: '__unpin', value: '60' }
5551568 { kind: 0, name: '__collect', value: '61' }
5551512 { kind: 3, name: '__rtti_base', value: 'global$16' }
5552176 { kind: 2, name: 'memory', value: '0' }
5552256 { kind: 0, name: '_start', value: '66' }
AssemblyScript version
v0.27.25