diff options
author | Thomas Lively <7121787+tlively@users.noreply.github.com> | 2019-11-22 12:46:04 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-22 12:46:04 -0800 |
commit | e2587f30827cd3d35dd409c2958b25a6c5517092 (patch) | |
tree | 22a372a3986cbfbc6db09df45bffe00631083f69 /src/js | |
parent | a0c423ef501ea7267c24c46e645296e713b2ea42 (diff) | |
download | binaryen-e2587f30827cd3d35dd409c2958b25a6c5517092.tar.gz binaryen-e2587f30827cd3d35dd409c2958b25a6c5517092.tar.bz2 binaryen-e2587f30827cd3d35dd409c2958b25a6c5517092.zip |
Multivalue type creation and inspection (#2459)
Adds the ability to create multivalue types from vectors of concrete value
types. All types are transparently interned, so their representation is still a
single uint32_t. Types can be extracted into vectors of their component parts,
and all the single value types expand into vectors containing themselves.
Multivalue types are not yet used in the IR, but their creation and inspection
functionality is exposed and tested in the C and JS APIs.
Also makes common type predicates methods of Type and improves the ergonomics of
type printing.
Diffstat (limited to 'src/js')
-rw-r--r-- | src/js/binaryen.js-post.js | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js index 37d2432cb..1f2c414e5 100644 --- a/src/js/binaryen.js-post.js +++ b/src/js/binaryen.js-post.js @@ -42,6 +42,26 @@ Module['exnref'] = Module['_BinaryenTypeExnref'](); Module['unreachable'] = Module['_BinaryenTypeUnreachable'](); Module['auto'] = /* deprecated */ Module['undefined'] = Module['_BinaryenTypeAuto'](); +Module['createType'] = function(types) { + return preserveStack(function() { + var array = i32sToStack(types); + return Module['_BinaryenTypeCreate'](array, types.length); + }); +}; + +Module['expandType'] = function(ty) { + return preserveStack(function() { + var numTypes = Module['_BinaryenTypeArity'](ty); + var array = stackAlloc(numTypes << 2); + Module['_BinaryenTypeExpand'](ty, array); + var types = []; + for (var i = 0; i < numTypes; i++) { + types.push(HEAPU32[(array >>> 2) + i]); + } + return types; + }); +}; + // Expression ids Module['InvalidId'] = Module['_BinaryenInvalidId'](); Module['BlockId'] = Module['_BinaryenBlockId'](); |