summaryrefslogtreecommitdiff
path: root/src/binaryen-c.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/binaryen-c.cpp')
-rw-r--r--src/binaryen-c.cpp63
1 files changed, 53 insertions, 10 deletions
diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp
index 83c626eb1..3ce24bdbd 100644
--- a/src/binaryen-c.cpp
+++ b/src/binaryen-c.cpp
@@ -338,16 +338,13 @@ BinaryenExpressionRef BinaryenIf(BinaryenModuleRef module, BinaryenExpressionRef
return static_cast<Expression*>(ret);
}
-BinaryenExpressionRef BinaryenLoop(BinaryenModuleRef module, const char* out, const char* in, BinaryenExpressionRef body) {
- if (out && !in) abort();
- auto* ret = Builder(*((Module*)module)).makeLoop(out ? Name(out) : Name(), in ? Name(in) : Name(), (Expression*)body);
+BinaryenExpressionRef BinaryenLoop(BinaryenModuleRef module, const char* name, BinaryenExpressionRef body) {
+ auto* ret = Builder(*((Module*)module)).makeLoop(name ? Name(name) : Name(), (Expression*)body);
if (tracing) {
auto id = noteExpression(ret);
std::cout << " expressions[" << id << "] = BinaryenLoop(the_module, ";
- traceNameOrNULL(out);
- std::cout << ", ";
- traceNameOrNULL(in);
+ traceNameOrNULL(name);
std::cout << ", expressions[" << expressions[body] << "]);\n";
}
@@ -488,6 +485,21 @@ BinaryenExpressionRef BinaryenSetLocal(BinaryenModuleRef module, BinaryenIndex i
ret->index = index;
ret->value = (Expression*)value;
+ ret->setTee(false);
+ ret->finalize();
+ return static_cast<Expression*>(ret);
+}
+BinaryenExpressionRef BinaryenTeeLocal(BinaryenModuleRef module, BinaryenIndex index, BinaryenExpressionRef value) {
+ auto* ret = ((Module*)module)->allocator.alloc<SetLocal>();
+
+ if (tracing) {
+ auto id = noteExpression(ret);
+ std::cout << " expressions[" << id << "] = BinaryenTeeLocal(the_module, " << index << ", expressions[" << expressions[value] << "]);\n";
+ }
+
+ ret->index = index;
+ ret->value = (Expression*)value;
+ ret->setTee(true);
ret->finalize();
return static_cast<Expression*>(ret);
}
@@ -508,12 +520,12 @@ BinaryenExpressionRef BinaryenLoad(BinaryenModuleRef module, uint32_t bytes, int
ret->finalize();
return static_cast<Expression*>(ret);
}
-BinaryenExpressionRef BinaryenStore(BinaryenModuleRef module, uint32_t bytes, uint32_t offset, uint32_t align, BinaryenExpressionRef ptr, BinaryenExpressionRef value) {
+BinaryenExpressionRef BinaryenStore(BinaryenModuleRef module, uint32_t bytes, uint32_t offset, uint32_t align, BinaryenExpressionRef ptr, BinaryenExpressionRef value, BinaryenType type) {
auto* ret = ((Module*)module)->allocator.alloc<Store>();
if (tracing) {
auto id = noteExpression(ret);
- std::cout << " expressions[" << id << "] = BinaryenStore(the_module, " << bytes << ", " << offset << ", " << align << ", expressions[" << expressions[ptr] << "], expressions[" << expressions[value] << "]);\n";
+ std::cout << " expressions[" << id << "] = BinaryenStore(the_module, " << bytes << ", " << offset << ", " << align << ", expressions[" << expressions[ptr] << "], expressions[" << expressions[value] << "], " << type << ");\n";
}
ret->bytes = bytes;
@@ -521,6 +533,7 @@ BinaryenExpressionRef BinaryenStore(BinaryenModuleRef module, uint32_t bytes, ui
ret->align = align ? align : bytes;
ret->ptr = (Expression*)ptr;
ret->value = (Expression*)value;
+ ret->valueType = WasmType(type);
ret->finalize();
return static_cast<Expression*>(ret);
}
@@ -584,6 +597,18 @@ BinaryenExpressionRef BinaryenSelect(BinaryenModuleRef module, BinaryenExpressio
ret->finalize();
return static_cast<Expression*>(ret);
}
+BinaryenExpressionRef BinaryenDrop(BinaryenModuleRef module, BinaryenExpressionRef value) {
+ auto* ret = ((Module*)module)->allocator.alloc<Drop>();
+
+ if (tracing) {
+ auto id = noteExpression(ret);
+ std::cout << " expressions[" << id << "] = BinaryenDrop(the_module, expressions[" << expressions[value] << "]);\n";
+ }
+
+ ret->value = (Expression*)value;
+ ret->finalize();
+ return static_cast<Expression*>(ret);
+}
BinaryenExpressionRef BinaryenReturn(BinaryenModuleRef module, BinaryenExpressionRef value) {
auto* ret = Builder(*((Module*)module)).makeReturn((Expression*)value);
@@ -692,7 +717,8 @@ BinaryenImportRef BinaryenAddImport(BinaryenModuleRef module, const char* intern
ret->name = internalName;
ret->module = externalModuleName;
ret->base = externalBaseName;
- ret->type = (FunctionType*)type;
+ ret->functionType = (FunctionType*)type;
+ ret->kind = Import::Function;
wasm->addImport(ret);
return ret;
}
@@ -780,7 +806,13 @@ void BinaryenSetMemory(BinaryenModuleRef module, BinaryenIndex initial, Binaryen
auto* wasm = (Module*)module;
wasm->memory.initial = initial;
wasm->memory.max = maximum;
- if (exportName) wasm->memory.exportName = exportName;
+ if (exportName) {
+ auto memoryExport = make_unique<Export>();
+ memoryExport->name = exportName;
+ memoryExport->value = Name::fromInt(0);
+ memoryExport->kind = Export::Memory;
+ wasm->addExport(memoryExport.release());
+ }
for (BinaryenIndex i = 0; i < numSegments; i++) {
wasm->memory.segments.emplace_back((Expression*)segmentOffsets[i], segments[i], segmentSizes[i]);
}
@@ -829,6 +861,17 @@ void BinaryenModuleOptimize(BinaryenModuleRef module) {
passRunner.run();
}
+void BinaryenModuleAutoDrop(BinaryenModuleRef module) {
+ if (tracing) {
+ std::cout << " BinaryenModuleAutoDrop(the_module);\n";
+ }
+
+ Module* wasm = (Module*)module;
+ PassRunner passRunner(wasm);
+ passRunner.add<AutoDrop>();
+ passRunner.run();
+}
+
size_t BinaryenModuleWrite(BinaryenModuleRef module, char* output, size_t outputSize) {
if (tracing) {
std::cout << " // BinaryenModuleWrite\n";