summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMax Graey <maxgraey@gmail.com>2022-09-12 22:36:56 +0300
committerGitHub <noreply@github.com>2022-09-12 12:36:56 -0700
commitaa36fc4f67cf38f097b4c2b4db53b718880f9c3a (patch)
treead056acbe1e294ae49f8aebc22bac97f2f4da829 /src
parent73b562e24e958e6d5c15aa96ddf4b2e8f31162f8 (diff)
downloadbinaryen-aa36fc4f67cf38f097b4c2b4db53b718880f9c3a.tar.gz
binaryen-aa36fc4f67cf38f097b4c2b4db53b718880f9c3a.tar.bz2
binaryen-aa36fc4f67cf38f097b4c2b4db53b718880f9c3a.zip
[C-/JS-API] Add new BinaryenMemoryIs64 API + add memory64 argument for BinaryenSetMemory (#4963)
Diffstat (limited to 'src')
-rw-r--r--src/binaryen-c.cpp13
-rw-r--r--src/binaryen-c.h3
-rw-r--r--src/js/binaryen.js-post.js6
3 files changed, 20 insertions, 2 deletions
diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp
index 914e37695..50e2e9a3c 100644
--- a/src/binaryen-c.cpp
+++ b/src/binaryen-c.cpp
@@ -4242,12 +4242,14 @@ void BinaryenSetMemory(BinaryenModuleRef module,
BinaryenIndex* segmentSizes,
BinaryenIndex numSegments,
bool shared,
+ bool memory64,
const char* name) {
auto memory = std::make_unique<Memory>();
memory->name = name ? name : "0";
memory->initial = initial;
memory->max = int32_t(maximum); // Make sure -1 extends.
memory->shared = shared;
+ memory->indexType = memory64 ? Type::i64 : Type::i32;
if (exportName) {
auto memoryExport = make_unique<Export>();
memoryExport->name = exportName;
@@ -4389,6 +4391,17 @@ bool BinaryenMemoryIsShared(BinaryenModuleRef module, const char* name) {
}
return memory->shared;
}
+bool BinaryenMemoryIs64(BinaryenModuleRef module, const char* name) {
+ // Maintaining compatibility for instructions with a single memory
+ if (name == nullptr && module->memories.size() == 1) {
+ name = module->memories[0]->name.c_str();
+ }
+ auto* memory = ((Module*)module)->getMemoryOrNull(name);
+ if (memory == nullptr) {
+ Fatal() << "invalid memory '" << name << "'.";
+ }
+ return memory->is64();
+}
size_t BinaryenGetMemorySegmentByteLength(BinaryenModuleRef module,
BinaryenIndex id) {
const auto& segments = ((Module*)module)->dataSegments;
diff --git a/src/binaryen-c.h b/src/binaryen-c.h
index 4e37b177a..d7555fc57 100644
--- a/src/binaryen-c.h
+++ b/src/binaryen-c.h
@@ -2485,6 +2485,7 @@ BINARYEN_API void BinaryenSetMemory(BinaryenModuleRef module,
BinaryenIndex* segmentSizes,
BinaryenIndex numSegments,
bool shared,
+ bool memory64,
const char* name);
BINARYEN_API bool BinaryenHasMemory(BinaryenModuleRef module);
@@ -2500,6 +2501,8 @@ BINARYEN_API const char* BinaryenMemoryImportGetBase(BinaryenModuleRef module,
const char* name);
BINARYEN_API bool BinaryenMemoryIsShared(BinaryenModuleRef module,
const char* name);
+BINARYEN_API bool BinaryenMemoryIs64(BinaryenModuleRef module,
+ const char* name);
// Memory segments. Query utilities.
diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js
index 158e3f29b..5634a8b9e 100644
--- a/src/js/binaryen.js-post.js
+++ b/src/js/binaryen.js-post.js
@@ -2566,7 +2566,7 @@ function wrapModule(module, self = {}) {
self['removeExport'] = function(externalName) {
return preserveStack(() => Module['_BinaryenRemoveExport'](module, strToStack(externalName)));
};
- self['setMemory'] = function(initial, maximum, exportName, segments = [], shared = false, internalName) {
+ self['setMemory'] = function(initial, maximum, exportName, segments = [], shared = false, memory64 = false, internalName) {
// segments are assumed to be { passive: bool, offset: expression ref, data: array of 8-bit data }
return preserveStack(() => {
const segmentsLen = segments.length;
@@ -2590,6 +2590,7 @@ function wrapModule(module, self = {}) {
i32sToStack(segmentDataLen),
segmentsLen,
shared,
+ memory64,
strToStack(internalName)
);
});
@@ -2602,7 +2603,8 @@ function wrapModule(module, self = {}) {
'module': UTF8ToString(Module['_BinaryenMemoryImportGetModule'](module, strToStack(name))),
'base': UTF8ToString(Module['_BinaryenMemoryImportGetBase'](module, strToStack(name))),
'initial': Module['_BinaryenMemoryGetInitial'](module, strToStack(name)),
- 'shared': Boolean(Module['_BinaryenMemoryIsShared'](module, strToStack(name)))
+ 'shared': Boolean(Module['_BinaryenMemoryIsShared'](module, strToStack(name))),
+ 'is64': Boolean(Module['_BinaryenMemoryIs64'](module, strToStack(name))),
};
if (Module['_BinaryenMemoryHasMax'](module, strToStack(name))) {
memoryInfo['max'] = Module['_BinaryenMemoryGetMax'](module, strToStack(name));