aboutsummaryrefslogtreecommitdiff
path: root/ext/wasm/common/whwasmutil.js
diff options
context:
space:
mode:
authorstephan <stephan@noemail.net>2022-12-25 20:05:11 +0000
committerstephan <stephan@noemail.net>2022-12-25 20:05:11 +0000
commit7d59d90a5b9dc56f5a19fe9a24be2500af664013 (patch)
tree012546c07cac2f1922a5b20cdc9d13231c56abae /ext/wasm/common/whwasmutil.js
parent031ee6b9dabe7711c5ec7cfd91f7bef20cb7432e (diff)
downloadsqlite-7d59d90a5b9dc56f5a19fe9a24be2500af664013.tar.gz
sqlite-7d59d90a5b9dc56f5a19fe9a24be2500af664013.zip
Add sqlite3.wasm.irSizeof() and extend certain allocation functions to make use of it.
FossilOrigin-Name: 1cbc7b1875e8611b9db7a747b4c9499501450deaf90c929d212511837d6f72b6
Diffstat (limited to 'ext/wasm/common/whwasmutil.js')
-rw-r--r--ext/wasm/common/whwasmutil.js19
1 files changed, 19 insertions, 0 deletions
diff --git a/ext/wasm/common/whwasmutil.js b/ext/wasm/common/whwasmutil.js
index c296a946b..e6f32abfa 100644
--- a/ext/wasm/common/whwasmutil.js
+++ b/ext/wasm/common/whwasmutil.js
@@ -247,6 +247,25 @@ self.WhWasmUtilInstaller = function(target){
cache.utf8Encoder = new TextEncoder('utf-8');
/**
+ For the given IR-like string in the set ('i8', 'i16', 'i32',
+ 'f32', 'float', 'i64', 'f64', 'double', '*'), or any string value
+ ending in '*', returns the sizeof for that value
+ (target.ptrSizeof in the latter case). For any other value, it
+ returns the undefined value.
+ */
+ target.irSizeof = (n)=>{
+ switch(n){
+ case 'i8': return 1;
+ case 'i16': return 2;
+ case 'i32': case 'f32': case 'float': return 4;
+ case 'i64': case 'f64': case 'double': return 8;
+ case '*': return ptrSizeof;
+ default:
+ return (''+n).endsWith('*') ? ptrSizeof : undefined;
+ }
+ };
+
+ /**
If (cache.heapSize !== cache.memory.buffer.byteLength), i.e. if
the heap has grown since the last call, updates cache.HEAPxyz.
Returns the cache object.