Skip to content

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

Merged
tlively merged 11 commits into
WebAssembly:masterfrom
COFFEETALES:js-list-each-item
Oct 21, 2019
Merged

tlively merged 11 commits into
WebAssembly:masterfrom
COFFEETALES:js-list-each-item

Conversation

@COFFEETALES

Copy link
Copy Markdown
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

@tlively tlively left a comment

Copy link
Copy Markdown
Member

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.

Comment thread src/binaryen-c.cpp Resolved
Comment thread src/binaryen-c.cpp Resolved
Comment thread src/js/binaryen.js-post.js Resolved
Comment thread test/binaryen.js/kitchen-sink.js Resolved
Comment thread src/binaryen-c.cpp Resolved

@tlively tlively left a comment

Copy link
Copy Markdown
Member

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.

Comment thread test/binaryen.js/kitchen-sink.js Resolved
Comment thread src/binaryen-c.cpp Resolved
Comment thread src/binaryen-c.cpp Resolved
Comment thread src/binaryen-c.cpp Resolved
Comment thread src/binaryen-c.cpp Resolved
Comment thread src/binaryen-c.cpp Resolved
Comment thread src/binaryen-c.cpp Resolved
@tlively

tlively commented Oct 17, 2019

Copy link
Copy Markdown
Member

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

dcodeIO commented Nov 12, 2019

Copy link
Copy Markdown
Contributor

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

kripken commented Nov 13, 2019 •

Copy link
Copy Markdown
Member

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

@tlively

tlively commented Nov 13, 2019

Copy link
Copy Markdown
Member

This is fixed by #2432.

@dcodeIO

dcodeIO commented Nov 13, 2019

Copy link
Copy Markdown
Contributor

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