Skip to content

Commit f52475a

Browse files
committed
Update testsuite
Remove test/binary/bad-function-missing-end.txt which is now covered upstream: WebAssembly/spec#1405
1 parent 3cd653a commit f52475a

File tree

15 files changed

+342
-285
lines changed

15 files changed

+342
-285
lines changed

src/binary-reader-ir.cc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,12 @@ class BinaryReaderIR : public BinaryReaderNop {
203203
Result EndFunctionBody(Index index) override;
204204
Result OnSimdLaneOpExpr(Opcode opcode, uint64_t value) override;
205205
Result OnSimdLoadLaneExpr(Opcode opcode,
206+
Index memidx,
206207
Address alignment_log2,
207208
Address offset,
208209
uint64_t value) override;
209210
Result OnSimdStoreLaneExpr(Opcode opcode,
211+
Index memidx,
210212
Address alignment_log2,
211213
Address offset,
212214
uint64_t value) override;
@@ -1099,19 +1101,21 @@ Result BinaryReaderIR::OnSimdLaneOpExpr(Opcode opcode, uint64_t value) {
10991101
}
11001102

11011103
Result BinaryReaderIR::OnSimdLoadLaneExpr(Opcode opcode,
1104+
Index memidx,
11021105
Address alignment_log2,
11031106
Address offset,
11041107
uint64_t value) {
1105-
return AppendExpr(
1106-
MakeUnique<SimdLoadLaneExpr>(opcode, 1 << alignment_log2, offset, value));
1108+
return AppendExpr(MakeUnique<SimdLoadLaneExpr>(
1109+
opcode, Var(memidx), 1 << alignment_log2, offset, value));
11071110
}
11081111

11091112
Result BinaryReaderIR::OnSimdStoreLaneExpr(Opcode opcode,
1113+
Index memidx,
11101114
Address alignment_log2,
11111115
Address offset,
11121116
uint64_t value) {
1113-
return AppendExpr(MakeUnique<SimdStoreLaneExpr>(opcode, 1 << alignment_log2,
1114-
offset, value));
1117+
return AppendExpr(MakeUnique<SimdStoreLaneExpr>(
1118+
opcode, Var(memidx), 1 << alignment_log2, offset, value));
11151119
}
11161120

11171121
Result BinaryReaderIR::OnSimdShuffleOpExpr(Opcode opcode, v128 value) {

src/binary-reader-logging.cc

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -717,12 +717,15 @@ Result BinaryReaderLogging::OnComdatEntry(ComdatType kind, Index index) {
717717
}
718718

719719
#define DEFINE_SIMD_LOAD_STORE_LANE_OPCODE(name) \
720-
Result BinaryReaderLogging::name(Opcode opcode, Address alignment_log2, \
721-
Address offset, uint64_t value) { \
722-
LOGF(#name "(opcode: \"%s\" (%u), align log2: %" PRIaddress \
723-
", offset: %" PRIaddress ", lane: %" PRIu64 ")\n", \
724-
opcode.GetName(), opcode.GetCode(), alignment_log2, offset, value); \
725-
return reader_->name(opcode, alignment_log2, offset, value); \
720+
Result BinaryReaderLogging::name(Opcode opcode, Index memidx, \
721+
Address alignment_log2, Address offset, \
722+
uint64_t value) { \
723+
LOGF(#name "(opcode: \"%s\" (%u), memidx: %" PRIindex \
724+
", align log2: %" PRIaddress ", offset: %" PRIaddress \
725+
", lane: %" PRIu64 ")\n", \
726+
opcode.GetName(), opcode.GetCode(), memidx, alignment_log2, offset, \
727+
value); \
728+
return reader_->name(opcode, memidx, alignment_log2, offset, value); \
726729
}
727730

728731
#define DEFINE0(name) \

src/binary-reader-logging.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,12 @@ class BinaryReaderLogging : public BinaryReaderDelegate {
235235
Result EndCodeSection() override;
236236
Result OnSimdLaneOpExpr(Opcode opcode, uint64_t value) override;
237237
Result OnSimdLoadLaneExpr(Opcode opcode,
238+
Index memidx,
238239
Address alignment_log2,
239240
Address offset,
240241
uint64_t value) override;
241242
Result OnSimdStoreLaneExpr(Opcode opcode,
243+
Index memidx,
242244
Address alignment_log2,
243245
Address offset,
244246
uint64_t value) override;

src/binary-reader-nop.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,12 +315,14 @@ class BinaryReaderNop : public BinaryReaderDelegate {
315315
return Result::Ok;
316316
}
317317
Result OnSimdLoadLaneExpr(Opcode opcode,
318+
Index memidx,
318319
Address alignment_log2,
319320
Address offset,
320321
uint64_t value) override {
321322
return Result::Ok;
322323
}
323324
Result OnSimdStoreLaneExpr(Opcode opcode,
325+
Index memidx,
324326
Address alignment_log2,
325327
Address offset,
326328
uint64_t value) override {

src/binary-reader.cc

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,12 +1328,19 @@ Result BinaryReader::ReadInstructions(bool stop_on_end,
13281328
case Opcode::V128Load64Lane: {
13291329
Address alignment_log2;
13301330
CHECK_RESULT(ReadAlignment(&alignment_log2, "load alignment"));
1331+
Index memidx = 0;
1332+
if (alignment_log2 >> 6) {
1333+
ERROR_IF(!options_.features.multi_memory_enabled(),
1334+
"multi_memory not allowed");
1335+
CHECK_RESULT(ReadMemidx(&memidx, "store memidx"));
1336+
alignment_log2 = alignment_log2 & ((1 << 6) - 1);
1337+
}
13311338
Address offset;
13321339
CHECK_RESULT(ReadAddress(&offset, 0, "load offset"));
13331340
uint8_t lane_val;
13341341
CHECK_RESULT(ReadU8(&lane_val, "Lane idx"));
13351342

1336-
CALLBACK(OnSimdLoadLaneExpr, opcode, alignment_log2, offset, lane_val);
1343+
CALLBACK(OnSimdLoadLaneExpr, opcode, memidx, alignment_log2, offset, lane_val);
13371344
CALLBACK(OnOpcodeUint32Uint32Uint32, alignment_log2, offset, lane_val);
13381345
break;
13391346
}
@@ -1343,12 +1350,19 @@ Result BinaryReader::ReadInstructions(bool stop_on_end,
13431350
case Opcode::V128Store64Lane: {
13441351
Address alignment_log2;
13451352
CHECK_RESULT(ReadAlignment(&alignment_log2, "load alignment"));
1353+
Index memidx = 0;
1354+
if (alignment_log2 >> 6) {
1355+
ERROR_IF(!options_.features.multi_memory_enabled(),
1356+
"multi_memory not allowed");
1357+
CHECK_RESULT(ReadMemidx(&memidx, "store memidx"));
1358+
alignment_log2 = alignment_log2 & ((1 << 6) - 1);
1359+
}
13461360
Address offset;
13471361
CHECK_RESULT(ReadAddress(&offset, 0, "load offset"));
13481362
uint8_t lane_val;
13491363
CHECK_RESULT(ReadU8(&lane_val, "Lane idx"));
13501364

1351-
CALLBACK(OnSimdStoreLaneExpr, opcode, alignment_log2, offset, lane_val);
1365+
CALLBACK(OnSimdStoreLaneExpr, opcode, memidx, alignment_log2, offset, lane_val);
13521366
CALLBACK(OnOpcodeUint32Uint32Uint32, alignment_log2, offset, lane_val);
13531367
break;
13541368
}

src/binary-reader.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,12 @@ class BinaryReaderDelegate {
299299
virtual Result OnSimdLaneOpExpr(Opcode opcode, uint64_t value) = 0;
300300
virtual Result OnSimdShuffleOpExpr(Opcode opcode, v128 value) = 0;
301301
virtual Result OnSimdLoadLaneExpr(Opcode opcode,
302+
Index memidx,
302303
Address alignment_log2,
303304
Address offset,
304305
uint64_t value) = 0;
305306
virtual Result OnSimdStoreLaneExpr(Opcode opcode,
307+
Index memidx,
306308
Address alignment_log2,
307309
Address offset,
308310
uint64_t value) = 0;

src/interp/binary-reader-interp.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,12 @@ class BinaryReaderInterp : public BinaryReaderNop {
238238
Result EndFunctionBody(Index index) override;
239239
Result OnSimdLaneOpExpr(Opcode opcode, uint64_t value) override;
240240
Result OnSimdLoadLaneExpr(Opcode opcode,
241+
Index memidx,
241242
Address alignment_log2,
242243
Address offset,
243244
uint64_t value) override;
244245
Result OnSimdStoreLaneExpr(Opcode opcode,
246+
Index memidx,
245247
Address alignment_log2,
246248
Address offset,
247249
uint64_t value) override;
@@ -901,22 +903,24 @@ uint32_t GetAlignment(Address alignment_log2) {
901903
}
902904

903905
Result BinaryReaderInterp::OnSimdLoadLaneExpr(Opcode opcode,
906+
Index memidx,
904907
Address alignment_log2,
905908
Address offset,
906909
uint64_t value) {
907910
CHECK_RESULT(validator_.OnSimdLoadLane(GetLocation(), opcode,
908911
GetAlignment(alignment_log2), value));
909-
istream_.Emit(opcode, kMemoryIndex0, offset, static_cast<u8>(value));
912+
istream_.Emit(opcode, memidx, offset, static_cast<u8>(value));
910913
return Result::Ok;
911914
}
912915

913916
Result BinaryReaderInterp::OnSimdStoreLaneExpr(Opcode opcode,
917+
Index memidx,
914918
Address alignment_log2,
915919
Address offset,
916920
uint64_t value) {
917921
CHECK_RESULT(validator_.OnSimdStoreLane(GetLocation(), opcode,
918922
GetAlignment(alignment_log2), value));
919-
istream_.Emit(opcode, kMemoryIndex0, offset, static_cast<u8>(value));
923+
istream_.Emit(opcode, memidx, offset, static_cast<u8>(value));
920924
return Result::Ok;
921925
}
922926

src/ir.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -501,35 +501,41 @@ class SimdLaneOpExpr : public ExprMixin<ExprType::SimdLaneOp> {
501501
uint64_t val;
502502
};
503503

504-
class SimdLoadLaneExpr : public OpcodeExpr<ExprType::SimdLoadLane> {
504+
class SimdLoadLaneExpr : public MemoryExpr<ExprType::SimdLoadLane> {
505505
public:
506506
SimdLoadLaneExpr(Opcode opcode,
507+
Var memidx,
507508
Address align,
508509
Address offset,
509510
uint64_t val,
510511
const Location& loc = Location())
511-
: OpcodeExpr<ExprType::SimdLoadLane>(opcode, loc),
512+
: MemoryExpr<ExprType::SimdLoadLane>(memidx, loc),
513+
opcode(opcode),
512514
align(align),
513515
offset(offset),
514516
val(val) {}
515517

518+
Opcode opcode;
516519
Address align;
517520
Address offset;
518521
uint64_t val;
519522
};
520523

521-
class SimdStoreLaneExpr : public OpcodeExpr<ExprType::SimdStoreLane> {
524+
class SimdStoreLaneExpr : public MemoryExpr<ExprType::SimdStoreLane> {
522525
public:
523526
SimdStoreLaneExpr(Opcode opcode,
527+
Var memidx,
524528
Address align,
525529
Address offset,
526530
uint64_t val,
527531
const Location& loc = Location())
528-
: OpcodeExpr<ExprType::SimdStoreLane>(opcode, loc),
532+
: MemoryExpr<ExprType::SimdStoreLane>(memidx, loc),
533+
opcode(opcode),
529534
align(align),
530535
offset(offset),
531536
val(val) {}
532537

538+
Opcode opcode;
533539
Address align;
534540
Address offset;
535541
uint64_t val;

src/wast-parser.cc

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -583,8 +583,8 @@ TokenTypePair WastParser::PeekPair() {
583583
return TokenTypePair{{Peek(), Peek(1)}};
584584
}
585585

586-
bool WastParser::PeekMatch(TokenType type) {
587-
return Peek() == type;
586+
bool WastParser::PeekMatch(TokenType type, size_t n) {
587+
return Peek(n) == type;
588588
}
589589

590590
bool WastParser::PeekMatchLpar(TokenType type) {
@@ -1945,6 +1945,25 @@ Result WastParser::ParseSIMDLoadStoreInstr(Location loc,
19451945
std::unique_ptr<Expr>* out_expr) {
19461946
ErrorUnlessOpcodeEnabled(token);
19471947

1948+
Var memidx(0, loc);
1949+
1950+
if (options_->features.multi_memory_enabled()) {
1951+
// We have to be a little careful when reading the memeory index.
1952+
// If there is just a single integer folloing the instruction that
1953+
// represents the lane index, so we check for either a pair of intergers
1954+
// or an integers followed by offset= or align=.
1955+
bool try_read_mem_index = true;
1956+
if (PeekMatch(TokenType::Nat)) {
1957+
// The next token could be a memory index or a lane index
1958+
if (!PeekMatch(TokenType::OffsetEqNat, 1) &&
1959+
!PeekMatch(TokenType::AlignEqNat, 1) && !PeekMatch(TokenType::Nat, 1)) {
1960+
try_read_mem_index = false;
1961+
}
1962+
}
1963+
if (try_read_mem_index) {
1964+
CHECK_RESULT(ParseMemidx(loc, &memidx));
1965+
}
1966+
}
19481967
Address offset;
19491968
Address align;
19501969
ParseOffsetOpt(&offset);
@@ -1957,7 +1976,7 @@ Result WastParser::ParseSIMDLoadStoreInstr(Location loc,
19571976
return Result::Error;
19581977
}
19591978

1960-
out_expr->reset(new T(token.opcode(), align, offset, lane_idx, loc));
1979+
out_expr->reset(new T(token.opcode(), memidx, align, offset, lane_idx, loc));
19611980
return Result::Ok;
19621981
}
19631982

src/wast-parser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class WastParser {
8282
TokenTypePair PeekPair();
8383

8484
// Returns true if the next token's type is equal to the parameter.
85-
bool PeekMatch(TokenType);
85+
bool PeekMatch(TokenType, size_t n = 0);
8686

8787
// Returns true if the next token's type is '(' and the following token is
8888
// equal to the parameter.

0 commit comments

Comments
 (0)