summaryrefslogtreecommitdiff
path: root/src/wasm/wat-parser.cpp
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2023-05-04 16:44:09 -0700
committerGitHub <noreply@github.com>2023-05-04 16:44:09 -0700
commit7f8e4cbf6273c9b13b3a1a42f5e2833ea0d0f686 (patch)
treecc0343495b994c67a01b5143e6345d45a1c3587d /src/wasm/wat-parser.cpp
parent09fe432c0d3cb7562767a8e06d4e918beb5990c2 (diff)
downloadbinaryen-7f8e4cbf6273c9b13b3a1a42f5e2833ea0d0f686.tar.gz
binaryen-7f8e4cbf6273c9b13b3a1a42f5e2833ea0d0f686.tar.bz2
binaryen-7f8e4cbf6273c9b13b3a1a42f5e2833ea0d0f686.zip
[NFC] Refactor each of ArrayNewSeg and ArrayInit into subclasses for Data/Elem (#5692)
ArrayNewSeg => ArrayNewSegData, ArrayNewSegElem ArrayInit => ArrayInitData, ArrayInitElem Basically we remove the opcode and use the class type to differentiate them. This adds some code but it makes the representation simpler and more compact in memory, and it will help with #5690
Diffstat (limited to 'src/wasm/wat-parser.cpp')
-rw-r--r--src/wasm/wat-parser.cpp59
1 files changed, 41 insertions, 18 deletions
diff --git a/src/wasm/wat-parser.cpp b/src/wasm/wat-parser.cpp
index 51527b5e3..528d0d1af 100644
--- a/src/wasm/wat-parser.cpp
+++ b/src/wasm/wat-parser.cpp
@@ -789,6 +789,10 @@ struct NullInstrParserCtx {
InstrT makeArrayNewData(Index, HeapTypeT, DataIdxT) {
return Ok{};
}
+ template<typename HeapTypeT>
+ InstrT makeArrayNewElem(Index, HeapTypeT, DataIdxT) {
+ return Ok{};
+ }
template<typename HeapTypeT> InstrT makeArrayGet(Index, HeapTypeT, bool) {
return Ok{};
}
@@ -2156,8 +2160,18 @@ struct ParseDefsCtx : TypeParserCtx<ParseDefsCtx> {
CHECK_ERR(size);
auto offset = pop(pos);
CHECK_ERR(offset);
- return push(pos,
- builder.makeArrayNewSeg(NewData, type, data, *offset, *size));
+ return push(pos, builder.makeArrayNewData(type, data, *offset, *size));
+ }
+
+ Result<> makeArrayNewElem(Index pos, HeapType type, Name data) {
+ if (!type.isArray()) {
+ return in.err(pos, "expected array type annotation");
+ }
+ auto size = pop(pos);
+ CHECK_ERR(size);
+ auto offset = pop(pos);
+ CHECK_ERR(offset);
+ return push(pos, builder.makeArrayNewElem(type, data, *offset, *size));
}
Result<> makeArrayGet(Index pos, HeapType type, bool signed_) {
@@ -2380,7 +2394,9 @@ template<typename Ctx> Result<typename Ctx::InstrT> makeStructSet(Ctx&, Index);
template<typename Ctx>
Result<typename Ctx::InstrT> makeArrayNew(Ctx&, Index, bool default_);
template<typename Ctx>
-Result<typename Ctx::InstrT> makeArrayNewSeg(Ctx&, Index, ArrayNewSegOp op);
+Result<typename Ctx::InstrT> makeArrayNewData(Ctx&, Index);
+template<typename Ctx>
+Result<typename Ctx::InstrT> makeArrayNewElem(Ctx&, Index);
template<typename Ctx>
Result<typename Ctx::InstrT> makeArrayNewFixed(Ctx&, Index);
template<typename Ctx>
@@ -2390,7 +2406,9 @@ template<typename Ctx> Result<typename Ctx::InstrT> makeArrayLen(Ctx&, Index);
template<typename Ctx> Result<typename Ctx::InstrT> makeArrayCopy(Ctx&, Index);
template<typename Ctx> Result<typename Ctx::InstrT> makeArrayFill(Ctx&, Index);
template<typename Ctx>
-Result<typename Ctx::InstrT> makeArrayInit(Ctx&, Index, ArrayInitOp);
+Result<typename Ctx::InstrT> makeArrayInitData(Ctx&, Index);
+template<typename Ctx>
+Result<typename Ctx::InstrT> makeArrayInitElem(Ctx&, Index);
template<typename Ctx>
Result<typename Ctx::InstrT> makeRefAs(Ctx&, Index, RefAsOp op);
template<typename Ctx>
@@ -3528,20 +3546,21 @@ Result<typename Ctx::InstrT> makeArrayNew(Ctx& ctx, Index pos, bool default_) {
}
template<typename Ctx>
-Result<typename Ctx::InstrT>
-makeArrayNewSeg(Ctx& ctx, Index pos, ArrayNewSegOp op) {
+Result<typename Ctx::InstrT> makeArrayNewData(Ctx& ctx, Index pos) {
auto type = typeidx(ctx);
CHECK_ERR(type);
- switch (op) {
- case NewData: {
- auto data = dataidx(ctx);
- CHECK_ERR(data);
- return ctx.makeArrayNewData(pos, *type, *data);
- }
- case NewElem:
- return ctx.in.err("unimplemented instruction");
- }
- WASM_UNREACHABLE("unexpected op");
+ auto data = dataidx(ctx);
+ CHECK_ERR(data);
+ return ctx.makeArrayNewData(pos, *type, *data);
+}
+
+template<typename Ctx>
+Result<typename Ctx::InstrT> makeArrayNewElem(Ctx& ctx, Index pos) {
+ auto type = typeidx(ctx);
+ CHECK_ERR(type);
+ auto data = dataidx(ctx);
+ CHECK_ERR(data);
+ return ctx.makeArrayNewElem(pos, *type, *data);
}
template<typename Ctx>
@@ -3585,8 +3604,12 @@ Result<typename Ctx::InstrT> makeArrayFill(Ctx& ctx, Index pos) {
}
template<typename Ctx>
-Result<typename Ctx::InstrT>
-makeArrayInit(Ctx& ctx, Index pos, ArrayInitOp op) {
+Result<typename Ctx::InstrT> makeArrayInitData(Ctx& ctx, Index pos) {
+ return ctx.in.err("unimplemented instruction");
+}
+
+template<typename Ctx>
+Result<typename Ctx::InstrT> makeArrayInitElem(Ctx& ctx, Index pos) {
return ctx.in.err("unimplemented instruction");
}