@@ -226,6 +226,12 @@ BinaryenType BinaryenTypeNullExternref(void) {
226226BinaryenType BinaryenTypeNullFuncref (void ) {
227227 return Type (HeapType::nofunc, Nullable).getID ();
228228}
229+ BinaryenType BinaryenTypeExnref (void ) {
230+ return Type (HeapType::exn, Nullable).getID ();
231+ }
232+ BinaryenType BinaryenTypeNullExnref (void ) {
233+ return Type (HeapType::noexn, Nullable).getID ();
234+ }
229235BinaryenType BinaryenTypeUnreachable (void ) { return Type::unreachable; }
230236BinaryenType BinaryenTypeAuto (void ) { return uintptr_t (-1 ); }
231237
@@ -302,6 +308,12 @@ BinaryenHeapType BinaryenHeapTypeNoext() {
302308BinaryenHeapType BinaryenHeapTypeNofunc () {
303309 return static_cast <BinaryenHeapType>(HeapType::BasicHeapType::nofunc);
304310}
311+ BinaryenHeapType BinaryenHeapTypeExn () {
312+ return static_cast <BinaryenHeapType>(HeapType::BasicHeapType::exn);
313+ }
314+ BinaryenHeapType BinaryenHeapTypeNoexn () {
315+ return static_cast <BinaryenHeapType>(HeapType::BasicHeapType::noexn);
316+ }
305317
306318bool BinaryenHeapTypeIsBasic (BinaryenHeapType heapType) {
307319 return HeapType (heapType).isBasic ();
@@ -1780,6 +1792,28 @@ BinaryenExpressionRef BinaryenTry(BinaryenModuleRef module,
17801792 return static_cast <Expression*>(ret);
17811793}
17821794
1795+ BinaryenExpressionRef BinaryenTryTable (BinaryenModuleRef module ,
1796+ BinaryenExpressionRef body,
1797+ const char ** catchTags,
1798+ const char ** catchDests,
1799+ const bool * catchRefs,
1800+ BinaryenIndex numCatches) {
1801+ std::vector<Name> tags;
1802+ std::vector<Name> dests;
1803+ std::vector<bool > refs;
1804+ tags.reserve (numCatches);
1805+ dests.reserve (numCatches);
1806+ refs.reserve (numCatches);
1807+ for (BinaryenIndex i = 0 ; i < numCatches; i++) {
1808+ tags.push_back (catchTags[i] ? Name (catchTags[i]) : Name ());
1809+ dests.push_back (catchDests[i]);
1810+ refs.push_back (catchRefs[i]);
1811+ }
1812+ return static_cast <Expression*>(
1813+ Builder (*(Module*)module )
1814+ .makeTryTable ((Expression*)body, tags, dests, refs));
1815+ }
1816+
17831817BinaryenExpressionRef BinaryenThrow (BinaryenModuleRef module ,
17841818 const char * tag,
17851819 BinaryenExpressionRef* operands,
@@ -1798,6 +1832,12 @@ BinaryenExpressionRef BinaryenRethrow(BinaryenModuleRef module,
17981832 Builder (*(Module*)module ).makeRethrow (target));
17991833}
18001834
1835+ BinaryenExpressionRef BinaryenThrowRef (BinaryenModuleRef module ,
1836+ BinaryenExpressionRef exnref) {
1837+ return static_cast <Expression*>(
1838+ Builder (*(Module*)module ).makeThrowRef ((Expression*)exnref));
1839+ }
1840+
18011841BinaryenExpressionRef BinaryenRefI31 (BinaryenModuleRef module ,
18021842 BinaryenExpressionRef value) {
18031843 return static_cast <Expression*>(
@@ -4086,6 +4126,112 @@ bool BinaryenTryIsDelegate(BinaryenExpressionRef expr) {
40864126 assert (expression->is <Try>());
40874127 return static_cast <Try*>(expression)->isDelegate ();
40884128}
4129+ // TryTable
4130+ BinaryenExpressionRef BinaryenTryTableGetBody (BinaryenExpressionRef expr) {
4131+ auto * expression = (Expression*)expr;
4132+ assert (expression->is <TryTable>());
4133+ return static_cast <TryTable*>(expression)->body ;
4134+ }
4135+ void BinaryenTryTableSetBody (BinaryenExpressionRef expr,
4136+ BinaryenExpressionRef bodyExpr) {
4137+ auto * expression = (Expression*)expr;
4138+ assert (expression->is <TryTable>());
4139+ assert (bodyExpr);
4140+ static_cast <TryTable*>(expression)->body = (Expression*)bodyExpr;
4141+ }
4142+ BinaryenIndex BinaryenTryTableGetNumCatches (BinaryenExpressionRef expr) {
4143+ auto * expression = (Expression*)expr;
4144+ assert (expression->is <TryTable>());
4145+ return static_cast <TryTable*>(expression)->catchTags .size ();
4146+ }
4147+ const char * BinaryenTryTableGetCatchTagAt (BinaryenExpressionRef expr,
4148+ BinaryenIndex index) {
4149+ auto * expression = (Expression*)expr;
4150+ assert (expression->is <TryTable>());
4151+ assert (index < static_cast <TryTable*>(expression)->catchTags .size ());
4152+ auto name = static_cast <TryTable*>(expression)->catchTags [index];
4153+ return name.is () ? name.str .data () : nullptr ;
4154+ }
4155+ void BinaryenTryTableSetCatchTagAt (BinaryenExpressionRef expr,
4156+ BinaryenIndex index,
4157+ const char * catchTag) {
4158+ auto * expression = (Expression*)expr;
4159+ assert (expression->is <TryTable>());
4160+ assert (index < static_cast <TryTable*>(expression)->catchTags .size ());
4161+ static_cast <TryTable*>(expression)->catchTags [index] =
4162+ catchTag ? Name (catchTag) : Name ();
4163+ }
4164+ const char * BinaryenTryTableGetCatchDestAt (BinaryenExpressionRef expr,
4165+ BinaryenIndex index) {
4166+ auto * expression = (Expression*)expr;
4167+ assert (expression->is <TryTable>());
4168+ assert (index < static_cast <TryTable*>(expression)->catchDests .size ());
4169+ return static_cast <TryTable*>(expression)->catchDests [index].str .data ();
4170+ }
4171+ void BinaryenTryTableSetCatchDestAt (BinaryenExpressionRef expr,
4172+ BinaryenIndex index,
4173+ const char * catchDest) {
4174+ auto * expression = (Expression*)expr;
4175+ assert (expression->is <TryTable>());
4176+ assert (index < static_cast <TryTable*>(expression)->catchDests .size ());
4177+ static_cast <TryTable*>(expression)->catchDests [index] = catchDest;
4178+ }
4179+ bool BinaryenTryTableIsCatchRefAt (BinaryenExpressionRef expr,
4180+ BinaryenIndex index) {
4181+ auto * expression = (Expression*)expr;
4182+ assert (expression->is <TryTable>());
4183+ assert (index < static_cast <TryTable*>(expression)->catchRefs .size ());
4184+ return static_cast <TryTable*>(expression)->catchRefs [index];
4185+ }
4186+ void BinaryenTryTableSetCatchRefAt (BinaryenExpressionRef expr,
4187+ BinaryenIndex index,
4188+ bool catchRef) {
4189+ auto * expression = (Expression*)expr;
4190+ assert (expression->is <TryTable>());
4191+ assert (index < static_cast <TryTable*>(expression)->catchRefs .size ());
4192+ static_cast <TryTable*>(expression)->catchRefs [index] = catchRef;
4193+ }
4194+ BinaryenIndex BinaryenTryTableAppendCatch (BinaryenExpressionRef expr,
4195+ const char * catchTag,
4196+ const char * catchDest,
4197+ bool catchRef) {
4198+ auto * expression = (Expression*)expr;
4199+ assert (expression->is <TryTable>());
4200+ assert (catchDest);
4201+ auto * tryTable = static_cast <TryTable*>(expression);
4202+ auto index = tryTable->catchTags .size ();
4203+ tryTable->catchTags .push_back (catchTag ? Name (catchTag) : Name ());
4204+ tryTable->catchDests .push_back (Name (catchDest));
4205+ tryTable->catchRefs .push_back (catchRef);
4206+ return index;
4207+ }
4208+ void BinaryenTryTableInsertCatchAt (BinaryenExpressionRef expr,
4209+ BinaryenIndex index,
4210+ const char * catchTag,
4211+ const char * catchDest,
4212+ bool catchRef) {
4213+ auto * expression = (Expression*)expr;
4214+ assert (expression->is <TryTable>());
4215+ assert (catchDest);
4216+ auto * tryTable = static_cast <TryTable*>(expression);
4217+ tryTable->catchTags .insertAt (index, catchTag ? Name (catchTag) : Name ());
4218+ tryTable->catchDests .insertAt (index, Name (catchDest));
4219+ tryTable->catchRefs .insertAt (index, catchRef);
4220+ }
4221+ const char * BinaryenTryTableRemoveCatchAt (BinaryenExpressionRef expr,
4222+ BinaryenIndex index) {
4223+ auto * expression = (Expression*)expr;
4224+ assert (expression->is <TryTable>());
4225+ auto * tryTable = static_cast <TryTable*>(expression);
4226+ tryTable->catchTags .removeAt (index);
4227+ tryTable->catchRefs .removeAt (index);
4228+ return tryTable->catchDests .removeAt (index).str .data ();
4229+ }
4230+ bool BinaryenTryTableHasCatchAll (BinaryenExpressionRef expr) {
4231+ auto * expression = (Expression*)expr;
4232+ assert (expression->is <TryTable>());
4233+ return static_cast <TryTable*>(expression)->hasCatchAll ();
4234+ }
40894235// Throw
40904236const char * BinaryenThrowGetTag (BinaryenExpressionRef expr) {
40914237 auto * expression = (Expression*)expr;
@@ -4154,6 +4300,19 @@ void BinaryenRethrowSetTarget(BinaryenExpressionRef expr, const char* target) {
41544300 assert (expression->is <Rethrow>());
41554301 static_cast <Rethrow*>(expression)->target = target;
41564302}
4303+ // ThrowRef
4304+ BinaryenExpressionRef BinaryenThrowRefGetExnref (BinaryenExpressionRef expr) {
4305+ auto * expression = (Expression*)expr;
4306+ assert (expression->is <ThrowRef>());
4307+ return static_cast <ThrowRef*>(expression)->exnref ;
4308+ }
4309+ void BinaryenThrowRefSetExnref (BinaryenExpressionRef expr,
4310+ BinaryenExpressionRef exnrefExpr) {
4311+ auto * expression = (Expression*)expr;
4312+ assert (expression->is <ThrowRef>());
4313+ assert (exnrefExpr);
4314+ static_cast <ThrowRef*>(expression)->exnref = (Expression*)exnrefExpr;
4315+ }
41574316// TupleMake
41584317BinaryenIndex BinaryenTupleMakeGetNumOperands (BinaryenExpressionRef expr) {
41594318 auto * expression = (Expression*)expr;
0 commit comments