Skip to content

Ability to list each item on Exports/Data Segments/Functions #2386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Oct 21, 2019
Merged

Ability to list each item on Exports/Data Segments/Functions #2386

merged 11 commits into from
Oct 21, 2019

Conversation

COFFEETALES
Copy link
Contributor

It gives the possibility to list several contents in a decoded module.

Some examples of the use of the JS api:

const decodedModule = binaryen.parseText( my_wast_content );

for ( let i = 0, len = decodedModule.getNumExports() ; i !== len ; ++i )
{
    const ptr = decodedModule.getExportByIndex(i);
    const expInfo = binaryen.getExportInfo(ptr);

    console.log('export id: ' + i.toString(10));
    console.log('ptr: ' + ptr.toString(10));
    console.log('expName: ' + expInfo.name);
}

for ( let i = 0, len = decodedModule.getNumFunctions() ; i !== len ; ++i )
{
    const ptr = decodedModule.getFunctionByIndex(i);
    const funcInfo = binaryen.getFunctionInfo( ptr );

    console.log('function id: ' + i.toString(10));
    console.log('ptr: ' + ptr.toString(10));
    console.log(funcInfo);
}

for ( let i = 0, len = decodedModule.getNumMemorySegments() ; i !== len ; ++i )
{
    const segment = decodedModule.getMemorySegmentInfoByIndex(i);

    console.log('data segment id: ' + i.toString(10));
    console.log('byteOffset: ' + segment.byteOffset );
    console.log(new Uint32Array(segment.data)); // ArrayBuffer treated as Uint32
}

@COFFEETALES COFFEETALES changed the title Ability to list each item from Exports/Data Segments/Functions Ability to list each item of Exports/Data Segments/Functions Oct 15, 2019
@COFFEETALES COFFEETALES changed the title Ability to list each item of Exports/Data Segments/Functions Ability to list each item on Exports/Data Segments/Functions Oct 15, 2019
@tlively tlively self-requested a review October 15, 2019 17:04
Copy link
Member

@tlively tlively left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small comments inline. Please also add tests in test/binaryen.js/kitchen-sink.js and test/example/c-api-kitchen-sink.c.

Copy link
Member

@tlively tlively left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Just one last readability comment on the tests and I think we're good to go.

@tlively
Copy link
Member

tlively commented Oct 17, 2019

Sorry, I noticed a few more C++ issues. This is the last of it for real now 👍

@tlively tlively merged commit 29da5c9 into WebAssembly:master Oct 21, 2019
@dcodeIO
Copy link
Contributor

dcodeIO commented Nov 12, 2019

While creating the respective bindings for AssemblyScript, I noticed that there is

int64_t BinaryenGetMemorySegmentByteOffset(BinaryenModuleRef module,
                                           BinaryenIndex id) {

returning an int64_t, which might be problematic in JS/Wasm contexts (potentially overflow a double or be illegal without BigInt integration). Mentioning since we are using a portable C binding in JS on our end, where there is no i64, so we can't use this API.

@kripken
Copy link
Member

kripken commented Nov 13, 2019

@dcodeIO The returned value will contain the lower 32 bits, though, so it should just work for you (with wasm32 for sure).

@tlively
Copy link
Member

tlively commented Nov 13, 2019

This is fixed by #2432.

@dcodeIO
Copy link
Contributor

dcodeIO commented Nov 13, 2019

Thanks! 🎉

Being so cautious here because asc is intended to be compiled to both JS and Wasm interchangeably at some point and whenever i64 or BigInt (which we don't have a good story for yet) pop up, I become a little nervous :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants