1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-01 06:27:03 +03:00

Add sqlite3.wasm.irSizeof() and extend certain allocation functions to make use of it.

FossilOrigin-Name: 1cbc7b1875e8611b9db7a747b4c9499501450deaf90c929d212511837d6f72b6
This commit is contained in:
stephan
2022-12-25 20:05:11 +00:00
parent 031ee6b9da
commit 7d59d90a5b
4 changed files with 42 additions and 10 deletions

View File

@ -246,6 +246,25 @@ self.WhWasmUtilInstaller = function(target){
cache.utf8Decoder = new TextDecoder();
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.