diff options
author | stephan <stephan@noemail.net> | 2022-09-06 16:47:43 +0000 |
---|---|---|
committer | stephan <stephan@noemail.net> | 2022-09-06 16:47:43 +0000 |
commit | 100b496dd28f62ff12f650c0eaf4827674c5e537 (patch) | |
tree | 43f6968f74d56fb08610e213eaa58106eb5407dc /ext/wasm/common/whwasmutil.js | |
parent | 09aa80d109eba3e3317a6d844673e6a0bc64ca06 (diff) | |
download | sqlite-100b496dd28f62ff12f650c0eaf4827674c5e537.tar.gz sqlite-100b496dd28f62ff12f650c0eaf4827674c5e537.zip |
Initial build of speedtest1.wasm and speedtest1.html with which to run it.
FossilOrigin-Name: 4441535e3e54dc1881f700fa3878964eb8554a6790fd6aa32945f7cc104a8467
Diffstat (limited to 'ext/wasm/common/whwasmutil.js')
-rw-r--r-- | ext/wasm/common/whwasmutil.js | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/ext/wasm/common/whwasmutil.js b/ext/wasm/common/whwasmutil.js index 38adc76c2..f72fba72c 100644 --- a/ext/wasm/common/whwasmutil.js +++ b/ext/wasm/common/whwasmutil.js @@ -212,9 +212,10 @@ self.WhWasmUtilInstaller = function(target){ that will certainly change. */ const ptrIR = target.pointerIR || 'i32'; - const ptrSizeof = ('i32'===ptrIR ? 4 - : ('i64'===ptrIR - ? 8 : toss("Unhandled ptrSizeof:",ptrIR))); + const ptrSizeof = target.ptrSizeof = + ('i32'===ptrIR ? 4 + : ('i64'===ptrIR + ? 8 : toss("Unhandled ptrSizeof:",ptrIR))); /** Stores various cached state. */ const cache = Object.create(null); /** Previously-recorded size of cache.memory.buffer, noted so that @@ -1022,6 +1023,29 @@ self.WhWasmUtilInstaller = function(target){ target.scopedAlloc, 'scopedAllocCString()'); /** + Creates an array, using scopedAlloc(), suitable for passing to a + C-level main() routine. The input is a collection with a length + property and a forEach() method. A block of memory list.length + entries long is allocated and each pointer-sized block of that + memory is populated with a scopedAllocCString() conversion of the + (''+value) of each element. Returns a pointer to the start of the + list, suitable for passing as the 2nd argument to a C-style + main() function. + + Throws if list.length is falsy or scopedAllocPush() is not active. + */ + target.scopedAllocMainArgv = function(list){ + if(!list.length) toss("Cannot allocate empty array."); + const pList = target.scopedAlloc(list.length * target.ptrSizeof); + let i = 0; + list.forEach((e)=>{ + target.setPtrValue(pList + (target.ptrSizeof * i++), + target.scopedAllocCString(""+e)); + }); + return pList; + }; + + /** Wraps function call func() in a scopedAllocPush() and scopedAllocPop() block, such that all calls to scopedAlloc() and friends from within that call will have their memory freed |