From 721e8ffb975a6e68a56287cd46ecc19e107211c6 Mon Sep 17 00:00:00 2001 From: Jackson Gardner Date: Tue, 24 May 2022 09:59:47 -0700 Subject: Add C and JS API functions for accessing memory info (#4682) Based on #3573 plus minor fixes --- test/binaryen.js/memory-info.js | 35 +++++++++++++++++++++++++++++++++++ test/binaryen.js/memory-info.js.txt | 9 +++++++++ 2 files changed, 44 insertions(+) create mode 100644 test/binaryen.js/memory-info.js create mode 100644 test/binaryen.js/memory-info.js.txt (limited to 'test/binaryen.js') diff --git a/test/binaryen.js/memory-info.js b/test/binaryen.js/memory-info.js new file mode 100644 index 000000000..16ec86753 --- /dev/null +++ b/test/binaryen.js/memory-info.js @@ -0,0 +1,35 @@ +var module = new binaryen.Module(); +assert(module.validate()); +console.log(JSON.stringify(module.hasMemory())); + +var initial = 1, maximum = 64; + +// Not shared +module = new binaryen.Module(); +module.setMemory(initial, maximum, ''); +assert(module.validate()); +console.log(JSON.stringify(module.hasMemory())); +console.log(JSON.stringify(module.getMemoryInfo())); + +// Shared +module = new binaryen.Module(); +module.setFeatures(binaryen.Features.MVP | binaryen.Features.Atomics); +module.setMemory(initial, maximum, '', [], true); +assert(module.validate()); +console.log(JSON.stringify(module.hasMemory())); +console.log(JSON.stringify(module.getMemoryInfo())); + +// Imported, not shared +module = new binaryen.Module(); +module.addMemoryImport('my_mem', 'env', 'memory', false); +assert(module.validate()); +console.log(JSON.stringify(module.hasMemory())); +console.log(JSON.stringify(module.getMemoryInfo())); + +// Imported, shared +module = new binaryen.Module(); +module.setFeatures(binaryen.Features.MVP | binaryen.Features.Atomics); +module.addMemoryImport('my_mem', 'env', 'memory', true); +assert(module.validate()); +console.log(JSON.stringify(module.hasMemory())); +console.log(JSON.stringify(module.getMemoryInfo())); diff --git a/test/binaryen.js/memory-info.js.txt b/test/binaryen.js/memory-info.js.txt new file mode 100644 index 000000000..39d1290ae --- /dev/null +++ b/test/binaryen.js/memory-info.js.txt @@ -0,0 +1,9 @@ +false +true +{"module":"","base":"","initial":1,"shared":false,"max":64} +true +{"module":"","base":"","initial":1,"shared":true,"max":64} +false +{"module":"env","base":"memory","initial":0,"shared":false,"max":65536} +false +{"module":"env","base":"memory","initial":0,"shared":true,"max":65536} -- cgit v1.2.3