Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/passes/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3148,10 +3148,6 @@ void PrintSExpression::printMemoryHeader(Memory* curr) {
o << '(';
printMedium(o, "memory") << ' ';
printName(curr->name, o) << ' ';
if (curr->shared) {
o << '(';
printMedium(o, "shared ");
}
if (curr->is64()) {
o << "i64 ";
}
Expand All @@ -3160,7 +3156,7 @@ void PrintSExpression::printMemoryHeader(Memory* curr) {
o << ' ' << curr->max;
}
if (curr->shared) {
o << ")";
printMedium(o, " shared");
}
o << ")";
}
Expand Down
66 changes: 7 additions & 59 deletions src/wasm/wasm-s-parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3480,7 +3480,7 @@ Index SExpressionWasmBuilder::parseMemoryLimits(

void SExpressionWasmBuilder::parseMemory(Element& s, bool preParseImport) {
auto memory = std::make_unique<Memory>();
memory->shared = false;
memory->shared = *s[s.size() - 1] == SHARED;
Index i = 1;
if (s[i]->dollared()) {
memory->setExplicitName(s[i++]->str());
Expand All @@ -3507,10 +3507,6 @@ void SExpressionWasmBuilder::parseMemory(Element& s, bool preParseImport) {
memory->module = inner[1]->str();
memory->base = inner[2]->str();
i++;
} else if (elementStartsWith(inner, SHARED)) {
memory->shared = true;
parseMemoryLimits(inner, 1, memory);
i++;
} else {
if (!(inner.size() > 0 ? inner[0]->str() != IMPORT : true)) {
throw SParseException("bad import ending", inner);
Expand All @@ -3533,52 +3529,9 @@ void SExpressionWasmBuilder::parseMemory(Element& s, bool preParseImport) {
return;
}
}
if (!memory->shared) {
i = parseMemoryLimits(s, i, memory);
}

// Parse memory initializers.
while (i < s.size()) {
Element& curr = *s[i];
size_t j = 1;
Address offsetValue;
if (elementStartsWith(curr, DATA)) {
offsetValue = 0;
} else {
auto offsetElem = curr[j++];
offsetValue = getAddress(offsetElem);
if (!memory->is64()) {
checkAddress(offsetValue, "excessive memory offset", offsetElem);
}
}
std::string_view input = curr[j]->str().str;
auto* offset = allocator.alloc<Const>();
if (memory->is64()) {
offset->type = Type::i64;
offset->value = Literal(offsetValue);
} else {
offset->type = Type::i32;
offset->value = Literal(int32_t(offsetValue));
}
if (input.size()) {
std::vector<char> data;
stringToBinary(*curr[j], input, data);
auto segment = Builder::makeDataSegment(Name::fromInt(dataCounter++),
memory->name,
false,
offset,
data.data(),
data.size());
segment->hasExplicitName = false;
dataSegmentNames.push_back(segment->name);
wasm.addDataSegment(std::move(segment));
} else {
auto segment = Builder::makeDataSegment(
Name::fromInt(dataCounter++), memory->name, false, offset);
segment->hasExplicitName = false;
wasm.addDataSegment(std::move(segment));
}
i++;
i = parseMemoryLimits(s, i, memory);
if (i + int(memory->shared) != s.size()) {
throw SParseException("expected end of memory", *s[i]);
}
wasm.addMemory(std::move(memory));
}
Expand Down Expand Up @@ -3774,15 +3727,10 @@ void SExpressionWasmBuilder::parseImport(Element& s) {
memory->base = base;
memoryNames.push_back(name);

if (inner[j]->isList()) {
auto& limits = *inner[j];
if (!elementStartsWith(limits, SHARED)) {
throw SParseException("bad memory limit declaration", inner, *inner[j]);
}
j = parseMemoryLimits(inner, j, memory);
if (j != inner.size() && *inner[j] == SHARED) {
memory->shared = true;
j = parseMemoryLimits(limits, 1, memory);
} else {
j = parseMemoryLimits(inner, j, memory);
j++;
}

wasm.addMemory(std::move(memory));
Expand Down
2 changes: 1 addition & 1 deletion test/binaryen.js/atomics.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var wast = `
(module
(memory $0 (shared 1 1))
(memory $0 1 1 shared)
)
`;

Expand Down
2 changes: 1 addition & 1 deletion test/binaryen.js/atomics.js.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(module
(type $0 (func))
(memory $0 (shared 1 1))
(memory $0 1 1 shared)
(func $main
(i32.atomic.store
(i32.const 0)
Expand Down
4 changes: 2 additions & 2 deletions test/binaryen.js/kitchen-sink.js.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ getExpressionInfo(tuple[3])={"id":14,"type":5,"value":3.7}
(import "module" "base" (func $an-imported (type $2) (param i32 f64) (result f32)))
(import "module" "base" (tag $a-tag-imp (param i32)))
(global $a-global i32 (i32.const 1))
(memory $0 (shared 1 256))
(memory $0 1 256 shared)
(data $0 (i32.const 10) "hello, world")
(data $1 "I am passive")
(table $t0 1 funcref)
Expand Down Expand Up @@ -2243,7 +2243,7 @@ getExpressionInfo(tuple[3])={"id":14,"type":5,"value":3.7}
(import "module" "base" (func $an-imported (type $2) (param i32 f64) (result f32)))
(import "module" "base" (tag $a-tag-imp (param i32)))
(global $a-global i32 (i32.const 1))
(memory $0 (shared 1 256))
(memory $0 1 256 shared)
(data $0 (i32.const 10) "hello, world")
(data $1 "I am passive")
(table $t0 1 funcref)
Expand Down
2 changes: 1 addition & 1 deletion test/example/c-api-kitchen-sink.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ BinaryenFeatureAll: 131071
))
(global $i32Struct-global (mut (ref null $1)) (struct.new_default $1))
(global $string-global (mut stringref) (string.const ""))
(memory $0 (shared 1 256))
(memory $0 1 256 shared)
(data $0 (i32.const 10) "hello, world")
(data $1 "I am passive")
(table $tab 0 100 funcref)
Expand Down
6 changes: 3 additions & 3 deletions test/example/module-splitting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ int main() {
// Global stuff
do_test({}, R"(
(module
(memory $mem (shared 3 42))
(memory $mem 3 42 shared)
(table $tab 3 42 funcref)
(global $glob (mut i32) (i32.const 7))
(tag $e (param i32))
Expand All @@ -82,7 +82,7 @@ int main() {
// Imported global stuff
do_test({}, R"(
(module
(import "env" "mem" (memory $mem (shared 3 42)))
(import "env" "mem" (memory $mem 3 42 shared))
(import "env" "tab" (table $tab 3 42 funcref))
(import "env" "glob" (global $glob (mut i32)))
(import "env" "e" (tag $e (param i32)))
Expand All @@ -91,7 +91,7 @@ int main() {
// Exported global stuff
do_test({}, R"(
(module
(memory $mem (shared 3 42))
(memory $mem 3 42 shared)
(table $tab 3 42 funcref)
(global $glob (mut i32) (i32.const 7))
(tag $e (param i32))
Expand Down
18 changes: 9 additions & 9 deletions test/example/module-splitting.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Before:
(module
(type $0 (func (param i32)))
(global $glob (mut i32) (i32.const 7))
(memory $mem (shared 3 42))
(memory $mem 3 42 shared)
(table $tab 3 42 funcref)
(tag $e (param i32))
)
Expand All @@ -23,7 +23,7 @@ After:
(module
(type $0 (func (param i32)))
(global $glob (mut i32) (i32.const 7))
(memory $mem (shared 3 42))
(memory $mem 3 42 shared)
(table $tab 3 42 funcref)
(tag $e (param i32))
(export "%memory" (memory $mem))
Expand All @@ -34,7 +34,7 @@ After:
Secondary:
(module
(type $0 (func (param i32)))
(import "primary" "%memory" (memory $mem (shared 3 42)))
(import "primary" "%memory" (memory $mem 3 42 shared))
(import "primary" "%table" (table $tab 3 42 funcref))
(import "primary" "%global" (global $glob (mut i32)))
(import "primary" "%tag" (tag $e (param i32)))
Expand All @@ -44,7 +44,7 @@ Secondary:
Before:
(module
(type $0 (func (param i32)))
(import "env" "mem" (memory $mem (shared 3 42)))
(import "env" "mem" (memory $mem 3 42 shared))
(import "env" "tab" (table $tab 3 42 funcref))
(import "env" "glob" (global $glob (mut i32)))
(import "env" "e" (tag $e (param i32)))
Expand All @@ -53,7 +53,7 @@ Keeping: <none>
After:
(module
(type $0 (func (param i32)))
(import "env" "mem" (memory $mem (shared 3 42)))
(import "env" "mem" (memory $mem 3 42 shared))
(import "env" "tab" (table $tab 3 42 funcref))
(import "env" "glob" (global $glob (mut i32)))
(import "env" "e" (tag $e (param i32)))
Expand All @@ -65,7 +65,7 @@ After:
Secondary:
(module
(type $0 (func (param i32)))
(import "primary" "%memory" (memory $mem (shared 3 42)))
(import "primary" "%memory" (memory $mem 3 42 shared))
(import "primary" "%table" (table $tab 3 42 funcref))
(import "primary" "%global" (global $glob (mut i32)))
(import "primary" "%tag" (tag $e (param i32)))
Expand All @@ -76,7 +76,7 @@ Before:
(module
(type $0 (func (param i32)))
(global $glob (mut i32) (i32.const 7))
(memory $mem (shared 3 42))
(memory $mem 3 42 shared)
(table $tab 3 42 funcref)
(tag $e (param i32))
(export "mem" (memory $mem))
Expand All @@ -89,7 +89,7 @@ After:
(module
(type $0 (func (param i32)))
(global $glob (mut i32) (i32.const 7))
(memory $mem (shared 3 42))
(memory $mem 3 42 shared)
(table $tab 3 42 funcref)
(tag $e (param i32))
(export "mem" (memory $mem))
Expand All @@ -100,7 +100,7 @@ After:
Secondary:
(module
(type $0 (func (param i32)))
(import "primary" "mem" (memory $mem (shared 3 42)))
(import "primary" "mem" (memory $mem 3 42 shared))
(import "primary" "tab" (table $tab 3 42 funcref))
(import "primary" "glob" (global $glob (mut i32)))
(import "primary" "e" (tag $e (param i32)))
Expand Down
8 changes: 4 additions & 4 deletions test/lit/basic/atomics.wast
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
;; CHECK-BIN: (type $0 (func))
;; CHECK-BIN-NODEBUG: (type $0 (func))
(type $0 (func))
;; CHECK-TEXT: (memory $0 (shared 23 256))
;; CHECK-BIN: (memory $0 (shared 23 256))
;; CHECK-BIN-NODEBUG: (memory $0 (shared 23 256))
(memory $0 (shared 23 256))
;; CHECK-TEXT: (memory $0 23 256 shared)
;; CHECK-BIN: (memory $0 23 256 shared)
;; CHECK-BIN-NODEBUG: (memory $0 23 256 shared)
(memory $0 23 256 shared)

;; CHECK-TEXT: (func $atomic-loadstore (type $0)
;; CHECK-TEXT-NEXT: (local $0 i32)
Expand Down
8 changes: 4 additions & 4 deletions test/lit/basic/atomics64.wast
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
;; CHECK-BIN: (type $0 (func))
;; CHECK-BIN-NODEBUG: (type $0 (func))
(type $0 (func))
;; CHECK-TEXT: (memory $0 (shared i64 23 256))
;; CHECK-BIN: (memory $0 (shared i64 23 256))
;; CHECK-BIN-NODEBUG: (memory $0 (shared i64 23 256))
(memory $0 (shared i64 23 256))
;; CHECK-TEXT: (memory $0 i64 23 256 shared)
;; CHECK-BIN: (memory $0 i64 23 256 shared)
;; CHECK-BIN-NODEBUG: (memory $0 i64 23 256 shared)
(memory $0 i64 23 256 shared)

;; CHECK-TEXT: (func $atomic-loadstore (type $0)
;; CHECK-TEXT-NEXT: (local $0 i64)
Expand Down
8 changes: 4 additions & 4 deletions test/lit/basic/memory-shared.wast
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
;; RUN: cat %t.bin.nodebug.wast | filecheck %s --check-prefix=CHECK-BIN-NODEBUG

(module
;; CHECK-TEXT: (memory $0 (shared 23 256))
;; CHECK-BIN: (memory $0 (shared 23 256))
;; CHECK-BIN-NODEBUG: (memory $0 (shared 23 256))
(memory $0 (shared 23 256))
;; CHECK-TEXT: (memory $0 23 256 shared)
;; CHECK-BIN: (memory $0 23 256 shared)
;; CHECK-BIN-NODEBUG: (memory $0 23 256 shared)
(memory $0 23 256 shared)
)
24 changes: 12 additions & 12 deletions test/lit/basic/multi-memories-atomics64.wast
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
;; CHECK-BIN: (type $0 (func))
;; CHECK-BIN-NODEBUG: (type $0 (func))
(type $0 (func))
;; CHECK-TEXT: (memory $appMemory (shared i64 23 256))
;; CHECK-BIN: (memory $appMemory (shared i64 23 256))
(memory $appMemory (shared i64 23 256))
;; CHECK-TEXT: (memory $dataMemory (shared i64 23 256))
;; CHECK-BIN: (memory $dataMemory (shared i64 23 256))
(memory $dataMemory (shared i64 23 256))
;; CHECK-TEXT: (memory $instrumentMemory (shared i64 23 256))
;; CHECK-BIN: (memory $instrumentMemory (shared i64 23 256))
(memory $instrumentMemory (shared i64 23 256))
;; CHECK-TEXT: (memory $appMemory i64 23 256 shared)
;; CHECK-BIN: (memory $appMemory i64 23 256 shared)
(memory $appMemory i64 23 256 shared)
;; CHECK-TEXT: (memory $dataMemory i64 23 256 shared)
;; CHECK-BIN: (memory $dataMemory i64 23 256 shared)
(memory $dataMemory i64 23 256 shared)
;; CHECK-TEXT: (memory $instrumentMemory i64 23 256 shared)
;; CHECK-BIN: (memory $instrumentMemory i64 23 256 shared)
(memory $instrumentMemory i64 23 256 shared)

;; CHECK-TEXT: (func $atomic-loadstore (type $0)
;; CHECK-TEXT-NEXT: (local $0 i64)
Expand Down Expand Up @@ -1064,11 +1064,11 @@
(atomic.fence)
)
)
;; CHECK-BIN-NODEBUG: (memory $0 (shared i64 23 256))
;; CHECK-BIN-NODEBUG: (memory $0 i64 23 256 shared)

;; CHECK-BIN-NODEBUG: (memory $1 (shared i64 23 256))
;; CHECK-BIN-NODEBUG: (memory $1 i64 23 256 shared)

;; CHECK-BIN-NODEBUG: (memory $2 (shared i64 23 256))
;; CHECK-BIN-NODEBUG: (memory $2 i64 23 256 shared)

;; CHECK-BIN-NODEBUG: (func $0 (type $0)
;; CHECK-BIN-NODEBUG-NEXT: (local $0 i64)
Expand Down
Loading