@@ -3561,6 +3561,92 @@ void BinaryenSetFunctionTable(BinaryenModuleRef module,
3561
3561
wasm->table .segments .push_back (segment);
3562
3562
}
3563
3563
3564
+ // Function table segments. Query utilities.
3565
+
3566
+ uint32_t BinaryenGetNumFunctionTableSegments (BinaryenModuleRef module ) {
3567
+ if (tracing) {
3568
+ std::cout << " BinaryenGetNumFunctionTableSegments(the_module);\n " ;
3569
+ }
3570
+
3571
+ auto * wasm = (Module*)module ;
3572
+ return wasm->table .segments .size ();
3573
+ }
3574
+
3575
+ uint32_t
3576
+ BinaryenGetFunctionTableSegmentOffset (BinaryenModuleRef module , BinaryenIndex id) {
3577
+ if (tracing) {
3578
+ std::cout << " BinaryenGetFunctionTableSegmentOffset(the_module, " << id
3579
+ << " );\n " ;
3580
+ }
3581
+
3582
+ auto * wasm = (Module*)module ;
3583
+ if (wasm->table .segments .size () <= id) {
3584
+ Fatal () << " invalid segment id." ;
3585
+ }
3586
+
3587
+ auto globalOffset = [&](const Expression* const & expr,
3588
+ int64_t & result) -> bool {
3589
+ if (auto * c = expr->dynCast <Const>()) {
3590
+ result = c->value .getInteger ();
3591
+ return true ;
3592
+ }
3593
+ return false ;
3594
+ };
3595
+
3596
+ const Table::Segment& segment = wasm->table .segments [id];
3597
+
3598
+ int64_t ret;
3599
+ if (globalOffset (segment.offset , ret)) {
3600
+ return ret;
3601
+ }
3602
+ if (auto * get = segment.offset ->dynCast <GlobalGet>()) {
3603
+ Global* global = wasm->getGlobal (get->name );
3604
+ if (globalOffset (global->init , ret)) {
3605
+ return ret;
3606
+ }
3607
+ }
3608
+
3609
+ Fatal () << " non-constant offsets aren't supported yet" ;
3610
+ return 0 ;
3611
+ }
3612
+
3613
+ size_t BinaryenGetFunctionTableSegmentLength (BinaryenModuleRef module ,
3614
+ BinaryenIndex id) {
3615
+ if (tracing) {
3616
+ std::cout << " BinaryenGetFunctionTableSegmentLength(the_module, " << id
3617
+ << " );\n " ;
3618
+ }
3619
+
3620
+ auto * wasm = (Module*)module ;
3621
+ if (wasm->table .segments .size () <= id) {
3622
+ Fatal () << " invalid segment id." ;
3623
+ }
3624
+ const Table::Segment& segment = wasm->table .segments [id];
3625
+ return segment.data .size ();
3626
+ }
3627
+
3628
+ const char *
3629
+ BinaryenGetFunctionTableSegmentEntry (BinaryenModuleRef module ,
3630
+ BinaryenIndex id,
3631
+ size_t entry) {
3632
+ if (tracing) {
3633
+ std::cout << " BinaryenGetFunctionTableSegmentEntry(the_module, " << id << " , "
3634
+ << entry << " );\n " ;
3635
+ }
3636
+
3637
+ auto * wasm = (Module*)module ;
3638
+ if (wasm->memory .segments .size () <= id) {
3639
+ Fatal () << " invalid segment id." ;
3640
+ }
3641
+ const Table::Segment& segment = wasm->table .segments [id];
3642
+ if (segment.data .size () <= entry) {
3643
+ Fatal () << " invalid segment entry index." ;
3644
+ }
3645
+ return segment.data [entry].c_str ();
3646
+ }
3647
+
3648
+
3649
+
3564
3650
// Memory. One per module
3565
3651
3566
3652
void BinaryenSetMemory (BinaryenModuleRef module ,
0 commit comments