diff options
author | KinderGartenKiller <33396195+mobsceneZ@users.noreply.github.com> | 2023-11-30 08:28:11 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-30 00:28:11 +0000 |
commit | 24742589f5471a5e72755d8fe1da9e49923a35ff (patch) | |
tree | 5f0bd747b252b687d637ae20b4596352bc58c3ad | |
parent | dbcac17d645d8ace8ae2cb69d6ba36b22d59b7cf (diff) | |
download | binaryen-24742589f5471a5e72755d8fe1da9e49923a35ff.tar.gz binaryen-24742589f5471a5e72755d8fe1da9e49923a35ff.tar.bz2 binaryen-24742589f5471a5e72755d8fe1da9e49923a35ff.zip |
C API: Add BinaryenTableGetType and BinaryenTableSetType (#6137)
Fixes #6136
-rw-r--r-- | src/binaryen-c.cpp | 6 | ||||
-rw-r--r-- | src/binaryen-c.h | 5 | ||||
-rw-r--r-- | test/example/c-api-multiple-tables.c | 5 |
3 files changed, 16 insertions, 0 deletions
diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp index 598156782..b53f5fd0c 100644 --- a/src/binaryen-c.cpp +++ b/src/binaryen-c.cpp @@ -5953,6 +5953,12 @@ BinaryenIndex BinaryenTableGetMax(BinaryenTableRef table) { void BinaryenTableSetMax(BinaryenTableRef table, BinaryenIndex max) { ((Table*)table)->max = max; } +BinaryenType BinaryenTableGetType(BinaryenTableRef table) { + return ((Table*)table)->type.getID(); +} +void BinaryenTableSetType(BinaryenTableRef table, BinaryenType tableType) { + ((Table*)table)->type = Type(tableType); +} // // =========== ElementSegment operations =========== diff --git a/src/binaryen-c.h b/src/binaryen-c.h index ee56afdad..82de2dae9 100644 --- a/src/binaryen-c.h +++ b/src/binaryen-c.h @@ -3258,6 +3258,11 @@ BINARYEN_API BinaryenIndex BinaryenTableGetMax(BinaryenTableRef table); // Sets the maximum number of pages of the specified `Table`. BINARYEN_API void BinaryenTableSetMax(BinaryenTableRef table, BinaryenIndex max); +// Gets the table type of the specified `Table`. +BINARYEN_API BinaryenType BinaryenTableGetType(BinaryenTableRef table); +// Sets the table type of the specified `Table`. +BINARYEN_API void BinaryenTableSetType(BinaryenTableRef table, + BinaryenType tableType); // // ========== Elem Segment Operations ========== diff --git a/test/example/c-api-multiple-tables.c b/test/example/c-api-multiple-tables.c index 7cd215bf9..4d1eefcfc 100644 --- a/test/example/c-api-multiple-tables.c +++ b/test/example/c-api-multiple-tables.c @@ -62,6 +62,11 @@ int main() { assert(BinaryenElementSegmentGetLength(elem1) == 1); assert(strcmp(BinaryenElementSegmentGetData(elem1, 0), funcNames[0]) == 0); + assert(BinaryenTableGetType(t2) == BinaryenTypeFuncref()); + BinaryenTableSetType(t2, BinaryenTypeExternref()); + assert(BinaryenTableGetType(t2) == BinaryenTypeExternref()); + BinaryenTableSetType(t2, BinaryenTypeFuncref()); + assert(strcmp(BinaryenTableGetName(t2), "t2") == 0); BinaryenTableSetName(t2, "table2"); BinaryenModuleUpdateMaps(module); |