summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Graey <maxgraey@gmail.com>2021-10-14 23:03:22 +0300
committerGitHub <noreply@github.com>2021-10-14 13:03:22 -0700
commit5dfff5cc2c75a6d2b6fde7f20f46ba169020b116 (patch)
tree9d2f6e54e7ba45155dbf462fe87e3ada7820f784
parent57e616595c158437b1739dbedb07c86c35d37b26 (diff)
downloadbinaryen-5dfff5cc2c75a6d2b6fde7f20f46ba169020b116.tar.gz
binaryen-5dfff5cc2c75a6d2b6fde7f20f46ba169020b116.tar.bz2
binaryen-5dfff5cc2c75a6d2b6fde7f20f46ba169020b116.zip
Refactor binaryen-c to use Builder when possible. NFC (#4247)
-rw-r--r--src/binaryen-c.cpp91
1 files changed, 32 insertions, 59 deletions
diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp
index 38367699d..eab435caa 100644
--- a/src/binaryen-c.cpp
+++ b/src/binaryen-c.cpp
@@ -787,12 +787,10 @@ BinaryenExpressionRef BinaryenIf(BinaryenModuleRef module,
BinaryenExpressionRef condition,
BinaryenExpressionRef ifTrue,
BinaryenExpressionRef ifFalse) {
- auto* ret = ((Module*)module)->allocator.alloc<If>();
- ret->condition = (Expression*)condition;
- ret->ifTrue = (Expression*)ifTrue;
- ret->ifFalse = (Expression*)ifFalse;
- ret->finalize();
- return static_cast<Expression*>(ret);
+ return static_cast<Expression*>(Builder(*(Module*)module)
+ .makeIf((Expression*)condition,
+ (Expression*)ifTrue,
+ (Expression*)ifFalse));
}
BinaryenExpressionRef BinaryenLoop(BinaryenModuleRef module,
const char* name,
@@ -902,50 +900,34 @@ BinaryenReturnCallIndirect(BinaryenModuleRef module,
BinaryenExpressionRef BinaryenLocalGet(BinaryenModuleRef module,
BinaryenIndex index,
BinaryenType type) {
- auto* ret = ((Module*)module)->allocator.alloc<LocalGet>();
- ret->index = index;
- ret->type = Type(type);
- ret->finalize();
- return static_cast<Expression*>(ret);
+ return static_cast<Expression*>(
+ Builder(*(Module*)module).makeLocalGet(index, Type(type)));
}
BinaryenExpressionRef BinaryenLocalSet(BinaryenModuleRef module,
BinaryenIndex index,
BinaryenExpressionRef value) {
- auto* ret = ((Module*)module)->allocator.alloc<LocalSet>();
- ret->index = index;
- ret->value = (Expression*)value;
- ret->makeSet();
- ret->finalize();
- return static_cast<Expression*>(ret);
+ return static_cast<Expression*>(
+ Builder(*(Module*)module).makeLocalSet(index, (Expression*)value));
}
BinaryenExpressionRef BinaryenLocalTee(BinaryenModuleRef module,
BinaryenIndex index,
BinaryenExpressionRef value,
BinaryenType type) {
- auto* ret = ((Module*)module)->allocator.alloc<LocalSet>();
- ret->index = index;
- ret->value = (Expression*)value;
- ret->makeTee(Type(type));
- ret->finalize();
- return static_cast<Expression*>(ret);
+ return static_cast<Expression*>(
+ Builder(*(Module*)module)
+ .makeLocalTee(index, (Expression*)value, Type(type)));
}
BinaryenExpressionRef BinaryenGlobalGet(BinaryenModuleRef module,
const char* name,
BinaryenType type) {
- auto* ret = ((Module*)module)->allocator.alloc<GlobalGet>();
- ret->name = name;
- ret->type = Type(type);
- ret->finalize();
- return static_cast<Expression*>(ret);
+ return static_cast<Expression*>(
+ Builder(*(Module*)module).makeGlobalGet(name, Type(type)));
}
BinaryenExpressionRef BinaryenGlobalSet(BinaryenModuleRef module,
const char* name,
BinaryenExpressionRef value) {
- auto* ret = ((Module*)module)->allocator.alloc<GlobalSet>();
- ret->name = name;
- ret->value = (Expression*)value;
- ret->finalize();
- return static_cast<Expression*>(ret);
+ return static_cast<Expression*>(
+ Builder(*(Module*)module).makeGlobalSet(name, (Expression*)value));
}
BinaryenExpressionRef BinaryenLoad(BinaryenModuleRef module,
uint32_t bytes,
@@ -954,16 +936,13 @@ BinaryenExpressionRef BinaryenLoad(BinaryenModuleRef module,
uint32_t align,
BinaryenType type,
BinaryenExpressionRef ptr) {
- auto* ret = ((Module*)module)->allocator.alloc<Load>();
- ret->isAtomic = false;
- ret->bytes = bytes;
- ret->signed_ = !!signed_;
- ret->offset = offset;
- ret->align = align ? align : bytes;
- ret->type = Type(type);
- ret->ptr = (Expression*)ptr;
- ret->finalize();
- return static_cast<Expression*>(ret);
+ return static_cast<Expression*>(Builder(*(Module*)module)
+ .makeLoad(bytes,
+ !!signed_,
+ offset,
+ align ? align : bytes,
+ (Expression*)ptr,
+ Type(type)));
}
BinaryenExpressionRef BinaryenStore(BinaryenModuleRef module,
uint32_t bytes,
@@ -972,16 +951,13 @@ BinaryenExpressionRef BinaryenStore(BinaryenModuleRef module,
BinaryenExpressionRef ptr,
BinaryenExpressionRef value,
BinaryenType type) {
- auto* ret = ((Module*)module)->allocator.alloc<Store>();
- ret->isAtomic = false;
- ret->bytes = bytes;
- ret->offset = offset;
- ret->align = align ? align : bytes;
- ret->ptr = (Expression*)ptr;
- ret->value = (Expression*)value;
- ret->valueType = Type(type);
- ret->finalize();
- return static_cast<Expression*>(ret);
+ return static_cast<Expression*>(Builder(*(Module*)module)
+ .makeStore(bytes,
+ offset,
+ align ? align : bytes,
+ (Expression*)ptr,
+ (Expression*)value,
+ Type(type)));
}
BinaryenExpressionRef BinaryenConst(BinaryenModuleRef module,
BinaryenLiteral value) {
@@ -1020,9 +996,7 @@ BinaryenExpressionRef BinaryenSelect(BinaryenModuleRef module,
}
BinaryenExpressionRef BinaryenDrop(BinaryenModuleRef module,
BinaryenExpressionRef value) {
- auto* ret = ((Module*)module)->allocator.alloc<Drop>();
- ret->value = (Expression*)value;
- ret->finalize();
+ auto* ret = Builder(*(Module*)module).makeDrop((Expression*)value);
return static_cast<Expression*>(ret);
}
BinaryenExpressionRef BinaryenReturn(BinaryenModuleRef module,
@@ -1040,11 +1014,10 @@ BinaryenExpressionRef BinaryenMemoryGrow(BinaryenModuleRef module,
return static_cast<Expression*>(ret);
}
BinaryenExpressionRef BinaryenNop(BinaryenModuleRef module) {
- return static_cast<Expression*>(((Module*)module)->allocator.alloc<Nop>());
+ return static_cast<Expression*>(Builder(*(Module*)module).makeNop());
}
BinaryenExpressionRef BinaryenUnreachable(BinaryenModuleRef module) {
- return static_cast<Expression*>(
- ((Module*)module)->allocator.alloc<Unreachable>());
+ return static_cast<Expression*>(Builder(*(Module*)module).makeUnreachable());
}
BinaryenExpressionRef BinaryenAtomicLoad(BinaryenModuleRef module,
uint32_t bytes,