Skip to content

Commit 570de79

Browse files
authored
[C/JS APIs] Allow JS and C to read the start function of a module (#7424)
This PR adds `BinaryenGetStart` to the C api and the corresponding `module.getStart` JS wrapper.
1 parent 85fc8bb commit 570de79

File tree

5 files changed

+11
-0
lines changed

5 files changed

+11
-0
lines changed

src/binaryen-c.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5289,6 +5289,10 @@ void BinaryenSetStart(BinaryenModuleRef module, BinaryenFunctionRef start) {
52895289
((Module*)module)->addStart(((Function*)start)->name);
52905290
}
52915291

5292+
BinaryenFunctionRef BinaryenGetStart(BinaryenModuleRef module) {
5293+
return ((Module*)module)->getFunctionOrNull(((Module*)module)->start);
5294+
}
5295+
52925296
// Features
52935297

52945298
BinaryenFeatures BinaryenModuleGetFeatures(BinaryenModuleRef module) {

src/binaryen-c.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2869,6 +2869,8 @@ BINARYEN_API void BinaryenAddDataSegment(BinaryenModuleRef module,
28692869
BINARYEN_API void BinaryenSetStart(BinaryenModuleRef module,
28702870
BinaryenFunctionRef start);
28712871

2872+
BINARYEN_API BinaryenFunctionRef BinaryenGetStart(BinaryenModuleRef module);
2873+
28722874
// Features
28732875

28742876
// These control what features are allowed when validation and in passes.

src/js/binaryen.js-post.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2594,6 +2594,9 @@ function wrapModule(module, self = {}) {
25942594
self['setStart'] = function(start) {
25952595
return Module['_BinaryenSetStart'](module, start);
25962596
};
2597+
self['getStart'] = function() {
2598+
return Module['_BinaryenGetStart'](module);
2599+
};
25972600
self['getFeatures'] = function() {
25982601
return Module['_BinaryenModuleGetFeatures'](module);
25992602
};

test/binaryen.js/kitchen-sink.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,7 @@ function test_core() {
760760
// Start function. One per module
761761
var starter = module.addFunction("starter", binaryen.none, binaryen.none, [], module.nop());
762762
module.setStart(starter);
763+
assert(module.getStart() == starter);
763764

764765
var features = binaryen.Features.All;
765766
module.setFeatures(features);

test/example/c-api-kitchen-sink.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,6 +1376,7 @@ void test_core() {
13761376
0,
13771377
BinaryenNop(module));
13781378
BinaryenSetStart(module, starter);
1379+
assert(BinaryenGetStart(module) == starter);
13791380

13801381
BinaryenFeatures features = BinaryenFeatureAll();
13811382
BinaryenModuleSetFeatures(module, features);

0 commit comments

Comments
 (0)