Skip to content

Commit 941c555

Browse files
committed
Use the standard shared memory text format
Update the legacy text parser and all tests to use the standard text format for shared memories, e.g. `(memory $m 1 1 shared)` rather than `(memory $m (shared 1 1))`. Also remove support for non-standard in-line "data" or "segment" declarations. This change makes the tests more compatible with the new text parser, which only supports the standard format.
1 parent 78e7cf6 commit 941c555

File tree

61 files changed

+148
-347
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+148
-347
lines changed

src/passes/Print.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3148,10 +3148,6 @@ void PrintSExpression::printMemoryHeader(Memory* curr) {
31483148
o << '(';
31493149
printMedium(o, "memory") << ' ';
31503150
printName(curr->name, o) << ' ';
3151-
if (curr->shared) {
3152-
o << '(';
3153-
printMedium(o, "shared ");
3154-
}
31553151
if (curr->is64()) {
31563152
o << "i64 ";
31573153
}
@@ -3160,7 +3156,7 @@ void PrintSExpression::printMemoryHeader(Memory* curr) {
31603156
o << ' ' << curr->max;
31613157
}
31623158
if (curr->shared) {
3163-
o << ")";
3159+
printMedium(o, " shared");
31643160
}
31653161
o << ")";
31663162
}

src/wasm/wasm-s-parser.cpp

Lines changed: 7 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -3480,7 +3480,7 @@ Index SExpressionWasmBuilder::parseMemoryLimits(
34803480

34813481
void SExpressionWasmBuilder::parseMemory(Element& s, bool preParseImport) {
34823482
auto memory = std::make_unique<Memory>();
3483-
memory->shared = false;
3483+
memory->shared = *s[s.size() - 1] == SHARED;
34843484
Index i = 1;
34853485
if (s[i]->dollared()) {
34863486
memory->setExplicitName(s[i++]->str());
@@ -3507,10 +3507,6 @@ void SExpressionWasmBuilder::parseMemory(Element& s, bool preParseImport) {
35073507
memory->module = inner[1]->str();
35083508
memory->base = inner[2]->str();
35093509
i++;
3510-
} else if (elementStartsWith(inner, SHARED)) {
3511-
memory->shared = true;
3512-
parseMemoryLimits(inner, 1, memory);
3513-
i++;
35143510
} else {
35153511
if (!(inner.size() > 0 ? inner[0]->str() != IMPORT : true)) {
35163512
throw SParseException("bad import ending", inner);
@@ -3533,52 +3529,9 @@ void SExpressionWasmBuilder::parseMemory(Element& s, bool preParseImport) {
35333529
return;
35343530
}
35353531
}
3536-
if (!memory->shared) {
3537-
i = parseMemoryLimits(s, i, memory);
3538-
}
3539-
3540-
// Parse memory initializers.
3541-
while (i < s.size()) {
3542-
Element& curr = *s[i];
3543-
size_t j = 1;
3544-
Address offsetValue;
3545-
if (elementStartsWith(curr, DATA)) {
3546-
offsetValue = 0;
3547-
} else {
3548-
auto offsetElem = curr[j++];
3549-
offsetValue = getAddress(offsetElem);
3550-
if (!memory->is64()) {
3551-
checkAddress(offsetValue, "excessive memory offset", offsetElem);
3552-
}
3553-
}
3554-
std::string_view input = curr[j]->str().str;
3555-
auto* offset = allocator.alloc<Const>();
3556-
if (memory->is64()) {
3557-
offset->type = Type::i64;
3558-
offset->value = Literal(offsetValue);
3559-
} else {
3560-
offset->type = Type::i32;
3561-
offset->value = Literal(int32_t(offsetValue));
3562-
}
3563-
if (input.size()) {
3564-
std::vector<char> data;
3565-
stringToBinary(*curr[j], input, data);
3566-
auto segment = Builder::makeDataSegment(Name::fromInt(dataCounter++),
3567-
memory->name,
3568-
false,
3569-
offset,
3570-
data.data(),
3571-
data.size());
3572-
segment->hasExplicitName = false;
3573-
dataSegmentNames.push_back(segment->name);
3574-
wasm.addDataSegment(std::move(segment));
3575-
} else {
3576-
auto segment = Builder::makeDataSegment(
3577-
Name::fromInt(dataCounter++), memory->name, false, offset);
3578-
segment->hasExplicitName = false;
3579-
wasm.addDataSegment(std::move(segment));
3580-
}
3581-
i++;
3532+
i = parseMemoryLimits(s, i, memory);
3533+
if (i + int(memory->shared) != s.size()) {
3534+
throw SParseException("expected end of memory", *s[i]);
35823535
}
35833536
wasm.addMemory(std::move(memory));
35843537
}
@@ -3774,15 +3727,10 @@ void SExpressionWasmBuilder::parseImport(Element& s) {
37743727
memory->base = base;
37753728
memoryNames.push_back(name);
37763729

3777-
if (inner[j]->isList()) {
3778-
auto& limits = *inner[j];
3779-
if (!elementStartsWith(limits, SHARED)) {
3780-
throw SParseException("bad memory limit declaration", inner, *inner[j]);
3781-
}
3730+
j = parseMemoryLimits(inner, j, memory);
3731+
if (j != inner.size() && *inner[j] == SHARED) {
37823732
memory->shared = true;
3783-
j = parseMemoryLimits(limits, 1, memory);
3784-
} else {
3785-
j = parseMemoryLimits(inner, j, memory);
3733+
j++;
37863734
}
37873735

37883736
wasm.addMemory(std::move(memory));

test/example/c-api-kitchen-sink.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ BinaryenFeatureAll: 131071
8888
))
8989
(global $i32Struct-global (mut (ref null $1)) (struct.new_default $1))
9090
(global $string-global (mut stringref) (string.const ""))
91-
(memory $0 (shared 1 256))
91+
(memory $0 1 256 shared)
9292
(data $0 (i32.const 10) "hello, world")
9393
(data $1 "I am passive")
9494
(table $tab 0 100 funcref)

test/example/module-splitting.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ int main() {
7373
// Global stuff
7474
do_test({}, R"(
7575
(module
76-
(memory $mem (shared 3 42))
76+
(memory $mem 3 42 shared)
7777
(table $tab 3 42 funcref)
7878
(global $glob (mut i32) (i32.const 7))
7979
(tag $e (param i32))
@@ -82,7 +82,7 @@ int main() {
8282
// Imported global stuff
8383
do_test({}, R"(
8484
(module
85-
(import "env" "mem" (memory $mem (shared 3 42)))
85+
(import "env" "mem" (memory $mem 3 42 shared))
8686
(import "env" "tab" (table $tab 3 42 funcref))
8787
(import "env" "glob" (global $glob (mut i32)))
8888
(import "env" "e" (tag $e (param i32)))
@@ -91,7 +91,7 @@ int main() {
9191
// Exported global stuff
9292
do_test({}, R"(
9393
(module
94-
(memory $mem (shared 3 42))
94+
(memory $mem 3 42 shared)
9595
(table $tab 3 42 funcref)
9696
(global $glob (mut i32) (i32.const 7))
9797
(tag $e (param i32))

test/example/module-splitting.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Before:
1414
(module
1515
(type $0 (func (param i32)))
1616
(global $glob (mut i32) (i32.const 7))
17-
(memory $mem (shared 3 42))
17+
(memory $mem 3 42 shared)
1818
(table $tab 3 42 funcref)
1919
(tag $e (param i32))
2020
)
@@ -23,7 +23,7 @@ After:
2323
(module
2424
(type $0 (func (param i32)))
2525
(global $glob (mut i32) (i32.const 7))
26-
(memory $mem (shared 3 42))
26+
(memory $mem 3 42 shared)
2727
(table $tab 3 42 funcref)
2828
(tag $e (param i32))
2929
(export "%memory" (memory $mem))
@@ -34,7 +34,7 @@ After:
3434
Secondary:
3535
(module
3636
(type $0 (func (param i32)))
37-
(import "primary" "%memory" (memory $mem (shared 3 42)))
37+
(import "primary" "%memory" (memory $mem 3 42 shared))
3838
(import "primary" "%table" (table $tab 3 42 funcref))
3939
(import "primary" "%global" (global $glob (mut i32)))
4040
(import "primary" "%tag" (tag $e (param i32)))
@@ -44,7 +44,7 @@ Secondary:
4444
Before:
4545
(module
4646
(type $0 (func (param i32)))
47-
(import "env" "mem" (memory $mem (shared 3 42)))
47+
(import "env" "mem" (memory $mem 3 42 shared))
4848
(import "env" "tab" (table $tab 3 42 funcref))
4949
(import "env" "glob" (global $glob (mut i32)))
5050
(import "env" "e" (tag $e (param i32)))
@@ -53,7 +53,7 @@ Keeping: <none>
5353
After:
5454
(module
5555
(type $0 (func (param i32)))
56-
(import "env" "mem" (memory $mem (shared 3 42)))
56+
(import "env" "mem" (memory $mem 3 42 shared))
5757
(import "env" "tab" (table $tab 3 42 funcref))
5858
(import "env" "glob" (global $glob (mut i32)))
5959
(import "env" "e" (tag $e (param i32)))
@@ -65,7 +65,7 @@ After:
6565
Secondary:
6666
(module
6767
(type $0 (func (param i32)))
68-
(import "primary" "%memory" (memory $mem (shared 3 42)))
68+
(import "primary" "%memory" (memory $mem 3 42 shared))
6969
(import "primary" "%table" (table $tab 3 42 funcref))
7070
(import "primary" "%global" (global $glob (mut i32)))
7171
(import "primary" "%tag" (tag $e (param i32)))
@@ -76,7 +76,7 @@ Before:
7676
(module
7777
(type $0 (func (param i32)))
7878
(global $glob (mut i32) (i32.const 7))
79-
(memory $mem (shared 3 42))
79+
(memory $mem 3 42 shared)
8080
(table $tab 3 42 funcref)
8181
(tag $e (param i32))
8282
(export "mem" (memory $mem))
@@ -89,7 +89,7 @@ After:
8989
(module
9090
(type $0 (func (param i32)))
9191
(global $glob (mut i32) (i32.const 7))
92-
(memory $mem (shared 3 42))
92+
(memory $mem 3 42 shared)
9393
(table $tab 3 42 funcref)
9494
(tag $e (param i32))
9595
(export "mem" (memory $mem))
@@ -100,7 +100,7 @@ After:
100100
Secondary:
101101
(module
102102
(type $0 (func (param i32)))
103-
(import "primary" "mem" (memory $mem (shared 3 42)))
103+
(import "primary" "mem" (memory $mem 3 42 shared))
104104
(import "primary" "tab" (table $tab 3 42 funcref))
105105
(import "primary" "glob" (global $glob (mut i32)))
106106
(import "primary" "e" (tag $e (param i32)))

test/lit/basic/atomics.wast

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
;; CHECK-BIN: (type $0 (func))
1515
;; CHECK-BIN-NODEBUG: (type $0 (func))
1616
(type $0 (func))
17-
;; CHECK-TEXT: (memory $0 (shared 23 256))
18-
;; CHECK-BIN: (memory $0 (shared 23 256))
19-
;; CHECK-BIN-NODEBUG: (memory $0 (shared 23 256))
20-
(memory $0 (shared 23 256))
17+
;; CHECK-TEXT: (memory $0 23 256 shared)
18+
;; CHECK-BIN: (memory $0 23 256 shared)
19+
;; CHECK-BIN-NODEBUG: (memory $0 23 256 shared)
20+
(memory $0 23 256 shared)
2121

2222
;; CHECK-TEXT: (func $atomic-loadstore (type $0)
2323
;; CHECK-TEXT-NEXT: (local $0 i32)

test/lit/basic/atomics64.wast

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
;; CHECK-BIN: (type $0 (func))
1515
;; CHECK-BIN-NODEBUG: (type $0 (func))
1616
(type $0 (func))
17-
;; CHECK-TEXT: (memory $0 (shared i64 23 256))
18-
;; CHECK-BIN: (memory $0 (shared i64 23 256))
19-
;; CHECK-BIN-NODEBUG: (memory $0 (shared i64 23 256))
20-
(memory $0 (shared i64 23 256))
17+
;; CHECK-TEXT: (memory $0 i64 23 256 shared)
18+
;; CHECK-BIN: (memory $0 i64 23 256 shared)
19+
;; CHECK-BIN-NODEBUG: (memory $0 i64 23 256 shared)
20+
(memory $0 i64 23 256 shared)
2121

2222
;; CHECK-TEXT: (func $atomic-loadstore (type $0)
2323
;; CHECK-TEXT-NEXT: (local $0 i64)

test/lit/basic/memory-shared.wast

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
;; RUN: cat %t.bin.nodebug.wast | filecheck %s --check-prefix=CHECK-BIN-NODEBUG
1111

1212
(module
13-
;; CHECK-TEXT: (memory $0 (shared 23 256))
14-
;; CHECK-BIN: (memory $0 (shared 23 256))
15-
;; CHECK-BIN-NODEBUG: (memory $0 (shared 23 256))
16-
(memory $0 (shared 23 256))
13+
;; CHECK-TEXT: (memory $0 23 256 shared)
14+
;; CHECK-BIN: (memory $0 23 256 shared)
15+
;; CHECK-BIN-NODEBUG: (memory $0 23 256 shared)
16+
(memory $0 23 256 shared)
1717
)

test/lit/basic/multi-memories-atomics64.wast

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
;; CHECK-BIN: (type $0 (func))
1515
;; CHECK-BIN-NODEBUG: (type $0 (func))
1616
(type $0 (func))
17-
;; CHECK-TEXT: (memory $appMemory (shared i64 23 256))
18-
;; CHECK-BIN: (memory $appMemory (shared i64 23 256))
19-
(memory $appMemory (shared i64 23 256))
20-
;; CHECK-TEXT: (memory $dataMemory (shared i64 23 256))
21-
;; CHECK-BIN: (memory $dataMemory (shared i64 23 256))
22-
(memory $dataMemory (shared i64 23 256))
23-
;; CHECK-TEXT: (memory $instrumentMemory (shared i64 23 256))
24-
;; CHECK-BIN: (memory $instrumentMemory (shared i64 23 256))
25-
(memory $instrumentMemory (shared i64 23 256))
17+
;; CHECK-TEXT: (memory $appMemory i64 23 256 shared)
18+
;; CHECK-BIN: (memory $appMemory i64 23 256 shared)
19+
(memory $appMemory i64 23 256 shared)
20+
;; CHECK-TEXT: (memory $dataMemory i64 23 256 shared)
21+
;; CHECK-BIN: (memory $dataMemory i64 23 256 shared)
22+
(memory $dataMemory i64 23 256 shared)
23+
;; CHECK-TEXT: (memory $instrumentMemory i64 23 256 shared)
24+
;; CHECK-BIN: (memory $instrumentMemory i64 23 256 shared)
25+
(memory $instrumentMemory i64 23 256 shared)
2626

2727
;; CHECK-TEXT: (func $atomic-loadstore (type $0)
2828
;; CHECK-TEXT-NEXT: (local $0 i64)
@@ -1064,11 +1064,11 @@
10641064
(atomic.fence)
10651065
)
10661066
)
1067-
;; CHECK-BIN-NODEBUG: (memory $0 (shared i64 23 256))
1067+
;; CHECK-BIN-NODEBUG: (memory $0 i64 23 256 shared)
10681068

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

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

10731073
;; CHECK-BIN-NODEBUG: (func $0 (type $0)
10741074
;; CHECK-BIN-NODEBUG-NEXT: (local $0 i64)

0 commit comments

Comments
 (0)