Upgrade V8 to 5.1.281.57 DO NOT MERGE
FPIIM-449
Change-Id: Id981b686b4d587ac31697662eb98bb34be42ad90
(cherry picked from commit 3b9bc31999c9787eb726ecdbfd5796bfdec32a18)
diff --git a/test/unittests/compiler/graph-unittest.h b/test/unittests/compiler/graph-unittest.h
index 9c99992..31bae6d 100644
--- a/test/unittests/compiler/graph-unittest.h
+++ b/test/unittests/compiler/graph-unittest.h
@@ -29,7 +29,6 @@
explicit GraphTest(int num_parameters = 1);
~GraphTest() override;
- protected:
Node* start() { return graph()->start(); }
Node* end() { return graph()->end(); }
diff --git a/test/unittests/compiler/int64-lowering-unittest.cc b/test/unittests/compiler/int64-lowering-unittest.cc
index eff6d4a..08f3038 100644
--- a/test/unittests/compiler/int64-lowering-unittest.cc
+++ b/test/unittests/compiler/int64-lowering-unittest.cc
@@ -28,7 +28,10 @@
class Int64LoweringTest : public GraphTest {
public:
- Int64LoweringTest() : GraphTest(), machine_(zone()) {
+ Int64LoweringTest()
+ : GraphTest(),
+ machine_(zone(), MachineRepresentation::kWord32,
+ MachineOperatorBuilder::Flag::kAllOptionalOps) {
value_[0] = 0x1234567890abcdef;
value_[1] = 0x1edcba098765432f;
value_[2] = 0x1133557799886644;
@@ -86,14 +89,34 @@
return static_cast<int32_t>(value_[i] >> 32);
}
+ void TestComparison(
+ const Operator* op,
+ Matcher<Node*> (*high_word_matcher)(const Matcher<Node*>& lhs_matcher,
+ const Matcher<Node*>& rhs_matcher),
+ Matcher<Node*> (*low_word_matcher)(const Matcher<Node*>& lhs_matcher,
+ const Matcher<Node*>& rhs_matcher)) {
+ LowerGraph(
+ graph()->NewNode(op, Int64Constant(value(0)), Int64Constant(value(1))),
+ MachineRepresentation::kWord32);
+ EXPECT_THAT(
+ graph()->end()->InputAt(1),
+ IsReturn(IsWord32Or(
+ high_word_matcher(IsInt32Constant(high_word_value(0)),
+ IsInt32Constant(high_word_value(1))),
+ IsWord32And(
+ IsWord32Equal(IsInt32Constant(high_word_value(0)),
+ IsInt32Constant(high_word_value(1))),
+ low_word_matcher(IsInt32Constant(low_word_value(0)),
+ IsInt32Constant(low_word_value(1))))),
+ start(), start()));
+ }
+
private:
MachineOperatorBuilder machine_;
int64_t value_[3];
};
TEST_F(Int64LoweringTest, Int64Constant) {
- if (4 != kPointerSize) return;
-
LowerGraph(Int64Constant(value(0)), MachineRepresentation::kWord64);
EXPECT_THAT(graph()->end()->InputAt(1),
IsReturn2(IsInt32Constant(low_word_value(0)),
@@ -101,8 +124,6 @@
}
TEST_F(Int64LoweringTest, Int64Load) {
- if (4 != kPointerSize) return;
-
int32_t base = 0x1234;
int32_t index = 0x5678;
@@ -128,8 +149,6 @@
}
TEST_F(Int64LoweringTest, Int64Store) {
- if (4 != kPointerSize) return;
-
// We have to build the TF graph explicitly here because Store does not return
// a value.
@@ -173,8 +192,6 @@
}
TEST_F(Int64LoweringTest, Int64And) {
- if (4 != kPointerSize) return;
-
LowerGraph(graph()->NewNode(machine()->Word64And(), Int64Constant(value(0)),
Int64Constant(value(1))),
MachineRepresentation::kWord64);
@@ -187,8 +204,6 @@
}
TEST_F(Int64LoweringTest, TruncateInt64ToInt32) {
- if (4 != kPointerSize) return;
-
LowerGraph(graph()->NewNode(machine()->TruncateInt64ToInt32(),
Int64Constant(value(0))),
MachineRepresentation::kWord32);
@@ -197,8 +212,6 @@
}
TEST_F(Int64LoweringTest, Parameter) {
- if (4 != kPointerSize) return;
-
LowerGraph(Parameter(0), MachineRepresentation::kWord64,
MachineRepresentation::kWord64, 1);
@@ -207,8 +220,6 @@
}
TEST_F(Int64LoweringTest, Parameter2) {
- if (4 != kPointerSize) return;
-
Signature<MachineRepresentation>::Builder sig_builder(zone(), 1, 5);
sig_builder.AddReturn(MachineRepresentation::kWord32);
@@ -229,8 +240,6 @@
}
TEST_F(Int64LoweringTest, CallI64Return) {
- if (4 != kPointerSize) return;
-
int32_t function = 0x9999;
Signature<MachineRepresentation>::Builder sig_builder(zone(), 1, 0);
@@ -259,8 +268,6 @@
}
TEST_F(Int64LoweringTest, CallI64Parameter) {
- if (4 != kPointerSize) return;
-
int32_t function = 0x9999;
Signature<MachineRepresentation>::Builder sig_builder(zone(), 1, 3);
@@ -294,6 +301,505 @@
wasm::ModuleEnv::GetI32WasmCallDescriptor(zone(), desc));
}
+// todo(ahaas): I added a list of missing instructions here to make merging
+// easier when I do them one by one.
+// kExprI64Add:
+TEST_F(Int64LoweringTest, Int64Add) {
+ LowerGraph(graph()->NewNode(machine()->Int64Add(), Int64Constant(value(0)),
+ Int64Constant(value(1))),
+ MachineRepresentation::kWord64);
+
+ Capture<Node*> add;
+ Matcher<Node*> add_matcher = IsInt32PairAdd(
+ IsInt32Constant(low_word_value(0)), IsInt32Constant(high_word_value(0)),
+ IsInt32Constant(low_word_value(1)), IsInt32Constant(high_word_value(1)));
+
+ EXPECT_THAT(graph()->end()->InputAt(1),
+ IsReturn2(IsProjection(0, AllOf(CaptureEq(&add), add_matcher)),
+ IsProjection(1, AllOf(CaptureEq(&add), add_matcher)),
+ start(), start()));
+}
+// kExprI64Sub:
+TEST_F(Int64LoweringTest, Int64Sub) {
+ LowerGraph(graph()->NewNode(machine()->Int64Sub(), Int64Constant(value(0)),
+ Int64Constant(value(1))),
+ MachineRepresentation::kWord64);
+
+ Capture<Node*> sub;
+ Matcher<Node*> sub_matcher = IsInt32PairSub(
+ IsInt32Constant(low_word_value(0)), IsInt32Constant(high_word_value(0)),
+ IsInt32Constant(low_word_value(1)), IsInt32Constant(high_word_value(1)));
+
+ EXPECT_THAT(graph()->end()->InputAt(1),
+ IsReturn2(IsProjection(0, AllOf(CaptureEq(&sub), sub_matcher)),
+ IsProjection(1, AllOf(CaptureEq(&sub), sub_matcher)),
+ start(), start()));
+}
+
+// kExprI64Mul:
+TEST_F(Int64LoweringTest, Int64Mul) {
+ LowerGraph(graph()->NewNode(machine()->Int64Mul(), Int64Constant(value(0)),
+ Int64Constant(value(1))),
+ MachineRepresentation::kWord64);
+
+ Capture<Node*> mul_capture;
+ Matcher<Node*> mul_matcher = IsInt32PairMul(
+ IsInt32Constant(low_word_value(0)), IsInt32Constant(high_word_value(0)),
+ IsInt32Constant(low_word_value(1)), IsInt32Constant(high_word_value(1)));
+
+ EXPECT_THAT(
+ graph()->end()->InputAt(1),
+ IsReturn2(IsProjection(0, AllOf(CaptureEq(&mul_capture), mul_matcher)),
+ IsProjection(1, AllOf(CaptureEq(&mul_capture), mul_matcher)),
+ start(), start()));
+}
+
+// kExprI64DivS:
+// kExprI64DivU:
+// kExprI64RemS:
+// kExprI64RemU:
+// kExprI64Ior:
+TEST_F(Int64LoweringTest, Int64Ior) {
+ LowerGraph(graph()->NewNode(machine()->Word64Or(), Int64Constant(value(0)),
+ Int64Constant(value(1))),
+ MachineRepresentation::kWord64);
+ EXPECT_THAT(graph()->end()->InputAt(1),
+ IsReturn2(IsWord32Or(IsInt32Constant(low_word_value(0)),
+ IsInt32Constant(low_word_value(1))),
+ IsWord32Or(IsInt32Constant(high_word_value(0)),
+ IsInt32Constant(high_word_value(1))),
+ start(), start()));
+}
+
+// kExprI64Xor:
+TEST_F(Int64LoweringTest, Int64Xor) {
+ LowerGraph(graph()->NewNode(machine()->Word64Xor(), Int64Constant(value(0)),
+ Int64Constant(value(1))),
+ MachineRepresentation::kWord64);
+ EXPECT_THAT(graph()->end()->InputAt(1),
+ IsReturn2(IsWord32Xor(IsInt32Constant(low_word_value(0)),
+ IsInt32Constant(low_word_value(1))),
+ IsWord32Xor(IsInt32Constant(high_word_value(0)),
+ IsInt32Constant(high_word_value(1))),
+ start(), start()));
+}
+// kExprI64Shl:
+TEST_F(Int64LoweringTest, Int64Shl) {
+ LowerGraph(graph()->NewNode(machine()->Word64Shl(), Int64Constant(value(0)),
+ Int64Constant(value(1))),
+ MachineRepresentation::kWord64);
+
+ Capture<Node*> shl;
+ Matcher<Node*> shl_matcher = IsWord32PairShl(
+ IsInt32Constant(low_word_value(0)), IsInt32Constant(high_word_value(0)),
+ IsInt32Constant(low_word_value(1)));
+
+ EXPECT_THAT(graph()->end()->InputAt(1),
+ IsReturn2(IsProjection(0, AllOf(CaptureEq(&shl), shl_matcher)),
+ IsProjection(1, AllOf(CaptureEq(&shl), shl_matcher)),
+ start(), start()));
+}
+// kExprI64ShrU:
+TEST_F(Int64LoweringTest, Int64ShrU) {
+ LowerGraph(graph()->NewNode(machine()->Word64Shr(), Int64Constant(value(0)),
+ Int64Constant(value(1))),
+ MachineRepresentation::kWord64);
+
+ Capture<Node*> shr;
+ Matcher<Node*> shr_matcher = IsWord32PairShr(
+ IsInt32Constant(low_word_value(0)), IsInt32Constant(high_word_value(0)),
+ IsInt32Constant(low_word_value(1)));
+
+ EXPECT_THAT(graph()->end()->InputAt(1),
+ IsReturn2(IsProjection(0, AllOf(CaptureEq(&shr), shr_matcher)),
+ IsProjection(1, AllOf(CaptureEq(&shr), shr_matcher)),
+ start(), start()));
+}
+// kExprI64ShrS:
+TEST_F(Int64LoweringTest, Int64ShrS) {
+ LowerGraph(graph()->NewNode(machine()->Word64Sar(), Int64Constant(value(0)),
+ Int64Constant(value(1))),
+ MachineRepresentation::kWord64);
+
+ Capture<Node*> sar;
+ Matcher<Node*> sar_matcher = IsWord32PairSar(
+ IsInt32Constant(low_word_value(0)), IsInt32Constant(high_word_value(0)),
+ IsInt32Constant(low_word_value(1)));
+
+ EXPECT_THAT(graph()->end()->InputAt(1),
+ IsReturn2(IsProjection(0, AllOf(CaptureEq(&sar), sar_matcher)),
+ IsProjection(1, AllOf(CaptureEq(&sar), sar_matcher)),
+ start(), start()));
+}
+// kExprI64Eq:
+TEST_F(Int64LoweringTest, Int64Eq) {
+ LowerGraph(graph()->NewNode(machine()->Word64Equal(), Int64Constant(value(0)),
+ Int64Constant(value(1))),
+ MachineRepresentation::kWord32);
+ EXPECT_THAT(
+ graph()->end()->InputAt(1),
+ IsReturn(IsWord32Equal(
+ IsWord32Or(IsWord32Xor(IsInt32Constant(low_word_value(0)),
+ IsInt32Constant(low_word_value(1))),
+ IsWord32Xor(IsInt32Constant(high_word_value(0)),
+ IsInt32Constant(high_word_value(1)))),
+ IsInt32Constant(0)),
+ start(), start()));
+}
+
+// kExprI64LtS:
+TEST_F(Int64LoweringTest, Int64LtS) {
+ TestComparison(machine()->Int64LessThan(), IsInt32LessThan, IsUint32LessThan);
+}
+// kExprI64LeS:
+TEST_F(Int64LoweringTest, Int64LeS) {
+ TestComparison(machine()->Int64LessThanOrEqual(), IsInt32LessThan,
+ IsUint32LessThanOrEqual);
+}
+// kExprI64LtU:
+TEST_F(Int64LoweringTest, Int64LtU) {
+ TestComparison(machine()->Uint64LessThan(), IsUint32LessThan,
+ IsUint32LessThan);
+}
+// kExprI64LeU:
+TEST_F(Int64LoweringTest, Int64LeU) {
+ TestComparison(machine()->Uint64LessThanOrEqual(), IsUint32LessThan,
+ IsUint32LessThanOrEqual);
+}
+
+// kExprI32ConvertI64:
+TEST_F(Int64LoweringTest, I32ConvertI64) {
+ LowerGraph(graph()->NewNode(machine()->TruncateInt64ToInt32(),
+ Int64Constant(value(0))),
+ MachineRepresentation::kWord32);
+ EXPECT_THAT(graph()->end()->InputAt(1),
+ IsReturn(IsInt32Constant(low_word_value(0)), start(), start()));
+}
+// kExprI64SConvertI32:
+TEST_F(Int64LoweringTest, I64SConvertI32) {
+ LowerGraph(graph()->NewNode(machine()->ChangeInt32ToInt64(),
+ Int32Constant(low_word_value(0))),
+ MachineRepresentation::kWord64);
+
+ EXPECT_THAT(graph()->end()->InputAt(1),
+ IsReturn2(IsInt32Constant(low_word_value(0)),
+ IsWord32Sar(IsInt32Constant(low_word_value(0)),
+ IsInt32Constant(31)),
+ start(), start()));
+}
+
+TEST_F(Int64LoweringTest, I64SConvertI32_2) {
+ LowerGraph(
+ graph()->NewNode(machine()->ChangeInt32ToInt64(),
+ graph()->NewNode(machine()->TruncateInt64ToInt32(),
+ Int64Constant(value(0)))),
+ MachineRepresentation::kWord64);
+
+ EXPECT_THAT(graph()->end()->InputAt(1),
+ IsReturn2(IsInt32Constant(low_word_value(0)),
+ IsWord32Sar(IsInt32Constant(low_word_value(0)),
+ IsInt32Constant(31)),
+ start(), start()));
+}
+// kExprI64UConvertI32:
+TEST_F(Int64LoweringTest, I64UConvertI32) {
+ LowerGraph(graph()->NewNode(machine()->ChangeUint32ToUint64(),
+ Int32Constant(low_word_value(0))),
+ MachineRepresentation::kWord64);
+
+ EXPECT_THAT(graph()->end()->InputAt(1),
+ IsReturn2(IsInt32Constant(low_word_value(0)), IsInt32Constant(0),
+ start(), start()));
+}
+
+TEST_F(Int64LoweringTest, I64UConvertI32_2) {
+ LowerGraph(
+ graph()->NewNode(machine()->ChangeUint32ToUint64(),
+ graph()->NewNode(machine()->TruncateInt64ToInt32(),
+ Int64Constant(value(0)))),
+ MachineRepresentation::kWord64);
+
+ EXPECT_THAT(graph()->end()->InputAt(1),
+ IsReturn2(IsInt32Constant(low_word_value(0)), IsInt32Constant(0),
+ start(), start()));
+}
+// kExprF64ReinterpretI64:
+TEST_F(Int64LoweringTest, F64ReinterpretI64) {
+ LowerGraph(graph()->NewNode(machine()->BitcastInt64ToFloat64(),
+ Int64Constant(value(0))),
+ MachineRepresentation::kFloat64);
+
+ Capture<Node*> stack_slot_capture;
+ Matcher<Node*> stack_slot_matcher =
+ IsStackSlot(MachineRepresentation::kWord64);
+
+ Capture<Node*> store_capture;
+ Matcher<Node*> store_matcher =
+ IsStore(StoreRepresentation(MachineRepresentation::kWord32,
+ WriteBarrierKind::kNoWriteBarrier),
+ AllOf(CaptureEq(&stack_slot_capture), stack_slot_matcher),
+ IsInt32Constant(0), IsInt32Constant(low_word_value(0)),
+ IsStore(StoreRepresentation(MachineRepresentation::kWord32,
+ WriteBarrierKind::kNoWriteBarrier),
+ AllOf(CaptureEq(&stack_slot_capture), stack_slot_matcher),
+ IsInt32Constant(4), IsInt32Constant(high_word_value(0)),
+ start(), start()),
+ start());
+
+ EXPECT_THAT(
+ graph()->end()->InputAt(1),
+ IsReturn(IsLoad(MachineType::Float64(),
+ AllOf(CaptureEq(&stack_slot_capture), stack_slot_matcher),
+ IsInt32Constant(0),
+ AllOf(CaptureEq(&store_capture), store_matcher), start()),
+ start(), start()));
+}
+// kExprI64ReinterpretF64:
+TEST_F(Int64LoweringTest, I64ReinterpretF64) {
+ LowerGraph(graph()->NewNode(machine()->BitcastFloat64ToInt64(),
+ Float64Constant(bit_cast<double>(value(0)))),
+ MachineRepresentation::kWord64);
+
+ Capture<Node*> stack_slot;
+ Matcher<Node*> stack_slot_matcher =
+ IsStackSlot(MachineRepresentation::kWord64);
+
+ Capture<Node*> store;
+ Matcher<Node*> store_matcher = IsStore(
+ StoreRepresentation(MachineRepresentation::kFloat64,
+ WriteBarrierKind::kNoWriteBarrier),
+ AllOf(CaptureEq(&stack_slot), stack_slot_matcher), IsInt32Constant(0),
+ IsFloat64Constant(bit_cast<double>(value(0))), start(), start());
+
+ EXPECT_THAT(
+ graph()->end()->InputAt(1),
+ IsReturn2(IsLoad(MachineType::Int32(),
+ AllOf(CaptureEq(&stack_slot), stack_slot_matcher),
+ IsInt32Constant(0),
+ AllOf(CaptureEq(&store), store_matcher), start()),
+ IsLoad(MachineType::Int32(),
+ AllOf(CaptureEq(&stack_slot), stack_slot_matcher),
+ IsInt32Constant(0x4),
+ AllOf(CaptureEq(&store), store_matcher), start()),
+ start(), start()));
+}
+// kExprI64Clz:
+TEST_F(Int64LoweringTest, I64Clz) {
+ LowerGraph(graph()->NewNode(machine()->Word64Clz(), Int64Constant(value(0))),
+ MachineRepresentation::kWord64);
+
+ Capture<Node*> branch_capture;
+ Matcher<Node*> branch_matcher = IsBranch(
+ IsWord32Equal(IsInt32Constant(high_word_value(0)), IsInt32Constant(0)),
+ start());
+
+ EXPECT_THAT(
+ graph()->end()->InputAt(1),
+ IsReturn2(
+ IsPhi(MachineRepresentation::kWord32,
+ IsInt32Add(IsWord32Clz(IsInt32Constant(low_word_value(0))),
+ IsInt32Constant(32)),
+ IsWord32Clz(IsInt32Constant(high_word_value(0))),
+ IsMerge(
+ IsIfTrue(AllOf(CaptureEq(&branch_capture), branch_matcher)),
+ IsIfFalse(
+ AllOf(CaptureEq(&branch_capture), branch_matcher)))),
+ IsInt32Constant(0), start(), start()));
+}
+// kExprI64Ctz:
+TEST_F(Int64LoweringTest, I64Ctz) {
+ LowerGraph(graph()->NewNode(machine()->Word64CtzPlaceholder(),
+ Int64Constant(value(0))),
+ MachineRepresentation::kWord64);
+ Capture<Node*> branch_capture;
+ Matcher<Node*> branch_matcher = IsBranch(
+ IsWord32Equal(IsInt32Constant(low_word_value(0)), IsInt32Constant(0)),
+ start());
+ EXPECT_THAT(
+ graph()->end()->InputAt(1),
+ IsReturn2(
+ IsPhi(MachineRepresentation::kWord32,
+ IsInt32Add(IsWord32Ctz(IsInt32Constant(high_word_value(0))),
+ IsInt32Constant(32)),
+ IsWord32Ctz(IsInt32Constant(low_word_value(0))),
+ IsMerge(
+ IsIfTrue(AllOf(CaptureEq(&branch_capture), branch_matcher)),
+ IsIfFalse(
+ AllOf(CaptureEq(&branch_capture), branch_matcher)))),
+ IsInt32Constant(0), start(), start()));
+}
+// kExprI64Popcnt:
+
+TEST_F(Int64LoweringTest, Dfs) {
+ Node* common = Int64Constant(value(0));
+ LowerGraph(graph()->NewNode(machine()->Word64And(), common,
+ graph()->NewNode(machine()->Word64And(), common,
+ Int64Constant(value(1)))),
+ MachineRepresentation::kWord64);
+
+ EXPECT_THAT(
+ graph()->end()->InputAt(1),
+ IsReturn2(IsWord32And(IsInt32Constant(low_word_value(0)),
+ IsWord32And(IsInt32Constant(low_word_value(0)),
+ IsInt32Constant(low_word_value(1)))),
+ IsWord32And(IsInt32Constant(high_word_value(0)),
+ IsWord32And(IsInt32Constant(high_word_value(0)),
+ IsInt32Constant(high_word_value(1)))),
+ start(), start()));
+}
+
+TEST_F(Int64LoweringTest, I64Popcnt) {
+ LowerGraph(graph()->NewNode(machine()->Word64PopcntPlaceholder(),
+ Int64Constant(value(0))),
+ MachineRepresentation::kWord64);
+
+ EXPECT_THAT(
+ graph()->end()->InputAt(1),
+ IsReturn2(IsInt32Add(IsWord32Popcnt(IsInt32Constant(low_word_value(0))),
+ IsWord32Popcnt(IsInt32Constant(high_word_value(0)))),
+ IsInt32Constant(0), start(), start()));
+}
+
+TEST_F(Int64LoweringTest, I64Ror) {
+ LowerGraph(graph()->NewNode(machine()->Word64Ror(), Int64Constant(value(0)),
+ Parameter(0)),
+ MachineRepresentation::kWord64, MachineRepresentation::kWord64, 1);
+
+ Matcher<Node*> branch_lt32_matcher =
+ IsBranch(IsInt32LessThan(IsParameter(0), IsInt32Constant(32)), start());
+
+ Matcher<Node*> low_input_matcher = IsPhi(
+ MachineRepresentation::kWord32, IsInt32Constant(low_word_value(0)),
+ IsInt32Constant(high_word_value(0)),
+ IsMerge(IsIfTrue(branch_lt32_matcher), IsIfFalse(branch_lt32_matcher)));
+
+ Matcher<Node*> high_input_matcher = IsPhi(
+ MachineRepresentation::kWord32, IsInt32Constant(high_word_value(0)),
+ IsInt32Constant(low_word_value(0)),
+ IsMerge(IsIfTrue(branch_lt32_matcher), IsIfFalse(branch_lt32_matcher)));
+
+ Matcher<Node*> shift_matcher =
+ IsWord32And(IsParameter(0), IsInt32Constant(0x1f));
+
+ Matcher<Node*> bit_mask_matcher = IsWord32Shl(
+ IsWord32Sar(IsInt32Constant(std::numeric_limits<int32_t>::min()),
+ shift_matcher),
+ IsInt32Constant(1));
+
+ Matcher<Node*> inv_mask_matcher =
+ IsWord32Xor(bit_mask_matcher, IsInt32Constant(-1));
+
+ EXPECT_THAT(
+ graph()->end()->InputAt(1),
+ IsReturn2(
+ IsWord32Or(IsWord32And(IsWord32Ror(low_input_matcher, shift_matcher),
+ inv_mask_matcher),
+ IsWord32And(IsWord32Ror(high_input_matcher, shift_matcher),
+ bit_mask_matcher)),
+ IsWord32Or(IsWord32And(IsWord32Ror(high_input_matcher, shift_matcher),
+ inv_mask_matcher),
+ IsWord32And(IsWord32Ror(low_input_matcher, shift_matcher),
+ bit_mask_matcher)),
+ start(), start()));
+}
+
+TEST_F(Int64LoweringTest, I64Ror_0) {
+ LowerGraph(graph()->NewNode(machine()->Word64Ror(), Int64Constant(value(0)),
+ Int32Constant(0)),
+ MachineRepresentation::kWord64);
+
+ EXPECT_THAT(graph()->end()->InputAt(1),
+ IsReturn2(IsInt32Constant(low_word_value(0)),
+ IsInt32Constant(high_word_value(0)), start(), start()));
+}
+
+TEST_F(Int64LoweringTest, I64Ror_32) {
+ LowerGraph(graph()->NewNode(machine()->Word64Ror(), Int64Constant(value(0)),
+ Int32Constant(32)),
+ MachineRepresentation::kWord64);
+
+ EXPECT_THAT(graph()->end()->InputAt(1),
+ IsReturn2(IsInt32Constant(high_word_value(0)),
+ IsInt32Constant(low_word_value(0)), start(), start()));
+}
+
+TEST_F(Int64LoweringTest, I64Ror_11) {
+ LowerGraph(graph()->NewNode(machine()->Word64Ror(), Int64Constant(value(0)),
+ Int32Constant(11)),
+ MachineRepresentation::kWord64);
+
+ EXPECT_THAT(
+ graph()->end()->InputAt(1),
+ IsReturn2(IsWord32Or(IsWord32Shr(IsInt32Constant(low_word_value(0)),
+ IsInt32Constant(11)),
+ IsWord32Shl(IsInt32Constant(high_word_value(0)),
+ IsInt32Constant(21))),
+ IsWord32Or(IsWord32Shr(IsInt32Constant(high_word_value(0)),
+ IsInt32Constant(11)),
+ IsWord32Shl(IsInt32Constant(low_word_value(0)),
+ IsInt32Constant(21))),
+ start(), start()));
+}
+
+TEST_F(Int64LoweringTest, I64Ror_43) {
+ LowerGraph(graph()->NewNode(machine()->Word64Ror(), Int64Constant(value(0)),
+ Int32Constant(43)),
+ MachineRepresentation::kWord64);
+
+ EXPECT_THAT(
+ graph()->end()->InputAt(1),
+ IsReturn2(IsWord32Or(IsWord32Shr(IsInt32Constant(high_word_value(0)),
+ IsInt32Constant(11)),
+ IsWord32Shl(IsInt32Constant(low_word_value(0)),
+ IsInt32Constant(21))),
+ IsWord32Or(IsWord32Shr(IsInt32Constant(low_word_value(0)),
+ IsInt32Constant(11)),
+ IsWord32Shl(IsInt32Constant(high_word_value(0)),
+ IsInt32Constant(21))),
+ start(), start()));
+}
+
+TEST_F(Int64LoweringTest, I64PhiWord64) {
+ LowerGraph(graph()->NewNode(common()->Phi(MachineRepresentation::kWord64, 2),
+ Int64Constant(value(0)), Int64Constant(value(1)),
+ start()),
+ MachineRepresentation::kWord64);
+
+ EXPECT_THAT(graph()->end()->InputAt(1),
+ IsReturn2(IsPhi(MachineRepresentation::kWord32,
+ IsInt32Constant(low_word_value(0)),
+ IsInt32Constant(low_word_value(1)), start()),
+ IsPhi(MachineRepresentation::kWord32,
+ IsInt32Constant(high_word_value(0)),
+ IsInt32Constant(high_word_value(1)), start()),
+ start(), start()));
+}
+
+void TestPhi(Int64LoweringTest* test, MachineRepresentation rep, Node* v1,
+ Node* v2) {
+ test->LowerGraph(test->graph()->NewNode(test->common()->Phi(rep, 2), v1, v2,
+ test->start()),
+ rep);
+
+ EXPECT_THAT(test->graph()->end()->InputAt(1),
+ IsReturn(IsPhi(rep, v1, v2, test->start()), test->start(),
+ test->start()));
+}
+
+TEST_F(Int64LoweringTest, I64PhiFloat32) {
+ TestPhi(this, MachineRepresentation::kFloat32, Float32Constant(1.5),
+ Float32Constant(2.5));
+}
+
+TEST_F(Int64LoweringTest, I64PhiFloat64) {
+ TestPhi(this, MachineRepresentation::kFloat64, Float32Constant(1.5),
+ Float32Constant(2.5));
+}
+
+TEST_F(Int64LoweringTest, I64PhiWord32) {
+ TestPhi(this, MachineRepresentation::kWord32, Float32Constant(1),
+ Float32Constant(2));
+}
} // namespace compiler
} // namespace internal
} // namespace v8
diff --git a/test/unittests/compiler/js-builtin-reducer-unittest.cc b/test/unittests/compiler/js-builtin-reducer-unittest.cc
index 9e14cda..0f8eed7 100644
--- a/test/unittests/compiler/js-builtin-reducer-unittest.cc
+++ b/test/unittests/compiler/js-builtin-reducer-unittest.cc
@@ -43,7 +43,7 @@
isolate()->factory()->NewStringFromAsciiChecked(
"Math")).ToHandleChecked();
Handle<JSFunction> f = Handle<JSFunction>::cast(
- JSObject::GetProperty(
+ Object::GetProperty(
m, isolate()->factory()->NewStringFromAsciiChecked(name))
.ToHandleChecked());
return HeapConstant(f);
@@ -149,8 +149,8 @@
Node* control = graph()->start();
Node* context = UndefinedConstant();
Node* frame_state = graph()->start();
- TRACED_FOREACH(Type*, t0, kIntegral32Types) {
- TRACED_FOREACH(Type*, t1, kIntegral32Types) {
+ TRACED_FOREACH(Type*, t0, kNumberTypes) {
+ TRACED_FOREACH(Type*, t1, kNumberTypes) {
Node* p0 = Parameter(t0, 0);
Node* p1 = Parameter(t1, 1);
Node* call = graph()->NewNode(javascript()->CallFunction(4), function,
@@ -159,7 +159,8 @@
Reduction r = Reduce(call);
ASSERT_TRUE(r.Changed());
- EXPECT_THAT(r.replacement(), IsInt32Mul(p0, p1));
+ EXPECT_THAT(r.replacement(),
+ IsNumberImul(IsNumberToUint32(p0), IsNumberToUint32(p1)));
}
}
}
diff --git a/test/unittests/compiler/js-intrinsic-lowering-unittest.cc b/test/unittests/compiler/js-intrinsic-lowering-unittest.cc
index 919c1b2..de0eefc 100644
--- a/test/unittests/compiler/js-intrinsic-lowering-unittest.cc
+++ b/test/unittests/compiler/js-intrinsic-lowering-unittest.cc
@@ -91,7 +91,8 @@
graph()->NewNode(javascript()->CallRuntime(Runtime::kInlineDoubleLo, 1),
input, context, effect, control));
ASSERT_TRUE(r.Changed());
- EXPECT_THAT(r.replacement(), IsFloat64ExtractLowWord32(input));
+ EXPECT_THAT(r.replacement(),
+ IsFloat64ExtractLowWord32(IsGuard(Type::Number(), input, _)));
}
@@ -108,7 +109,8 @@
graph()->NewNode(javascript()->CallRuntime(Runtime::kInlineDoubleHi, 1),
input, context, effect, control));
ASSERT_TRUE(r.Changed());
- EXPECT_THAT(r.replacement(), IsFloat64ExtractHighWord32(input));
+ EXPECT_THAT(r.replacement(),
+ IsFloat64ExtractHighWord32(IsGuard(Type::Number(), input, _)));
}
@@ -240,58 +242,6 @@
// -----------------------------------------------------------------------------
-// %_MathFloor
-
-
-TEST_F(JSIntrinsicLoweringTest, InlineMathFloor) {
- Node* const input = Parameter(0);
- Node* const context = Parameter(1);
- Node* const effect = graph()->start();
- Node* const control = graph()->start();
- Reduction const r = Reduce(
- graph()->NewNode(javascript()->CallRuntime(Runtime::kInlineMathFloor, 1),
- input, context, effect, control),
- MachineOperatorBuilder::kFloat64RoundDown);
- ASSERT_TRUE(r.Changed());
- EXPECT_THAT(r.replacement(), IsFloat64RoundDown(input));
-}
-
-
-// -----------------------------------------------------------------------------
-// %_MathSqrt
-
-
-TEST_F(JSIntrinsicLoweringTest, InlineMathSqrt) {
- Node* const input = Parameter(0);
- Node* const context = Parameter(1);
- Node* const effect = graph()->start();
- Node* const control = graph()->start();
- Reduction const r = Reduce(
- graph()->NewNode(javascript()->CallRuntime(Runtime::kInlineMathSqrt, 1),
- input, context, effect, control));
- ASSERT_TRUE(r.Changed());
- EXPECT_THAT(r.replacement(), IsFloat64Sqrt(input));
-}
-
-
-// -----------------------------------------------------------------------------
-// %_MathClz32
-
-
-TEST_F(JSIntrinsicLoweringTest, InlineMathClz32) {
- Node* const input = Parameter(0);
- Node* const context = Parameter(1);
- Node* const effect = graph()->start();
- Node* const control = graph()->start();
- Reduction const r = Reduce(
- graph()->NewNode(javascript()->CallRuntime(Runtime::kInlineMathClz32, 1),
- input, context, effect, control));
- ASSERT_TRUE(r.Changed());
- EXPECT_THAT(r.replacement(), IsWord32Clz(input));
-}
-
-
-// -----------------------------------------------------------------------------
// %_ValueOf
@@ -334,6 +284,23 @@
AllOf(CaptureEq(&if_false0), IsIfFalse(CaptureEq(&branch0))))));
}
+// -----------------------------------------------------------------------------
+// %_GetOrdinaryHasInstance
+
+TEST_F(JSIntrinsicLoweringTest, InlineGetOrdinaryHasInstance) {
+ Node* const context = Parameter(0);
+ Node* const effect = graph()->start();
+ Node* const control = graph()->start();
+ Reduction const r = Reduce(graph()->NewNode(
+ javascript()->CallRuntime(Runtime::kInlineGetOrdinaryHasInstance, 0),
+ context, effect, control));
+ ASSERT_TRUE(r.Changed());
+ EXPECT_THAT(
+ r.replacement(),
+ IsLoadContext(
+ ContextAccess(0, Context::ORDINARY_HAS_INSTANCE_INDEX, true), _));
+}
+
} // namespace compiler
} // namespace internal
} // namespace v8
diff --git a/test/unittests/compiler/js-typed-lowering-unittest.cc b/test/unittests/compiler/js-typed-lowering-unittest.cc
index e37d4a2..1adb5da 100644
--- a/test/unittests/compiler/js-typed-lowering-unittest.cc
+++ b/test/unittests/compiler/js-typed-lowering-unittest.cc
@@ -67,7 +67,7 @@
STATIC_ASSERT(LANGUAGE_END == 3);
-const LanguageMode kLanguageModes[] = {SLOPPY, STRICT, STRONG};
+const LanguageMode kLanguageModes[] = {SLOPPY, STRICT};
} // namespace
diff --git a/test/unittests/compiler/load-elimination-unittest.cc b/test/unittests/compiler/load-elimination-unittest.cc
index 3ad11cf..38bb151 100644
--- a/test/unittests/compiler/load-elimination-unittest.cc
+++ b/test/unittests/compiler/load-elimination-unittest.cc
@@ -12,30 +12,33 @@
namespace internal {
namespace compiler {
-class LoadEliminationTest : public GraphTest {
+class LoadEliminationTest : public TypedGraphTest {
public:
- LoadEliminationTest() : GraphTest(3), simplified_(zone()) {}
+ LoadEliminationTest()
+ : TypedGraphTest(3), common_(zone()), simplified_(zone()) {}
~LoadEliminationTest() override {}
protected:
Reduction Reduce(Node* node) {
// TODO(titzer): mock the GraphReducer here for better unit testing.
GraphReducer graph_reducer(zone(), graph());
- LoadElimination reducer(&graph_reducer);
+ LoadElimination reducer(&graph_reducer, graph(), common());
return reducer.Reduce(node);
}
SimplifiedOperatorBuilder* simplified() { return &simplified_; }
+ CommonOperatorBuilder* common() { return &common_; }
private:
+ CommonOperatorBuilder common_;
SimplifiedOperatorBuilder simplified_;
};
TEST_F(LoadEliminationTest, LoadFieldWithStoreField) {
- Node* object1 = Parameter(0);
- Node* object2 = Parameter(1);
- Node* value = Parameter(2);
+ Node* object1 = Parameter(Type::Any(), 0);
+ Node* object2 = Parameter(Type::Any(), 1);
+ Node* value = Parameter(Type::Any(), 2);
Node* effect = graph()->start();
Node* control = graph()->start();
diff --git a/test/unittests/compiler/loop-peeling-unittest.cc b/test/unittests/compiler/loop-peeling-unittest.cc
index 9dcec85..9db4905 100644
--- a/test/unittests/compiler/loop-peeling-unittest.cc
+++ b/test/unittests/compiler/loop-peeling-unittest.cc
@@ -64,7 +64,7 @@
OFStream os(stdout);
os << AsRPO(*graph());
}
- Zone zone;
+ Zone zone(isolate()->allocator());
return LoopFinder::BuildLoopTree(graph(), &zone);
}
diff --git a/test/unittests/compiler/node-test-utils.cc b/test/unittests/compiler/node-test-utils.cc
index ee4cf54..6e5d39f 100644
--- a/test/unittests/compiler/node-test-utils.cc
+++ b/test/unittests/compiler/node-test-utils.cc
@@ -1330,6 +1330,53 @@
const Matcher<Node*> control_matcher_;
};
+class IsStackSlotMatcher final : public NodeMatcher {
+ public:
+ explicit IsStackSlotMatcher(const Matcher<MachineRepresentation>& rep_matcher)
+ : NodeMatcher(IrOpcode::kStackSlot), rep_matcher_(rep_matcher) {}
+
+ void DescribeTo(std::ostream* os) const final {
+ NodeMatcher::DescribeTo(os);
+ *os << " whose rep (";
+ rep_matcher_.DescribeTo(os);
+ *os << ")";
+ }
+
+ bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
+ return (NodeMatcher::MatchAndExplain(node, listener) &&
+ PrintMatchAndExplain(OpParameter<MachineRepresentation>(node),
+ "rep", rep_matcher_, listener));
+ }
+
+ private:
+ const Matcher<MachineRepresentation> rep_matcher_;
+};
+
+class IsGuardMatcher final : public NodeMatcher {
+ public:
+ IsGuardMatcher(const Matcher<Type*>& type_matcher,
+ const Matcher<Node*>& value_matcher,
+ const Matcher<Node*>& control_matcher)
+ : NodeMatcher(IrOpcode::kGuard),
+ type_matcher_(type_matcher),
+ value_matcher_(value_matcher),
+ control_matcher_(control_matcher) {}
+
+ bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
+ return (NodeMatcher::MatchAndExplain(node, listener) &&
+ PrintMatchAndExplain(OpParameter<Type*>(node->op()), "type",
+ type_matcher_, listener) &&
+ PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0),
+ "value", value_matcher_, listener) &&
+ PrintMatchAndExplain(NodeProperties::GetControlInput(node, 0),
+ "control", control_matcher_, listener));
+ }
+
+ private:
+ const Matcher<Type*> type_matcher_;
+ const Matcher<Node*> value_matcher_;
+ const Matcher<Node*> control_matcher_;
+};
class IsToNumberMatcher final : public NodeMatcher {
public:
@@ -1406,6 +1453,86 @@
const Matcher<Node*> context_matcher_;
};
+class IsQuadopMatcher final : public NodeMatcher {
+ public:
+ IsQuadopMatcher(IrOpcode::Value opcode, const Matcher<Node*>& a_matcher,
+ const Matcher<Node*>& b_matcher,
+ const Matcher<Node*>& c_matcher,
+ const Matcher<Node*>& d_matcher)
+ : NodeMatcher(opcode),
+ a_matcher_(a_matcher),
+ b_matcher_(b_matcher),
+ c_matcher_(c_matcher),
+ d_matcher_(d_matcher) {}
+
+ void DescribeTo(std::ostream* os) const final {
+ NodeMatcher::DescribeTo(os);
+ *os << " whose a (";
+ a_matcher_.DescribeTo(os);
+ *os << ") and b (";
+ b_matcher_.DescribeTo(os);
+ *os << ") and c (";
+ c_matcher_.DescribeTo(os);
+ *os << ") and d (";
+ d_matcher_.DescribeTo(os);
+ *os << ")";
+ }
+
+ bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
+ return (NodeMatcher::MatchAndExplain(node, listener) &&
+ PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0), "a",
+ a_matcher_, listener) &&
+ PrintMatchAndExplain(NodeProperties::GetValueInput(node, 1), "b",
+ b_matcher_, listener) &&
+ PrintMatchAndExplain(NodeProperties::GetValueInput(node, 2), "c",
+ c_matcher_, listener) &&
+ PrintMatchAndExplain(NodeProperties::GetValueInput(node, 3), "d",
+ d_matcher_, listener));
+ }
+
+ private:
+ const Matcher<Node*> a_matcher_;
+ const Matcher<Node*> b_matcher_;
+ const Matcher<Node*> c_matcher_;
+ const Matcher<Node*> d_matcher_;
+};
+
+class IsTernopMatcher final : public NodeMatcher {
+ public:
+ IsTernopMatcher(IrOpcode::Value opcode, const Matcher<Node*>& lhs_matcher,
+ const Matcher<Node*>& mid_matcher,
+ const Matcher<Node*>& rhs_matcher)
+ : NodeMatcher(opcode),
+ lhs_matcher_(lhs_matcher),
+ mid_matcher_(mid_matcher),
+ rhs_matcher_(rhs_matcher) {}
+
+ void DescribeTo(std::ostream* os) const final {
+ NodeMatcher::DescribeTo(os);
+ *os << " whose lhs (";
+ lhs_matcher_.DescribeTo(os);
+ *os << ") and mid (";
+ mid_matcher_.DescribeTo(os);
+ *os << ") and rhs (";
+ rhs_matcher_.DescribeTo(os);
+ *os << ")";
+ }
+
+ bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
+ return (NodeMatcher::MatchAndExplain(node, listener) &&
+ PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0), "lhs",
+ lhs_matcher_, listener) &&
+ PrintMatchAndExplain(NodeProperties::GetValueInput(node, 1), "mid",
+ mid_matcher_, listener) &&
+ PrintMatchAndExplain(NodeProperties::GetValueInput(node, 2), "rhs",
+ rhs_matcher_, listener));
+ }
+
+ private:
+ const Matcher<Node*> lhs_matcher_;
+ const Matcher<Node*> mid_matcher_;
+ const Matcher<Node*> rhs_matcher_;
+};
class IsBinopMatcher final : public NodeMatcher {
public:
@@ -1484,7 +1611,6 @@
} // namespace
-
Matcher<Node*> IsDead() {
return MakeMatcher(new NodeMatcher(IrOpcode::kDead));
}
@@ -1938,6 +2064,12 @@
effect_matcher, control_matcher));
}
+Matcher<Node*> IsGuard(const Matcher<Type*>& type_matcher,
+ const Matcher<Node*>& value_matcher,
+ const Matcher<Node*>& control_matcher) {
+ return MakeMatcher(
+ new IsGuardMatcher(type_matcher, value_matcher, control_matcher));
+}
Matcher<Node*> IsReferenceEqual(const Matcher<Type*>& type_matcher,
const Matcher<Node*>& lhs_matcher,
@@ -2044,6 +2176,9 @@
effect_matcher, control_matcher));
}
+Matcher<Node*> IsStackSlot(const Matcher<MachineRepresentation>& rep_matcher) {
+ return MakeMatcher(new IsStackSlotMatcher(rep_matcher));
+}
Matcher<Node*> IsToNumber(const Matcher<Node*>& base_matcher,
const Matcher<Node*>& context_matcher,
@@ -2069,6 +2204,29 @@
return MakeMatcher(new NodeMatcher(IrOpcode::kLoadFramePointer));
}
+#define IS_QUADOP_MATCHER(Name) \
+ Matcher<Node*> Is##Name( \
+ const Matcher<Node*>& a_matcher, const Matcher<Node*>& b_matcher, \
+ const Matcher<Node*>& c_matcher, const Matcher<Node*>& d_matcher) { \
+ return MakeMatcher(new IsQuadopMatcher(IrOpcode::k##Name, a_matcher, \
+ b_matcher, c_matcher, d_matcher)); \
+ }
+
+IS_QUADOP_MATCHER(Int32PairAdd)
+IS_QUADOP_MATCHER(Int32PairSub)
+IS_QUADOP_MATCHER(Int32PairMul)
+
+#define IS_TERNOP_MATCHER(Name) \
+ Matcher<Node*> Is##Name(const Matcher<Node*>& lhs_matcher, \
+ const Matcher<Node*>& mid_matcher, \
+ const Matcher<Node*>& rhs_matcher) { \
+ return MakeMatcher(new IsTernopMatcher(IrOpcode::k##Name, lhs_matcher, \
+ mid_matcher, rhs_matcher)); \
+ }
+
+IS_TERNOP_MATCHER(Word32PairShl)
+IS_TERNOP_MATCHER(Word32PairShr)
+IS_TERNOP_MATCHER(Word32PairSar)
#define IS_BINOP_MATCHER(Name) \
Matcher<Node*> Is##Name(const Matcher<Node*>& lhs_matcher, \
@@ -2083,8 +2241,10 @@
IS_BINOP_MATCHER(NumberShiftLeft)
IS_BINOP_MATCHER(NumberShiftRight)
IS_BINOP_MATCHER(NumberShiftRightLogical)
+IS_BINOP_MATCHER(NumberImul)
IS_BINOP_MATCHER(Word32And)
IS_BINOP_MATCHER(Word32Or)
+IS_BINOP_MATCHER(Word32Xor)
IS_BINOP_MATCHER(Word32Sar)
IS_BINOP_MATCHER(Word32Shl)
IS_BINOP_MATCHER(Word32Shr)
@@ -2146,6 +2306,8 @@
IS_UNOP_MATCHER(ObjectIsReceiver)
IS_UNOP_MATCHER(ObjectIsSmi)
IS_UNOP_MATCHER(Word32Clz)
+IS_UNOP_MATCHER(Word32Ctz)
+IS_UNOP_MATCHER(Word32Popcnt)
#undef IS_UNOP_MATCHER
} // namespace compiler
diff --git a/test/unittests/compiler/node-test-utils.h b/test/unittests/compiler/node-test-utils.h
index 03f2a3b..dd036c9 100644
--- a/test/unittests/compiler/node-test-utils.h
+++ b/test/unittests/compiler/node-test-utils.h
@@ -211,6 +211,8 @@
const Matcher<Node*>& rhs_matcher);
Matcher<Node*> IsNumberShiftRightLogical(const Matcher<Node*>& lhs_matcher,
const Matcher<Node*>& rhs_matcher);
+Matcher<Node*> IsNumberImul(const Matcher<Node*>& lhs_matcher,
+ const Matcher<Node*>& rhs_matcher);
Matcher<Node*> IsAllocate(const Matcher<Node*>& size_matcher,
const Matcher<Node*>& effect_matcher,
const Matcher<Node*>& control_matcher);
@@ -261,10 +263,13 @@
const Matcher<Node*>& value_matcher,
const Matcher<Node*>& effect_matcher,
const Matcher<Node*>& control_matcher);
+Matcher<Node*> IsStackSlot(const Matcher<MachineRepresentation>& rep_matcher);
Matcher<Node*> IsWord32And(const Matcher<Node*>& lhs_matcher,
const Matcher<Node*>& rhs_matcher);
Matcher<Node*> IsWord32Or(const Matcher<Node*>& lhs_matcher,
const Matcher<Node*>& rhs_matcher);
+Matcher<Node*> IsWord32Xor(const Matcher<Node*>& lhs_matcher,
+ const Matcher<Node*>& rhs_matcher);
Matcher<Node*> IsWord32Sar(const Matcher<Node*>& lhs_matcher,
const Matcher<Node*>& rhs_matcher);
Matcher<Node*> IsWord32Shl(const Matcher<Node*>& lhs_matcher,
@@ -276,6 +281,8 @@
Matcher<Node*> IsWord32Equal(const Matcher<Node*>& lhs_matcher,
const Matcher<Node*>& rhs_matcher);
Matcher<Node*> IsWord32Clz(const Matcher<Node*>& value_matcher);
+Matcher<Node*> IsWord32Ctz(const Matcher<Node*>& value_matcher);
+Matcher<Node*> IsWord32Popcnt(const Matcher<Node*>& value_matcher);
Matcher<Node*> IsWord64And(const Matcher<Node*>& lhs_matcher,
const Matcher<Node*>& rhs_matcher);
Matcher<Node*> IsWord64Or(const Matcher<Node*>& lhs_matcher,
@@ -356,6 +363,35 @@
Matcher<Node*> IsParameter(const Matcher<int> index_matcher);
Matcher<Node*> IsLoadFramePointer();
+Matcher<Node*> IsInt32PairAdd(const Matcher<Node*>& a_matcher,
+ const Matcher<Node*>& b_matcher,
+ const Matcher<Node*>& c_matcher,
+ const Matcher<Node*>& d_matcher);
+Matcher<Node*> IsInt32PairSub(const Matcher<Node*>& a_matcher,
+ const Matcher<Node*>& b_matcher,
+ const Matcher<Node*>& c_matcher,
+ const Matcher<Node*>& d_matcher);
+Matcher<Node*> IsInt32PairMul(const Matcher<Node*>& a_matcher,
+ const Matcher<Node*>& b_matcher,
+ const Matcher<Node*>& c_matcher,
+ const Matcher<Node*>& d_matcher);
+
+Matcher<Node*> IsWord32PairShl(const Matcher<Node*>& lhs_matcher,
+ const Matcher<Node*>& mid_matcher,
+ const Matcher<Node*>& rhs_matcher);
+Matcher<Node*> IsWord32PairShr(const Matcher<Node*>& lhs_matcher,
+ const Matcher<Node*>& mid_matcher,
+ const Matcher<Node*>& rhs_matcher);
+
+Matcher<Node*> IsWord32PairSar(const Matcher<Node*>& lhs_matcher,
+ const Matcher<Node*>& mid_matcher,
+ const Matcher<Node*>& rhs_matcher);
+
+Matcher<Node*> IsStackSlot();
+Matcher<Node*> IsGuard(const Matcher<Type*>& type_matcher,
+ const Matcher<Node*>& value_matcher,
+ const Matcher<Node*>& control_matcher);
+
} // namespace compiler
} // namespace internal
} // namespace v8
diff --git a/test/unittests/compiler/s390/OWNERS b/test/unittests/compiler/s390/OWNERS
new file mode 100644
index 0000000..eb007cb
--- /dev/null
+++ b/test/unittests/compiler/s390/OWNERS
@@ -0,0 +1,5 @@
+jyan@ca.ibm.com
+dstence@us.ibm.com
+joransiu@ca.ibm.com
+mbrandy@us.ibm.com
+michael_dawson@ca.ibm.com
diff --git a/test/unittests/compiler/s390/instruction-selector-s390-unittest.cc b/test/unittests/compiler/s390/instruction-selector-s390-unittest.cc
new file mode 100644
index 0000000..5fe72ee
--- /dev/null
+++ b/test/unittests/compiler/s390/instruction-selector-s390-unittest.cc
@@ -0,0 +1,11 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "test/unittests/compiler/instruction-selector-unittest.h"
+
+namespace v8 {
+namespace internal {
+namespace compiler {} // namespace compiler
+} // namespace internal
+} // namespace v8
diff --git a/test/unittests/compiler/scheduler-unittest.cc b/test/unittests/compiler/scheduler-unittest.cc
index 6cf0734..da77bdc 100644
--- a/test/unittests/compiler/scheduler-unittest.cc
+++ b/test/unittests/compiler/scheduler-unittest.cc
@@ -2,15 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "src/compiler/schedule.h"
#include "src/compiler/access-builder.h"
#include "src/compiler/common-operator.h"
-#include "src/compiler/graph.h"
#include "src/compiler/graph-visualizer.h"
+#include "src/compiler/graph.h"
#include "src/compiler/js-operator.h"
#include "src/compiler/node.h"
#include "src/compiler/opcodes.h"
#include "src/compiler/operator.h"
-#include "src/compiler/schedule.h"
#include "src/compiler/scheduler.h"
#include "src/compiler/simplified-operator.h"
#include "src/compiler/source-position.h"
@@ -136,6 +136,51 @@
ComputeAndVerifySchedule(13);
}
+TARGET_TEST_F(SchedulerTest, FloatingDeadDiamond1) {
+ Node* start = graph()->NewNode(common()->Start(1));
+ graph()->SetStart(start);
+
+ Node* p0 = graph()->NewNode(common()->Parameter(0), start);
+ Node* d1 = CreateDiamond(graph(), common(), p0);
+ USE(d1);
+ Node* ret = graph()->NewNode(common()->Return(), p0, start, start);
+ Node* end = graph()->NewNode(common()->End(1), ret);
+
+ graph()->SetEnd(end);
+
+ ComputeAndVerifySchedule(4);
+}
+
+TARGET_TEST_F(SchedulerTest, FloatingDeadDiamond2) {
+ Graph* g = graph();
+ Node* start = g->NewNode(common()->Start(1));
+ g->SetStart(start);
+
+ Node* n1 = g->NewNode(common()->Parameter(1), start);
+
+ Node* n2 = g->NewNode(common()->Branch(), n1, start);
+ Node* n3 = g->NewNode(common()->IfTrue(), n2);
+ Node* n4 = g->NewNode(common()->IfFalse(), n2);
+ Node* n5 = g->NewNode(common()->Int32Constant(-100));
+ Node* n6 = g->NewNode(common()->Return(), n5, start, n4);
+ Node* n7 = g->NewNode(common()->Int32Constant(0));
+ Node* n8 = g->NewNode(common()->Return(), n7, start, n3);
+ Node* n9 = g->NewNode(common()->End(2), n6, n8);
+
+ // Dead nodes
+ Node* n10 = g->NewNode(common()->Branch(), n1, n3);
+ Node* n11 = g->NewNode(common()->IfTrue(), n10);
+ Node* n12 = g->NewNode(common()->IfFalse(), n10);
+ Node* n13 = g->NewNode(common()->Merge(2), n11, n12);
+ Node* n14 =
+ g->NewNode(common()->Phi(MachineRepresentation::kWord32, 2), n1, n7, n13);
+
+ USE(n14);
+
+ g->SetEnd(n9);
+
+ ComputeAndVerifySchedule(10);
+}
TARGET_TEST_F(SchedulerTest, FloatingDiamond2) {
Node* start = graph()->NewNode(common()->Start(2));
diff --git a/test/unittests/compiler/select-lowering-unittest.cc b/test/unittests/compiler/select-lowering-unittest.cc
deleted file mode 100644
index 43cfd84..0000000
--- a/test/unittests/compiler/select-lowering-unittest.cc
+++ /dev/null
@@ -1,74 +0,0 @@
-// Copyright 2014 the V8 project authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "src/compiler/select-lowering.h"
-#include "test/unittests/compiler/graph-unittest.h"
-#include "test/unittests/compiler/node-test-utils.h"
-#include "testing/gmock-support.h"
-
-using testing::AllOf;
-using testing::Capture;
-using testing::CaptureEq;
-using testing::Not;
-
-namespace v8 {
-namespace internal {
-namespace compiler {
-
-class SelectLoweringTest : public GraphTest {
- public:
- SelectLoweringTest() : GraphTest(5), lowering_(graph(), common()) {}
-
- protected:
- Reduction Reduce(Node* node) { return lowering_.Reduce(node); }
-
- private:
- SelectLowering lowering_;
-};
-
-
-TEST_F(SelectLoweringTest, SelectWithSameConditions) {
- Node* const p0 = Parameter(0);
- Node* const p1 = Parameter(1);
- Node* const p2 = Parameter(2);
- Node* const p3 = Parameter(3);
- Node* const p4 = Parameter(4);
- Node* const s0 = graph()->NewNode(
- common()->Select(MachineRepresentation::kWord32), p0, p1, p2);
-
- Capture<Node*> branch;
- Capture<Node*> merge;
- {
- Reduction const r = Reduce(s0);
- ASSERT_TRUE(r.Changed());
- EXPECT_THAT(
- r.replacement(),
- IsPhi(
- MachineRepresentation::kWord32, p1, p2,
- AllOf(CaptureEq(&merge),
- IsMerge(IsIfTrue(CaptureEq(&branch)),
- IsIfFalse(AllOf(CaptureEq(&branch),
- IsBranch(p0, graph()->start())))))));
- }
- {
- Reduction const r = Reduce(graph()->NewNode(
- common()->Select(MachineRepresentation::kWord32), p0, p3, p4));
- ASSERT_TRUE(r.Changed());
- EXPECT_THAT(r.replacement(), IsPhi(MachineRepresentation::kWord32, p3, p4,
- CaptureEq(&merge)));
- }
- {
- // We must not reuse the diamond if it is reachable from either else/then
- // values of the Select, because the resulting graph can not be scheduled.
- Reduction const r = Reduce(graph()->NewNode(
- common()->Select(MachineRepresentation::kWord32), p0, s0, p0));
- ASSERT_TRUE(r.Changed());
- EXPECT_THAT(r.replacement(), IsPhi(MachineRepresentation::kWord32, s0, p0,
- Not(CaptureEq(&merge))));
- }
-}
-
-} // namespace compiler
-} // namespace internal
-} // namespace v8
diff --git a/test/unittests/compiler/zone-pool-unittest.cc b/test/unittests/compiler/zone-pool-unittest.cc
index 3bfde4b..47f1cc5 100644
--- a/test/unittests/compiler/zone-pool-unittest.cc
+++ b/test/unittests/compiler/zone-pool-unittest.cc
@@ -12,7 +12,7 @@
class ZonePoolTest : public TestWithIsolate {
public:
- ZonePoolTest() {}
+ ZonePoolTest() : zone_pool_(&allocator_) {}
protected:
ZonePool* zone_pool() { return &zone_pool_; }
@@ -38,6 +38,7 @@
}
private:
+ base::AccountingAllocator allocator_;
ZonePool zone_pool_;
base::RandomNumberGenerator rng;
};
diff --git a/test/unittests/heap/gc-idle-time-handler-unittest.cc b/test/unittests/heap/gc-idle-time-handler-unittest.cc
index 6413e36..99351b5 100644
--- a/test/unittests/heap/gc-idle-time-handler-unittest.cc
+++ b/test/unittests/heap/gc-idle-time-handler-unittest.cc
@@ -74,43 +74,6 @@
}
-TEST(GCIdleTimeHandler, EstimateMarkCompactTimeInitial) {
- size_t size = 100 * MB;
- size_t time = GCIdleTimeHandler::EstimateMarkCompactTime(size, 0);
- EXPECT_EQ(size / GCIdleTimeHandler::kInitialConservativeMarkCompactSpeed,
- time);
-}
-
-
-TEST(GCIdleTimeHandler, EstimateMarkCompactTimeNonZero) {
- size_t size = 100 * MB;
- size_t speed = 1 * MB;
- size_t time = GCIdleTimeHandler::EstimateMarkCompactTime(size, speed);
- EXPECT_EQ(size / speed, time);
-}
-
-
-TEST(GCIdleTimeHandler, EstimateMarkCompactTimeMax) {
- size_t size = std::numeric_limits<size_t>::max();
- size_t speed = 1;
- size_t time = GCIdleTimeHandler::EstimateMarkCompactTime(size, speed);
- EXPECT_EQ(GCIdleTimeHandler::kMaxMarkCompactTimeInMs, time);
-}
-
-
-TEST_F(GCIdleTimeHandlerTest, ShouldDoMarkCompact) {
- size_t idle_time_ms = GCIdleTimeHandler::kMaxScheduledIdleTime;
- EXPECT_TRUE(GCIdleTimeHandler::ShouldDoMarkCompact(idle_time_ms, 0, 0));
-}
-
-
-TEST_F(GCIdleTimeHandlerTest, DontDoMarkCompact) {
- size_t idle_time_ms = 1;
- EXPECT_FALSE(GCIdleTimeHandler::ShouldDoMarkCompact(
- idle_time_ms, kSizeOfObjects, kMarkingSpeed));
-}
-
-
TEST_F(GCIdleTimeHandlerTest, ShouldDoFinalIncrementalMarkCompact) {
size_t idle_time_ms = 16;
EXPECT_TRUE(GCIdleTimeHandler::ShouldDoFinalIncrementalMarkCompact(
diff --git a/test/unittests/heap/gc-tracer-unittest.cc b/test/unittests/heap/gc-tracer-unittest.cc
new file mode 100644
index 0000000..2bf4d03
--- /dev/null
+++ b/test/unittests/heap/gc-tracer-unittest.cc
@@ -0,0 +1,49 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <cmath>
+#include <limits>
+
+#include "src/heap/gc-tracer.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace v8 {
+namespace internal {
+
+TEST(GCTracer, AverageSpeed) {
+ RingBuffer<BytesAndDuration> buffer;
+ EXPECT_EQ(100 / 2,
+ GCTracer::AverageSpeed(buffer, MakeBytesAndDuration(100, 2), 0));
+ buffer.Push(MakeBytesAndDuration(100, 8));
+ EXPECT_EQ(100 / 2,
+ GCTracer::AverageSpeed(buffer, MakeBytesAndDuration(100, 2), 2));
+ EXPECT_EQ(200 / 10,
+ GCTracer::AverageSpeed(buffer, MakeBytesAndDuration(100, 2), 3));
+ const int max_speed = 1024 * MB;
+ buffer.Reset();
+ buffer.Push(MakeBytesAndDuration(max_speed, 0.5));
+ EXPECT_EQ(max_speed,
+ GCTracer::AverageSpeed(buffer, MakeBytesAndDuration(0, 0), 1));
+ const int min_speed = 1;
+ buffer.Reset();
+ buffer.Push(MakeBytesAndDuration(1, 10000));
+ EXPECT_EQ(min_speed,
+ GCTracer::AverageSpeed(buffer, MakeBytesAndDuration(0, 0), 1));
+ buffer.Reset();
+ int sum = 0;
+ for (int i = 0; i < buffer.kSize; i++) {
+ sum += i + 1;
+ buffer.Push(MakeBytesAndDuration(i + 1, 1));
+ }
+ EXPECT_EQ(
+ sum * 1.0 / buffer.kSize,
+ GCTracer::AverageSpeed(buffer, MakeBytesAndDuration(0, 0), buffer.kSize));
+ buffer.Push(MakeBytesAndDuration(100, 1));
+ EXPECT_EQ(
+ (sum * 1.0 - 1 + 100) / buffer.kSize,
+ GCTracer::AverageSpeed(buffer, MakeBytesAndDuration(0, 0), buffer.kSize));
+}
+
+} // namespace internal
+} // namespace v8
diff --git a/test/unittests/heap/scavenge-job-unittest.cc b/test/unittests/heap/scavenge-job-unittest.cc
index dbd463c..91abbb1 100644
--- a/test/unittests/heap/scavenge-job-unittest.cc
+++ b/test/unittests/heap/scavenge-job-unittest.cc
@@ -71,7 +71,7 @@
EXPECT_FALSE(ScavengeJob::ReachedIdleAllocationLimit(
scavenge_speed, expected_size - 1, kNewSpaceCapacity));
EXPECT_TRUE(ScavengeJob::ReachedIdleAllocationLimit(
- scavenge_speed, expected_size, kNewSpaceCapacity));
+ scavenge_speed, expected_size + 1, kNewSpaceCapacity));
}
diff --git a/test/unittests/heap/slot-set-unittest.cc b/test/unittests/heap/slot-set-unittest.cc
index 3761889..26a26f0 100644
--- a/test/unittests/heap/slot-set-unittest.cc
+++ b/test/unittests/heap/slot-set-unittest.cc
@@ -55,9 +55,9 @@
set.Iterate([](Address slot_address) {
uintptr_t intaddr = reinterpret_cast<uintptr_t>(slot_address);
if (intaddr % 3 == 0) {
- return SlotSet::KEEP_SLOT;
+ return KEEP_SLOT;
} else {
- return SlotSet::REMOVE_SLOT;
+ return REMOVE_SLOT;
}
});
@@ -139,5 +139,33 @@
}
}
+TEST(TypedSlotSet, Iterate) {
+ TypedSlotSet set(0);
+ const int kDelta = 10000001;
+ int added = 0;
+ for (uint32_t i = 0; i < TypedSlotSet::kMaxOffset; i += kDelta) {
+ SlotType type = static_cast<SlotType>(i % NUMBER_OF_SLOT_TYPES);
+ set.Insert(type, i);
+ ++added;
+ }
+ int iterated = 0;
+ set.Iterate([&iterated, kDelta](SlotType type, Address addr) {
+ uint32_t i = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(addr));
+ EXPECT_EQ(i % NUMBER_OF_SLOT_TYPES, static_cast<uint32_t>(type));
+ EXPECT_EQ(0, i % kDelta);
+ ++iterated;
+ return i % 2 == 0 ? KEEP_SLOT : REMOVE_SLOT;
+ });
+ EXPECT_EQ(added, iterated);
+ iterated = 0;
+ set.Iterate([&iterated](SlotType type, Address addr) {
+ uint32_t i = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(addr));
+ EXPECT_EQ(0, i % 2);
+ ++iterated;
+ return KEEP_SLOT;
+ });
+ EXPECT_EQ(added / 2, iterated);
+}
+
} // namespace internal
} // namespace v8
diff --git a/test/unittests/interpreter/bytecode-array-builder-unittest.cc b/test/unittests/interpreter/bytecode-array-builder-unittest.cc
index 839215f..255d836 100644
--- a/test/unittests/interpreter/bytecode-array-builder-unittest.cc
+++ b/test/unittests/interpreter/bytecode-array-builder-unittest.cc
@@ -139,7 +139,6 @@
builder.CompareOperation(Token::Value::EQ, reg)
.CompareOperation(Token::Value::NE, reg)
.CompareOperation(Token::Value::EQ_STRICT, reg)
- .CompareOperation(Token::Value::NE_STRICT, reg)
.CompareOperation(Token::Value::LT, reg)
.CompareOperation(Token::Value::GT, reg)
.CompareOperation(Token::Value::LTE, reg)
@@ -161,6 +160,21 @@
.JumpIfUndefined(&start)
.JumpIfNotHole(&start);
+ // Longer jumps with constant operands
+ BytecodeLabel end[8];
+ builder.Jump(&end[0])
+ .LoadTrue()
+ .JumpIfTrue(&end[1])
+ .LoadTrue()
+ .JumpIfFalse(&end[2])
+ .LoadLiteral(Smi::FromInt(0))
+ .JumpIfTrue(&end[3])
+ .LoadLiteral(Smi::FromInt(0))
+ .JumpIfFalse(&end[4])
+ .JumpIfNull(&end[5])
+ .JumpIfUndefined(&end[6])
+ .JumpIfNotHole(&end[7]);
+
// Perform an operation that returns boolean value to
// generate JumpIfTrue/False
builder.CompareOperation(Token::Value::EQ, reg)
@@ -205,11 +219,11 @@
builder.ForInPrepare(reg)
.ForInDone(reg, reg)
- .ForInNext(reg, reg, reg)
+ .ForInNext(reg, reg, reg, 1)
.ForInStep(reg);
builder.ForInPrepare(wide)
.ForInDone(reg, other)
- .ForInNext(wide, wide, wide)
+ .ForInNext(wide, wide, wide, 1024)
.ForInStep(reg);
// Wide constant pool loads
@@ -223,9 +237,13 @@
// Emit wide global load / store operations.
builder.LoadGlobal(name, 1024, TypeofMode::NOT_INSIDE_TYPEOF)
.LoadGlobal(name, 1024, TypeofMode::INSIDE_TYPEOF)
+ .LoadGlobal(name, 1024, TypeofMode::INSIDE_TYPEOF)
.StoreGlobal(name, 1024, LanguageMode::SLOPPY)
.StoreGlobal(wide_name, 1, LanguageMode::STRICT);
+ // Emit extra wide global load.
+ builder.LoadGlobal(name, 1024 * 1024, TypeofMode::NOT_INSIDE_TYPEOF);
+
// Emit wide load / store property operations.
builder.LoadNamedProperty(reg, wide_name, 0)
.LoadKeyedProperty(reg, 2056)
@@ -271,28 +289,44 @@
.BinaryOperation(Token::Value::ADD, reg)
.JumpIfFalse(&start);
- builder.Debugger();
+ // Intrinsics handled by the interpreter.
+ builder.CallRuntime(Runtime::kInlineIsArray, reg, 1)
+ .CallRuntime(Runtime::kInlineIsArray, wide, 1);
+ builder.Debugger();
+ for (size_t i = 0; i < arraysize(end); i++) {
+ builder.Bind(&end[i]);
+ }
builder.Return();
// Generate BytecodeArray.
Handle<BytecodeArray> the_array = builder.ToBytecodeArray();
CHECK_EQ(the_array->frame_size(),
- (builder.fixed_and_temporary_register_count() +
- builder.translation_register_count()) *
- kPointerSize);
+ builder.fixed_and_temporary_register_count() * kPointerSize);
// Build scorecard of bytecodes encountered in the BytecodeArray.
std::vector<int> scorecard(Bytecodes::ToByte(Bytecode::kLast) + 1);
+
Bytecode final_bytecode = Bytecode::kLdaZero;
int i = 0;
while (i < the_array->length()) {
uint8_t code = the_array->get(i);
scorecard[code] += 1;
final_bytecode = Bytecodes::FromByte(code);
- i += Bytecodes::Size(Bytecodes::FromByte(code));
+ OperandScale operand_scale = OperandScale::kSingle;
+ int prefix_offset = 0;
+ if (Bytecodes::IsPrefixScalingBytecode(final_bytecode)) {
+ operand_scale = Bytecodes::PrefixBytecodeToOperandScale(final_bytecode);
+ prefix_offset = 1;
+ code = the_array->get(i + 1);
+ final_bytecode = Bytecodes::FromByte(code);
+ }
+ i += prefix_offset + Bytecodes::Size(final_bytecode, operand_scale);
}
+ // Insert entry for illegal bytecode as this is never willingly emitted.
+ scorecard[Bytecodes::ToByte(Bytecode::kIllegal)] = 1;
+
// Check return occurs at the end and only once in the BytecodeArray.
CHECK_EQ(final_bytecode, Bytecode::kReturn);
CHECK_EQ(scorecard[Bytecodes::ToByte(final_bytecode)], 1);
@@ -330,7 +364,7 @@
TEST_F(BytecodeArrayBuilderTest, RegisterValues) {
int index = 1;
- uint8_t operand = static_cast<uint8_t>(-index);
+ int32_t operand = -index;
Register the_register(index);
CHECK_EQ(the_register.index(), index);
@@ -531,6 +565,12 @@
for (int i = 0; i < 63; i++) {
builder.Jump(&label4);
}
+
+ // Add padding to force wide backwards jumps.
+ for (int i = 0; i < 256; i++) {
+ builder.LoadTrue();
+ }
+
builder.BinaryOperation(Token::Value::ADD, reg).JumpIfFalse(&label4);
builder.BinaryOperation(Token::Value::ADD, reg).JumpIfTrue(&label3);
builder.CompareOperation(Token::Value::EQ, reg).JumpIfFalse(&label2);
@@ -546,51 +586,65 @@
// Ignore compare operation.
iterator.Advance();
CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfTrue);
+ CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
CHECK_EQ(iterator.GetImmediateOperand(0), -2);
iterator.Advance();
// Ignore compare operation.
iterator.Advance();
CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfFalse);
+ CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
CHECK_EQ(iterator.GetImmediateOperand(0), -2);
iterator.Advance();
// Ignore binary operation.
iterator.Advance();
CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfToBooleanTrue);
+ CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
CHECK_EQ(iterator.GetImmediateOperand(0), -2);
iterator.Advance();
// Ignore binary operation.
iterator.Advance();
CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfToBooleanFalse);
+ CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
CHECK_EQ(iterator.GetImmediateOperand(0), -2);
iterator.Advance();
for (int i = 0; i < 63; i++) {
CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump);
+ CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
CHECK_EQ(iterator.GetImmediateOperand(0), -i * 2 - 4);
iterator.Advance();
}
+ // Check padding to force wide backwards jumps.
+ for (int i = 0; i < 256; i++) {
+ CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaTrue);
+ iterator.Advance();
+ }
// Ignore binary operation.
iterator.Advance();
- CHECK_EQ(iterator.current_bytecode(),
- Bytecode::kJumpIfToBooleanFalseConstant);
- CHECK_EQ(Smi::cast(*iterator.GetConstantForIndexOperand(0))->value(), -132);
+ CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfToBooleanFalse);
+ CHECK_EQ(iterator.current_operand_scale(), OperandScale::kDouble);
+ CHECK_EQ(iterator.GetImmediateOperand(0), -389);
iterator.Advance();
// Ignore binary operation.
iterator.Advance();
- CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfToBooleanTrueConstant);
- CHECK_EQ(Smi::cast(*iterator.GetConstantForIndexOperand(0))->value(), -140);
+ CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfToBooleanTrue);
+ CHECK_EQ(iterator.current_operand_scale(), OperandScale::kDouble);
+ CHECK_EQ(iterator.GetImmediateOperand(0), -399);
iterator.Advance();
// Ignore compare operation.
iterator.Advance();
- CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfFalseConstant);
- CHECK_EQ(Smi::cast(*iterator.GetConstantForIndexOperand(0))->value(), -148);
+ CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfFalse);
+ CHECK_EQ(iterator.current_operand_scale(), OperandScale::kDouble);
+ CHECK_EQ(iterator.GetImmediateOperand(0), -409);
iterator.Advance();
// Ignore compare operation.
iterator.Advance();
- CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfTrueConstant);
- CHECK_EQ(Smi::cast(*iterator.GetConstantForIndexOperand(0))->value(), -156);
+ CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfTrue);
+ CHECK_EQ(iterator.current_operand_scale(), OperandScale::kDouble);
+ CHECK_EQ(iterator.GetImmediateOperand(0), -419);
iterator.Advance();
- CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpConstant);
- CHECK_EQ(Smi::cast(*iterator.GetConstantForIndexOperand(0))->value(), -160);
+ CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump);
+ CHECK_EQ(iterator.current_operand_scale(), OperandScale::kDouble);
+ CHECK_EQ(iterator.GetImmediateOperand(0), -425);
iterator.Advance();
CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn);
iterator.Advance();
@@ -652,6 +706,85 @@
CHECK(iterator.done());
}
+TEST_F(BytecodeArrayBuilderTest, OperandScales) {
+ CHECK_EQ(BytecodeArrayBuilder::OperandSizesToScale(OperandSize::kByte),
+ OperandScale::kSingle);
+ CHECK_EQ(BytecodeArrayBuilder::OperandSizesToScale(OperandSize::kShort),
+ OperandScale::kDouble);
+ CHECK_EQ(BytecodeArrayBuilder::OperandSizesToScale(OperandSize::kQuad),
+ OperandScale::kQuadruple);
+ CHECK_EQ(BytecodeArrayBuilder::OperandSizesToScale(
+ OperandSize::kShort, OperandSize::kShort, OperandSize::kShort,
+ OperandSize::kShort),
+ OperandScale::kDouble);
+ CHECK_EQ(BytecodeArrayBuilder::OperandSizesToScale(
+ OperandSize::kQuad, OperandSize::kShort, OperandSize::kShort,
+ OperandSize::kShort),
+ OperandScale::kQuadruple);
+ CHECK_EQ(BytecodeArrayBuilder::OperandSizesToScale(
+ OperandSize::kShort, OperandSize::kQuad, OperandSize::kShort,
+ OperandSize::kShort),
+ OperandScale::kQuadruple);
+ CHECK_EQ(BytecodeArrayBuilder::OperandSizesToScale(
+ OperandSize::kShort, OperandSize::kShort, OperandSize::kQuad,
+ OperandSize::kShort),
+ OperandScale::kQuadruple);
+ CHECK_EQ(BytecodeArrayBuilder::OperandSizesToScale(
+ OperandSize::kShort, OperandSize::kShort, OperandSize::kShort,
+ OperandSize::kQuad),
+ OperandScale::kQuadruple);
+}
+
+TEST_F(BytecodeArrayBuilderTest, SizesForSignOperands) {
+ CHECK(BytecodeArrayBuilder::SizeForSignedOperand(0) == OperandSize::kByte);
+ CHECK(BytecodeArrayBuilder::SizeForSignedOperand(kMaxInt8) ==
+ OperandSize::kByte);
+ CHECK(BytecodeArrayBuilder::SizeForSignedOperand(kMinInt8) ==
+ OperandSize::kByte);
+ CHECK(BytecodeArrayBuilder::SizeForSignedOperand(kMaxInt8 + 1) ==
+ OperandSize::kShort);
+ CHECK(BytecodeArrayBuilder::SizeForSignedOperand(kMinInt8 - 1) ==
+ OperandSize::kShort);
+ CHECK(BytecodeArrayBuilder::SizeForSignedOperand(kMaxInt16) ==
+ OperandSize::kShort);
+ CHECK(BytecodeArrayBuilder::SizeForSignedOperand(kMinInt16) ==
+ OperandSize::kShort);
+ CHECK(BytecodeArrayBuilder::SizeForSignedOperand(kMaxInt16 + 1) ==
+ OperandSize::kQuad);
+ CHECK(BytecodeArrayBuilder::SizeForSignedOperand(kMinInt16 - 1) ==
+ OperandSize::kQuad);
+ CHECK(BytecodeArrayBuilder::SizeForSignedOperand(kMaxInt) ==
+ OperandSize::kQuad);
+ CHECK(BytecodeArrayBuilder::SizeForSignedOperand(kMinInt) ==
+ OperandSize::kQuad);
+}
+
+TEST_F(BytecodeArrayBuilderTest, SizesForUnsignOperands) {
+ // int overloads
+ CHECK(BytecodeArrayBuilder::SizeForUnsignedOperand(0) == OperandSize::kByte);
+ CHECK(BytecodeArrayBuilder::SizeForUnsignedOperand(kMaxUInt8) ==
+ OperandSize::kByte);
+ CHECK(BytecodeArrayBuilder::SizeForUnsignedOperand(kMaxUInt8 + 1) ==
+ OperandSize::kShort);
+ CHECK(BytecodeArrayBuilder::SizeForUnsignedOperand(kMaxUInt16) ==
+ OperandSize::kShort);
+ CHECK(BytecodeArrayBuilder::SizeForUnsignedOperand(kMaxUInt16 + 1) ==
+ OperandSize::kQuad);
+ // size_t overloads
+ CHECK(BytecodeArrayBuilder::SizeForUnsignedOperand(static_cast<size_t>(0)) ==
+ OperandSize::kByte);
+ CHECK(BytecodeArrayBuilder::SizeForUnsignedOperand(
+ static_cast<size_t>(kMaxUInt8)) == OperandSize::kByte);
+ CHECK(BytecodeArrayBuilder::SizeForUnsignedOperand(
+ static_cast<size_t>(kMaxUInt8 + 1)) == OperandSize::kShort);
+ CHECK(BytecodeArrayBuilder::SizeForUnsignedOperand(
+ static_cast<size_t>(kMaxUInt16)) == OperandSize::kShort);
+ CHECK(BytecodeArrayBuilder::SizeForUnsignedOperand(
+ static_cast<size_t>(kMaxUInt16 + 1)) == OperandSize::kQuad);
+ CHECK(BytecodeArrayBuilder::SizeForUnsignedOperand(
+ static_cast<size_t>(kMaxUInt32)) == OperandSize::kQuad);
+}
+
} // namespace interpreter
} // namespace internal
} // namespace v8
diff --git a/test/unittests/interpreter/bytecode-array-iterator-unittest.cc b/test/unittests/interpreter/bytecode-array-iterator-unittest.cc
index f2dcd71..43c6caa 100644
--- a/test/unittests/interpreter/bytecode-array-iterator-unittest.cc
+++ b/test/unittests/interpreter/bytecode-array-iterator-unittest.cc
@@ -22,7 +22,7 @@
TEST_F(BytecodeArrayIteratorTest, IteratesBytecodeArray) {
// Use a builder to create an array with containing multiple bytecodes
// with 0, 1 and 2 operands.
- BytecodeArrayBuilder builder(isolate(), zone(), 3, 2, 0);
+ BytecodeArrayBuilder builder(isolate(), zone(), 3, 3, 0);
Factory* factory = isolate()->factory();
Handle<HeapObject> heap_num_0 = factory->NewHeapNumber(2.718);
Handle<HeapObject> heap_num_1 = factory->NewHeapNumber(2147483647);
@@ -31,9 +31,9 @@
Smi* smi_1 = Smi::FromInt(-65536);
Register reg_0(0);
Register reg_1(1);
- Register reg_2 = Register::FromParameterIndex(2, builder.parameter_count());
+ Register param = Register::FromParameterIndex(2, builder.parameter_count());
Handle<String> name = factory->NewStringFromStaticChars("abc");
- int name_index = 3;
+ int name_index = 2;
int feedback_slot = 97;
builder.LoadLiteral(heap_num_0)
@@ -43,67 +43,139 @@
.LoadLiteral(smi_1)
.LoadAccumulatorWithRegister(reg_0)
.LoadNamedProperty(reg_1, name, feedback_slot)
- .StoreAccumulatorInRegister(reg_2)
+ .StoreAccumulatorInRegister(param)
+ .CallRuntimeForPair(Runtime::kLoadLookupSlotForCall, param, 1, reg_0)
+ .ForInPrepare(reg_0)
.CallRuntime(Runtime::kLoadIC_Miss, reg_0, 1)
.Debugger()
+ .LoadGlobal(name, 0x10000000, TypeofMode::NOT_INSIDE_TYPEOF)
.Return();
// Test iterator sees the expected output from the builder.
BytecodeArrayIterator iterator(builder.ToBytecodeArray());
+ const int kPrefixByteSize = 1;
+ int offset = 0;
+
CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaConstant);
+ CHECK_EQ(iterator.current_offset(), offset);
+ CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
CHECK(iterator.GetConstantForIndexOperand(0).is_identical_to(heap_num_0));
CHECK(!iterator.done());
+ offset += Bytecodes::Size(Bytecode::kLdaConstant, OperandScale::kSingle);
iterator.Advance();
CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaConstant);
+ CHECK_EQ(iterator.current_offset(), offset);
+ CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
CHECK(iterator.GetConstantForIndexOperand(0).is_identical_to(heap_num_1));
CHECK(!iterator.done());
+ offset += Bytecodes::Size(Bytecode::kLdaConstant, OperandScale::kSingle);
iterator.Advance();
CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaZero);
+ CHECK_EQ(iterator.current_offset(), offset);
+ CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
CHECK(!iterator.done());
+ offset += Bytecodes::Size(Bytecode::kLdaZero, OperandScale::kSingle);
iterator.Advance();
- CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaSmi8);
+ CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaSmi);
+ CHECK_EQ(iterator.current_offset(), offset);
+ CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
CHECK_EQ(Smi::FromInt(iterator.GetImmediateOperand(0)), smi_0);
CHECK(!iterator.done());
+ offset += Bytecodes::Size(Bytecode::kLdaSmi, OperandScale::kSingle);
iterator.Advance();
- CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaConstant);
- CHECK_EQ(*iterator.GetConstantForIndexOperand(0), smi_1);
+ CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaSmi);
+ CHECK_EQ(iterator.current_offset(), offset);
+ CHECK_EQ(iterator.current_operand_scale(), OperandScale::kQuadruple);
+ CHECK_EQ(Smi::FromInt(iterator.GetImmediateOperand(0)), smi_1);
CHECK(!iterator.done());
+ offset += Bytecodes::Size(Bytecode::kLdaSmi, OperandScale::kQuadruple) +
+ kPrefixByteSize;
iterator.Advance();
CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdar);
+ CHECK_EQ(iterator.current_offset(), offset);
+ CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
CHECK_EQ(iterator.GetRegisterOperand(0).index(), reg_0.index());
CHECK(!iterator.done());
+ offset += Bytecodes::Size(Bytecode::kLdar, OperandScale::kSingle);
iterator.Advance();
CHECK_EQ(iterator.current_bytecode(), Bytecode::kLoadIC);
+ CHECK_EQ(iterator.current_offset(), offset);
+ CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
CHECK_EQ(iterator.GetRegisterOperand(0).index(), reg_1.index());
CHECK_EQ(iterator.GetIndexOperand(1), name_index);
CHECK_EQ(iterator.GetIndexOperand(2), feedback_slot);
CHECK(!iterator.done());
+ offset += Bytecodes::Size(Bytecode::kLoadIC, OperandScale::kSingle);
iterator.Advance();
CHECK_EQ(iterator.current_bytecode(), Bytecode::kStar);
- CHECK_EQ(iterator.GetRegisterOperand(0).index(), reg_2.index());
+ CHECK_EQ(iterator.current_offset(), offset);
+ CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
+ CHECK_EQ(iterator.GetRegisterOperand(0).index(), param.index());
+ CHECK_EQ(iterator.GetRegisterOperandRange(0), 1);
CHECK(!iterator.done());
+ offset += Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle);
+ iterator.Advance();
+
+ CHECK_EQ(iterator.current_bytecode(), Bytecode::kCallRuntimeForPair);
+ CHECK_EQ(iterator.current_offset(), offset);
+ CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
+ CHECK_EQ(iterator.GetRuntimeIdOperand(0), Runtime::kLoadLookupSlotForCall);
+ CHECK_EQ(iterator.GetRegisterOperand(1).index(), param.index());
+ CHECK_EQ(iterator.GetRegisterOperandRange(1), 1);
+ CHECK_EQ(iterator.GetRegisterCountOperand(2), 1);
+ CHECK_EQ(iterator.GetRegisterOperand(3).index(), reg_0.index());
+ CHECK_EQ(iterator.GetRegisterOperandRange(3), 2);
+ CHECK(!iterator.done());
+ offset +=
+ Bytecodes::Size(Bytecode::kCallRuntimeForPair, OperandScale::kSingle);
+ iterator.Advance();
+
+ CHECK_EQ(iterator.current_bytecode(), Bytecode::kForInPrepare);
+ CHECK_EQ(iterator.current_offset(), offset);
+ CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
+ CHECK_EQ(iterator.GetRegisterOperand(0).index(), reg_0.index());
+ CHECK_EQ(iterator.GetRegisterOperandRange(0), 3);
+ CHECK(!iterator.done());
+ offset += Bytecodes::Size(Bytecode::kForInPrepare, OperandScale::kSingle);
iterator.Advance();
CHECK_EQ(iterator.current_bytecode(), Bytecode::kCallRuntime);
- CHECK_EQ(static_cast<Runtime::FunctionId>(iterator.GetIndexOperand(0)),
+ CHECK_EQ(iterator.current_offset(), offset);
+ CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
+ CHECK_EQ(static_cast<Runtime::FunctionId>(iterator.GetRuntimeIdOperand(0)),
Runtime::kLoadIC_Miss);
CHECK_EQ(iterator.GetRegisterOperand(1).index(), reg_0.index());
CHECK_EQ(iterator.GetRegisterCountOperand(2), 1);
CHECK(!iterator.done());
+ offset += Bytecodes::Size(Bytecode::kCallRuntime, OperandScale::kSingle);
iterator.Advance();
CHECK_EQ(iterator.current_bytecode(), Bytecode::kDebugger);
+ CHECK_EQ(iterator.current_offset(), offset);
+ CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
CHECK(!iterator.done());
+ offset += Bytecodes::Size(Bytecode::kDebugger, OperandScale::kSingle);
+ iterator.Advance();
+
+ CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaGlobal);
+ CHECK_EQ(iterator.current_offset(), offset);
+ CHECK_EQ(iterator.current_operand_scale(), OperandScale::kQuadruple);
+ CHECK_EQ(iterator.current_bytecode_size(), 10);
+ CHECK_EQ(iterator.GetIndexOperand(1), 0x10000000);
+ offset += Bytecodes::Size(Bytecode::kLdaGlobal, OperandScale::kQuadruple) +
+ kPrefixByteSize;
iterator.Advance();
CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn);
+ CHECK_EQ(iterator.current_offset(), offset);
+ CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
CHECK(!iterator.done());
iterator.Advance();
CHECK(iterator.done());
diff --git a/test/unittests/interpreter/bytecode-register-allocator-unittest.cc b/test/unittests/interpreter/bytecode-register-allocator-unittest.cc
index ec29935..d4dc111 100644
--- a/test/unittests/interpreter/bytecode-register-allocator-unittest.cc
+++ b/test/unittests/interpreter/bytecode-register-allocator-unittest.cc
@@ -140,29 +140,6 @@
}
}
-TEST_F(TemporaryRegisterAllocatorTest, RangeAvoidsTranslationBoundary) {
- int boundary = RegisterTranslator::DistanceToTranslationWindow(Register(0));
- int limit = boundary + 64;
-
- for (int run_length = 2; run_length < 32; run_length += 7) {
- ZoneVector<int> run_starts(zone());
- for (int start = 0; start < limit; start += run_length) {
- int run_start =
- allocator()->PrepareForConsecutiveTemporaryRegisters(run_length);
- run_starts.push_back(run_start);
- for (int i = 0; i < run_length; i++) {
- allocator()->BorrowConsecutiveTemporaryRegister(run_start + i);
- }
- CHECK(run_start >= boundary || run_start + run_length <= boundary);
- }
- for (size_t batch = 0; batch < run_starts.size(); batch++) {
- for (int i = run_starts[batch]; i < run_starts[batch] + run_length; i++) {
- allocator()->ReturnTemporaryRegister(i);
- }
- }
- }
-}
-
TEST_F(TemporaryRegisterAllocatorTest, NotInRange) {
for (int i = 0; i < 10; i++) {
int reg = allocator()->BorrowTemporaryRegisterNotInRange(2, 5);
diff --git a/test/unittests/interpreter/bytecodes-unittest.cc b/test/unittests/interpreter/bytecodes-unittest.cc
index 212e029..b3554c3 100644
--- a/test/unittests/interpreter/bytecodes-unittest.cc
+++ b/test/unittests/interpreter/bytecodes-unittest.cc
@@ -14,28 +14,27 @@
namespace interpreter {
TEST(OperandConversion, Registers) {
- int register_count = Register::MaxRegisterIndex() + 1;
+ int register_count = 128;
int step = register_count / 7;
for (int i = 0; i < register_count; i += step) {
if (i <= kMaxInt8) {
- uint8_t operand0 = Register(i).ToOperand();
+ uint32_t operand0 = Register(i).ToOperand();
Register reg0 = Register::FromOperand(operand0);
CHECK_EQ(i, reg0.index());
}
- uint16_t operand1 = Register(i).ToWideOperand();
- Register reg1 = Register::FromWideOperand(operand1);
+ uint32_t operand1 = Register(i).ToOperand();
+ Register reg1 = Register::FromOperand(operand1);
CHECK_EQ(i, reg1.index());
- uint32_t operand2 = Register(i).ToRawOperand();
- Register reg2 = Register::FromRawOperand(operand2);
+ uint32_t operand2 = Register(i).ToOperand();
+ Register reg2 = Register::FromOperand(operand2);
CHECK_EQ(i, reg2.index());
}
for (int i = 0; i <= kMaxUInt8; i++) {
- uint8_t operand = static_cast<uint8_t>(i);
- Register reg = Register::FromOperand(operand);
- if (i > 0 && i < -kMinInt8) {
+ Register reg = Register::FromOperand(i);
+ if (i > 0) {
CHECK(reg.is_parameter());
} else {
CHECK(!reg.is_parameter());
@@ -51,7 +50,7 @@
int parameter_count = parameter_counts[p];
for (int i = 0; i < parameter_count; i++) {
Register r = Register::FromParameterIndex(i, parameter_count);
- uint8_t operand_value = r.ToOperand();
+ uint32_t operand_value = r.ToOperand();
Register s = Register::FromOperand(operand_value);
CHECK_EQ(i, s.ToParameterIndex(parameter_count));
}
@@ -59,8 +58,8 @@
}
TEST(OperandConversion, RegistersParametersNoOverlap) {
- int register_count = Register::MaxRegisterIndex() + 1;
- int parameter_count = Register::MaxParameterIndex() + 1;
+ int register_count = 128;
+ int parameter_count = 100;
int32_t register_space_size = base::bits::RoundUpToPowerOfTwo32(
static_cast<uint32_t>(register_count + parameter_count));
uint32_t range = static_cast<uint32_t>(register_space_size);
@@ -68,18 +67,33 @@
for (int i = 0; i < register_count; i += 1) {
Register r = Register(i);
- uint32_t operand = r.ToWideOperand();
- CHECK_LT(operand, operand_count.size());
- operand_count[operand] += 1;
- CHECK_EQ(operand_count[operand], 1);
+ int32_t operand = r.ToOperand();
+ uint8_t index = static_cast<uint8_t>(operand);
+ CHECK_LT(index, operand_count.size());
+ operand_count[index] += 1;
+ CHECK_EQ(operand_count[index], 1);
}
for (int i = 0; i < parameter_count; i += 1) {
Register r = Register::FromParameterIndex(i, parameter_count);
- uint32_t operand = r.ToWideOperand();
- CHECK_LT(operand, operand_count.size());
- operand_count[operand] += 1;
- CHECK_EQ(operand_count[operand], 1);
+ uint32_t operand = r.ToOperand();
+ uint8_t index = static_cast<uint8_t>(operand);
+ CHECK_LT(index, operand_count.size());
+ operand_count[index] += 1;
+ CHECK_EQ(operand_count[index], 1);
+ }
+}
+
+TEST(OperandScaling, ScalableAndNonScalable) {
+ for (OperandScale operand_scale = OperandScale::kSingle;
+ operand_scale <= OperandScale::kMaxValid;
+ operand_scale = Bytecodes::NextOperandScale(operand_scale)) {
+ int scale = static_cast<int>(operand_scale);
+ CHECK_EQ(Bytecodes::Size(Bytecode::kCallRuntime, operand_scale),
+ 1 + 2 + 2 * scale);
+ CHECK_EQ(Bytecodes::Size(Bytecode::kCreateObjectLiteral, operand_scale),
+ 1 + 2 * scale + 1);
+ CHECK_EQ(Bytecodes::Size(Bytecode::kTestIn, operand_scale), 1 + scale);
}
}
@@ -87,16 +101,11 @@
CHECK_EQ(Bytecodes::NumberOfRegisterOperands(Bytecode::kAdd), 1);
CHECK_EQ(Bytecodes::NumberOfRegisterOperands(Bytecode::kCall), 2);
CHECK_EQ(Bytecodes::NumberOfRegisterOperands(Bytecode::kCallRuntime), 1);
- CHECK_EQ(Bytecodes::NumberOfRegisterOperands(Bytecode::kCallRuntimeWide), 1);
CHECK_EQ(Bytecodes::NumberOfRegisterOperands(Bytecode::kCallRuntimeForPair),
2);
- CHECK_EQ(
- Bytecodes::NumberOfRegisterOperands(Bytecode::kCallRuntimeForPairWide),
- 2);
CHECK_EQ(Bytecodes::NumberOfRegisterOperands(Bytecode::kDeletePropertyStrict),
1);
CHECK_EQ(Bytecodes::NumberOfRegisterOperands(Bytecode::kForInPrepare), 1);
- CHECK_EQ(Bytecodes::NumberOfRegisterOperands(Bytecode::kForInPrepareWide), 1);
CHECK_EQ(Bytecodes::NumberOfRegisterOperands(Bytecode::kInc), 0);
CHECK_EQ(Bytecodes::NumberOfRegisterOperands(Bytecode::kJumpIfTrue), 0);
CHECK_EQ(Bytecodes::NumberOfRegisterOperands(Bytecode::kNew), 2);
@@ -116,11 +125,11 @@
}
TEST(Bytecodes, RegisterOperands) {
- CHECK(Bytecodes::IsRegisterOperandType(OperandType::kReg8));
- CHECK(Bytecodes::IsRegisterInputOperandType(OperandType::kReg8));
- CHECK(!Bytecodes::IsRegisterOutputOperandType(OperandType::kReg8));
- CHECK(!Bytecodes::IsRegisterInputOperandType(OperandType::kRegOut8));
- CHECK(Bytecodes::IsRegisterOutputOperandType(OperandType::kRegOut8));
+ CHECK(Bytecodes::IsRegisterOperandType(OperandType::kReg));
+ CHECK(Bytecodes::IsRegisterInputOperandType(OperandType::kReg));
+ CHECK(!Bytecodes::IsRegisterOutputOperandType(OperandType::kReg));
+ CHECK(!Bytecodes::IsRegisterInputOperandType(OperandType::kRegOut));
+ CHECK(Bytecodes::IsRegisterOutputOperandType(OperandType::kRegOut));
#define IS_REGISTER_OPERAND_TYPE(Name, _) \
CHECK(Bytecodes::IsRegisterOperandType(OperandType::k##Name));
@@ -155,16 +164,155 @@
#undef IS_NOT_REGISTER_INPUT_OPERAND_TYPE
}
-TEST(Bytecodes, DebugBreak) {
- for (uint32_t i = 0; i < Bytecodes::ToByte(Bytecode::kLast); i++) {
- Bytecode bytecode = Bytecodes::FromByte(i);
- Bytecode debugbreak = Bytecodes::GetDebugBreak(bytecode);
- if (!Bytecodes::IsDebugBreak(debugbreak)) {
- PrintF("Bytecode %s has no matching debug break with length %d\n",
- Bytecodes::ToString(bytecode), Bytecodes::Size(bytecode));
- CHECK(false);
- }
+TEST(Bytecodes, DebugBreakExistForEachBytecode) {
+ static const OperandScale kOperandScale = OperandScale::kSingle;
+#define CHECK_DEBUG_BREAK_SIZE(Name, ...) \
+ if (!Bytecodes::IsDebugBreak(Bytecode::k##Name) && \
+ !Bytecodes::IsPrefixScalingBytecode(Bytecode::k##Name)) { \
+ Bytecode debug_bytecode = Bytecodes::GetDebugBreak(Bytecode::k##Name); \
+ CHECK_EQ(Bytecodes::Size(Bytecode::k##Name, kOperandScale), \
+ Bytecodes::Size(debug_bytecode, kOperandScale)); \
}
+ BYTECODE_LIST(CHECK_DEBUG_BREAK_SIZE)
+#undef CHECK_DEBUG_BREAK_SIZE
+}
+
+TEST(Bytecodes, DecodeBytecodeAndOperands) {
+ struct BytecodesAndResult {
+ const uint8_t bytecode[32];
+ const size_t length;
+ int parameter_count;
+ const char* output;
+ };
+
+#define B(Name) static_cast<uint8_t>(Bytecode::k##Name)
+ const BytecodesAndResult cases[] = {
+ {{B(LdaSmi), 0x01}, 2, 0, " LdaSmi [1]"},
+ {{B(Wide), B(LdaSmi), 0xe8, 0x03}, 4, 0, " LdaSmi.Wide [1000]"},
+ {{B(ExtraWide), B(LdaSmi), 0xa0, 0x86, 0x01, 0x00},
+ 6,
+ 0,
+ "LdaSmi.ExtraWide [100000]"},
+ {{B(LdaSmi), 0xff}, 2, 0, " LdaSmi [-1]"},
+ {{B(Wide), B(LdaSmi), 0x18, 0xfc}, 4, 0, " LdaSmi.Wide [-1000]"},
+ {{B(ExtraWide), B(LdaSmi), 0x60, 0x79, 0xfe, 0xff},
+ 6,
+ 0,
+ "LdaSmi.ExtraWide [-100000]"},
+ {{B(Star), 0xfb}, 2, 0, " Star r5"},
+ {{B(Wide), B(Star), 0x78, 0xff}, 4, 0, " Star.Wide r136"},
+ {{B(Wide), B(Call), 0x7a, 0xff, 0x79, 0xff, 0x02, 0x00, 0xb1, 0x00},
+ 10,
+ 0,
+ "Call.Wide r134, r135, #2, [177]"},
+ {{B(Ldar),
+ static_cast<uint8_t>(Register::FromParameterIndex(2, 3).ToOperand())},
+ 2,
+ 3,
+ " Ldar a1"},
+ {{B(Wide), B(CreateObjectLiteral), 0x01, 0x02, 0x03, 0x04, 0xa5},
+ 7,
+ 0,
+ "CreateObjectLiteral.Wide [513], [1027], #165"},
+ {{B(ExtraWide), B(JumpIfNull), 0x15, 0xcd, 0x5b, 0x07},
+ 6,
+ 0,
+ "JumpIfNull.ExtraWide [123456789]"},
+ };
+#undef B
+
+ for (size_t i = 0; i < arraysize(cases); ++i) {
+ // Generate reference string by prepending formatted bytes.
+ std::stringstream expected_ss;
+ std::ios default_format(nullptr);
+ default_format.copyfmt(expected_ss);
+ // Match format of Bytecodes::Decode() for byte representations.
+ expected_ss.fill('0');
+ expected_ss.flags(std::ios::right | std::ios::hex);
+ for (size_t b = 0; b < cases[i].length; b++) {
+ expected_ss << std::setw(2) << static_cast<uint32_t>(cases[i].bytecode[b])
+ << ' ';
+ }
+ expected_ss.copyfmt(default_format);
+ expected_ss << cases[i].output;
+
+ // Generate decoded byte output.
+ std::stringstream actual_ss;
+ Bytecodes::Decode(actual_ss, cases[i].bytecode, cases[i].parameter_count);
+
+ // Compare.
+ CHECK_EQ(actual_ss.str(), expected_ss.str());
+ }
+}
+
+TEST(Bytecodes, DebugBreakForPrefixBytecodes) {
+ CHECK_EQ(Bytecode::kDebugBreakWide,
+ Bytecodes::GetDebugBreak(Bytecode::kWide));
+ CHECK_EQ(Bytecode::kDebugBreakExtraWide,
+ Bytecodes::GetDebugBreak(Bytecode::kExtraWide));
+}
+
+TEST(Bytecodes, PrefixMappings) {
+ Bytecode prefixes[] = {Bytecode::kWide, Bytecode::kExtraWide};
+ TRACED_FOREACH(Bytecode, prefix, prefixes) {
+ CHECK_EQ(prefix, Bytecodes::OperandScaleToPrefixBytecode(
+ Bytecodes::PrefixBytecodeToOperandScale(prefix)));
+ }
+}
+
+TEST(OperandScale, PrefixesScale) {
+ CHECK(Bytecodes::NextOperandScale(OperandScale::kSingle) ==
+ OperandScale::kDouble);
+ CHECK(Bytecodes::NextOperandScale(OperandScale::kDouble) ==
+ OperandScale::kQuadruple);
+ CHECK(Bytecodes::NextOperandScale(OperandScale::kQuadruple) ==
+ OperandScale::kInvalid);
+}
+
+TEST(OperandScale, PrefixesRequired) {
+ CHECK(!Bytecodes::OperandScaleRequiresPrefixBytecode(OperandScale::kSingle));
+ CHECK(Bytecodes::OperandScaleRequiresPrefixBytecode(OperandScale::kDouble));
+ CHECK(
+ Bytecodes::OperandScaleRequiresPrefixBytecode(OperandScale::kQuadruple));
+ CHECK(Bytecodes::OperandScaleToPrefixBytecode(OperandScale::kDouble) ==
+ Bytecode::kWide);
+ CHECK(Bytecodes::OperandScaleToPrefixBytecode(OperandScale::kQuadruple) ==
+ Bytecode::kExtraWide);
+}
+
+TEST(AccumulatorUse, LogicalOperators) {
+ CHECK_EQ(AccumulatorUse::kNone | AccumulatorUse::kRead,
+ AccumulatorUse::kRead);
+ CHECK_EQ(AccumulatorUse::kRead | AccumulatorUse::kWrite,
+ AccumulatorUse::kReadWrite);
+ CHECK_EQ(AccumulatorUse::kRead & AccumulatorUse::kReadWrite,
+ AccumulatorUse::kRead);
+ CHECK_EQ(AccumulatorUse::kRead & AccumulatorUse::kWrite,
+ AccumulatorUse::kNone);
+}
+
+TEST(AccumulatorUse, SampleBytecodes) {
+ CHECK(Bytecodes::ReadsAccumulator(Bytecode::kStar));
+ CHECK(!Bytecodes::WritesAccumulator(Bytecode::kStar));
+ CHECK_EQ(Bytecodes::GetAccumulatorUse(Bytecode::kStar),
+ AccumulatorUse::kRead);
+ CHECK(!Bytecodes::ReadsAccumulator(Bytecode::kLdar));
+ CHECK(Bytecodes::WritesAccumulator(Bytecode::kLdar));
+ CHECK_EQ(Bytecodes::GetAccumulatorUse(Bytecode::kLdar),
+ AccumulatorUse::kWrite);
+ CHECK(Bytecodes::ReadsAccumulator(Bytecode::kAdd));
+ CHECK(Bytecodes::WritesAccumulator(Bytecode::kAdd));
+ CHECK_EQ(Bytecodes::GetAccumulatorUse(Bytecode::kAdd),
+ AccumulatorUse::kReadWrite);
+}
+
+TEST(AccumulatorUse, AccumulatorUseToString) {
+ std::set<std::string> names;
+ names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kNone));
+ names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kRead));
+ names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kWrite));
+ names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kReadWrite));
+ CHECK_EQ(names.size(), 4);
}
} // namespace interpreter
diff --git a/test/unittests/interpreter/constant-array-builder-unittest.cc b/test/unittests/interpreter/constant-array-builder-unittest.cc
index b3ec5ff..7122437 100644
--- a/test/unittests/interpreter/constant-array-builder-unittest.cc
+++ b/test/unittests/interpreter/constant-array-builder-unittest.cc
@@ -19,79 +19,76 @@
ConstantArrayBuilderTest() {}
~ConstantArrayBuilderTest() override {}
- static const size_t kLowCapacity = ConstantArrayBuilder::kLowCapacity;
- static const size_t kMaxCapacity = ConstantArrayBuilder::kMaxCapacity;
+ static const size_t k8BitCapacity = ConstantArrayBuilder::k8BitCapacity;
+ static const size_t k16BitCapacity = ConstantArrayBuilder::k16BitCapacity;
};
-
STATIC_CONST_MEMBER_DEFINITION const size_t
- ConstantArrayBuilderTest::kMaxCapacity;
+ ConstantArrayBuilderTest::k16BitCapacity;
STATIC_CONST_MEMBER_DEFINITION const size_t
- ConstantArrayBuilderTest::kLowCapacity;
-
+ ConstantArrayBuilderTest::k8BitCapacity;
TEST_F(ConstantArrayBuilderTest, AllocateAllEntries) {
ConstantArrayBuilder builder(isolate(), zone());
- for (size_t i = 0; i < kMaxCapacity; i++) {
+ for (size_t i = 0; i < k16BitCapacity; i++) {
builder.Insert(handle(Smi::FromInt(static_cast<int>(i)), isolate()));
}
- CHECK_EQ(builder.size(), kMaxCapacity);
- for (size_t i = 0; i < kMaxCapacity; i++) {
+ CHECK_EQ(builder.size(), k16BitCapacity);
+ for (size_t i = 0; i < k16BitCapacity; i++) {
CHECK_EQ(Handle<Smi>::cast(builder.At(i))->value(), i);
}
}
-
TEST_F(ConstantArrayBuilderTest, AllocateEntriesWithIdx8Reservations) {
- for (size_t reserved = 1; reserved < kLowCapacity; reserved *= 3) {
+ for (size_t reserved = 1; reserved < k8BitCapacity; reserved *= 3) {
ConstantArrayBuilder builder(isolate(), zone());
for (size_t i = 0; i < reserved; i++) {
OperandSize operand_size = builder.CreateReservedEntry();
CHECK(operand_size == OperandSize::kByte);
}
- for (size_t i = 0; i < 2 * kLowCapacity; i++) {
+ for (size_t i = 0; i < 2 * k8BitCapacity; i++) {
Handle<Object> object = isolate()->factory()->NewNumberFromSize(i);
builder.Insert(object);
- if (i + reserved < kLowCapacity) {
- CHECK_LE(builder.size(), kLowCapacity);
+ if (i + reserved < k8BitCapacity) {
+ CHECK_LE(builder.size(), k8BitCapacity);
CHECK_EQ(builder.size(), i + 1);
CHECK(builder.At(i)->SameValue(*object));
} else {
- CHECK_GE(builder.size(), kLowCapacity);
+ CHECK_GE(builder.size(), k8BitCapacity);
CHECK_EQ(builder.size(), i + reserved + 1);
CHECK(builder.At(i + reserved)->SameValue(*object));
}
}
- CHECK_EQ(builder.size(), 2 * kLowCapacity + reserved);
+ CHECK_EQ(builder.size(), 2 * k8BitCapacity + reserved);
// Check reserved values represented by the hole.
for (size_t i = 0; i < reserved; i++) {
- Handle<Object> empty = builder.At(kLowCapacity - reserved + i);
+ Handle<Object> empty = builder.At(k8BitCapacity - reserved + i);
CHECK(empty->SameValue(isolate()->heap()->the_hole_value()));
}
// Commmit reserved entries with duplicates and check size does not change.
- DCHECK_EQ(reserved + 2 * kLowCapacity, builder.size());
+ DCHECK_EQ(reserved + 2 * k8BitCapacity, builder.size());
size_t duplicates_in_idx8_space =
- std::min(reserved, kLowCapacity - reserved);
+ std::min(reserved, k8BitCapacity - reserved);
for (size_t i = 0; i < duplicates_in_idx8_space; i++) {
builder.CommitReservedEntry(OperandSize::kByte,
isolate()->factory()->NewNumberFromSize(i));
- DCHECK_EQ(reserved + 2 * kLowCapacity, builder.size());
+ DCHECK_EQ(reserved + 2 * k8BitCapacity, builder.size());
}
// Check all committed values match expected (holes where
// duplicates_in_idx8_space allocated).
- for (size_t i = 0; i < kLowCapacity - reserved; i++) {
+ for (size_t i = 0; i < k8BitCapacity - reserved; i++) {
Smi* smi = Smi::FromInt(static_cast<int>(i));
CHECK(Handle<Smi>::cast(builder.At(i))->SameValue(smi));
}
- for (size_t i = kLowCapacity; i < 2 * kLowCapacity + reserved; i++) {
+ for (size_t i = k8BitCapacity; i < 2 * k8BitCapacity + reserved; i++) {
Smi* smi = Smi::FromInt(static_cast<int>(i - reserved));
CHECK(Handle<Smi>::cast(builder.At(i))->SameValue(smi));
}
for (size_t i = 0; i < reserved; i++) {
- size_t index = kLowCapacity - reserved + i;
+ size_t index = k8BitCapacity - reserved + i;
CHECK(builder.At(index)->IsTheHole());
}
@@ -102,20 +99,19 @@
}
for (size_t i = 0; i < duplicates_in_idx8_space; i++) {
Handle<Object> object =
- isolate()->factory()->NewNumberFromSize(2 * kLowCapacity + i);
+ isolate()->factory()->NewNumberFromSize(2 * k8BitCapacity + i);
size_t index = builder.CommitReservedEntry(OperandSize::kByte, object);
- CHECK_EQ(static_cast<int>(index), kLowCapacity - reserved + i);
+ CHECK_EQ(static_cast<int>(index), k8BitCapacity - reserved + i);
CHECK(builder.At(static_cast<int>(index))->SameValue(*object));
}
- CHECK_EQ(builder.size(), 2 * kLowCapacity + reserved);
+ CHECK_EQ(builder.size(), 2 * k8BitCapacity + reserved);
}
}
-
-TEST_F(ConstantArrayBuilderTest, AllocateEntriesWithIdx16Reservations) {
- for (size_t reserved = 1; reserved < kLowCapacity; reserved *= 3) {
+TEST_F(ConstantArrayBuilderTest, AllocateEntriesWithWideReservations) {
+ for (size_t reserved = 1; reserved < k8BitCapacity; reserved *= 3) {
ConstantArrayBuilder builder(isolate(), zone());
- for (size_t i = 0; i < kLowCapacity; i++) {
+ for (size_t i = 0; i < k8BitCapacity; i++) {
Handle<Object> object = isolate()->factory()->NewNumberFromSize(i);
builder.Insert(object);
CHECK(builder.At(i)->SameValue(*object));
@@ -124,20 +120,20 @@
for (size_t i = 0; i < reserved; i++) {
OperandSize operand_size = builder.CreateReservedEntry();
CHECK(operand_size == OperandSize::kShort);
- CHECK_EQ(builder.size(), kLowCapacity);
+ CHECK_EQ(builder.size(), k8BitCapacity);
}
for (size_t i = 0; i < reserved; i++) {
builder.DiscardReservedEntry(OperandSize::kShort);
- CHECK_EQ(builder.size(), kLowCapacity);
+ CHECK_EQ(builder.size(), k8BitCapacity);
}
for (size_t i = 0; i < reserved; i++) {
OperandSize operand_size = builder.CreateReservedEntry();
CHECK(operand_size == OperandSize::kShort);
Handle<Object> object = isolate()->factory()->NewNumberFromSize(i);
builder.CommitReservedEntry(operand_size, object);
- CHECK_EQ(builder.size(), kLowCapacity);
+ CHECK_EQ(builder.size(), k8BitCapacity);
}
- for (size_t i = kLowCapacity; i < kLowCapacity + reserved; i++) {
+ for (size_t i = k8BitCapacity; i < k8BitCapacity + reserved; i++) {
OperandSize operand_size = builder.CreateReservedEntry();
CHECK(operand_size == OperandSize::kShort);
Handle<Object> object = isolate()->factory()->NewNumberFromSize(i);
@@ -163,26 +159,40 @@
}
}
+TEST_F(ConstantArrayBuilderTest, ToLargeFixedArray) {
+ ConstantArrayBuilder builder(isolate(), zone());
+ static const size_t kNumberOfElements = 37373;
+ for (size_t i = 0; i < kNumberOfElements; i++) {
+ Handle<Object> object = isolate()->factory()->NewNumberFromSize(i);
+ builder.Insert(object);
+ CHECK(builder.At(i)->SameValue(*object));
+ }
+ Handle<FixedArray> constant_array = builder.ToFixedArray();
+ CHECK_EQ(constant_array->length(), kNumberOfElements);
+ for (size_t i = 0; i < kNumberOfElements; i++) {
+ CHECK(constant_array->get(static_cast<int>(i))->SameValue(*builder.At(i)));
+ }
+}
TEST_F(ConstantArrayBuilderTest, GapFilledWhenLowReservationCommitted) {
ConstantArrayBuilder builder(isolate(), zone());
- for (size_t i = 0; i < kLowCapacity; i++) {
+ for (size_t i = 0; i < k8BitCapacity; i++) {
OperandSize operand_size = builder.CreateReservedEntry();
CHECK(OperandSize::kByte == operand_size);
CHECK_EQ(builder.size(), 0);
}
- for (size_t i = 0; i < kLowCapacity; i++) {
+ for (size_t i = 0; i < k8BitCapacity; i++) {
Handle<Object> object = isolate()->factory()->NewNumberFromSize(i);
builder.Insert(object);
- CHECK_EQ(builder.size(), i + kLowCapacity + 1);
+ CHECK_EQ(builder.size(), i + k8BitCapacity + 1);
}
- for (size_t i = 0; i < kLowCapacity; i++) {
+ for (size_t i = 0; i < k8BitCapacity; i++) {
builder.CommitReservedEntry(OperandSize::kByte,
- builder.At(i + kLowCapacity));
- CHECK_EQ(builder.size(), 2 * kLowCapacity);
+ builder.At(i + k8BitCapacity));
+ CHECK_EQ(builder.size(), 2 * k8BitCapacity);
}
- for (size_t i = 0; i < kLowCapacity; i++) {
- Handle<Object> original = builder.At(kLowCapacity + i);
+ for (size_t i = 0; i < k8BitCapacity; i++) {
+ Handle<Object> original = builder.At(k8BitCapacity + i);
Handle<Object> duplicate = builder.At(i);
CHECK(original->SameValue(*duplicate));
Handle<Object> reference = isolate()->factory()->NewNumberFromSize(i);
@@ -190,33 +200,89 @@
}
}
-
TEST_F(ConstantArrayBuilderTest, GapNotFilledWhenLowReservationDiscarded) {
ConstantArrayBuilder builder(isolate(), zone());
- for (size_t i = 0; i < kLowCapacity; i++) {
+ for (size_t i = 0; i < k8BitCapacity; i++) {
OperandSize operand_size = builder.CreateReservedEntry();
CHECK(OperandSize::kByte == operand_size);
CHECK_EQ(builder.size(), 0);
}
- for (size_t i = 0; i < kLowCapacity; i++) {
+ for (size_t i = 0; i < k8BitCapacity; i++) {
Handle<Object> object = isolate()->factory()->NewNumberFromSize(i);
builder.Insert(object);
- CHECK_EQ(builder.size(), i + kLowCapacity + 1);
+ CHECK_EQ(builder.size(), i + k8BitCapacity + 1);
}
- for (size_t i = 0; i < kLowCapacity; i++) {
+ for (size_t i = 0; i < k8BitCapacity; i++) {
builder.DiscardReservedEntry(OperandSize::kByte);
- builder.Insert(builder.At(i + kLowCapacity));
- CHECK_EQ(builder.size(), 2 * kLowCapacity);
+ builder.Insert(builder.At(i + k8BitCapacity));
+ CHECK_EQ(builder.size(), 2 * k8BitCapacity);
}
- for (size_t i = 0; i < kLowCapacity; i++) {
+ for (size_t i = 0; i < k8BitCapacity; i++) {
Handle<Object> reference = isolate()->factory()->NewNumberFromSize(i);
- Handle<Object> original = builder.At(kLowCapacity + i);
+ Handle<Object> original = builder.At(k8BitCapacity + i);
CHECK(original->SameValue(*reference));
Handle<Object> duplicate = builder.At(i);
CHECK(duplicate->SameValue(*isolate()->factory()->the_hole_value()));
}
}
+TEST_F(ConstantArrayBuilderTest, HolesWithUnusedReservations) {
+ static int kNumberOfHoles = 128;
+ ConstantArrayBuilder builder(isolate(), zone());
+ for (int i = 0; i < kNumberOfHoles; ++i) {
+ CHECK_EQ(builder.CreateReservedEntry(), OperandSize::kByte);
+ }
+ for (int i = 0; i < 128; ++i) {
+ CHECK_EQ(builder.Insert(isolate()->factory()->NewNumber(i)), i);
+ }
+ CHECK_EQ(builder.Insert(isolate()->factory()->NewNumber(256)), 256);
+
+ Handle<FixedArray> constant_array = builder.ToFixedArray();
+ CHECK_EQ(constant_array->length(), 257);
+ for (int i = 128; i < 256; i++) {
+ CHECK(constant_array->get(i)->SameValue(
+ *isolate()->factory()->the_hole_value()));
+ }
+ CHECK(!constant_array->get(127)->SameValue(
+ *isolate()->factory()->the_hole_value()));
+ CHECK(!constant_array->get(256)->SameValue(
+ *isolate()->factory()->the_hole_value()));
+}
+
+TEST_F(ConstantArrayBuilderTest, ReservationsAtAllScales) {
+ ConstantArrayBuilder builder(isolate(), zone());
+ for (int i = 0; i < 256; i++) {
+ CHECK_EQ(builder.CreateReservedEntry(), OperandSize::kByte);
+ }
+ for (int i = 256; i < 65536; ++i) {
+ CHECK_EQ(builder.CreateReservedEntry(), OperandSize::kShort);
+ }
+ for (int i = 65536; i < 131072; ++i) {
+ CHECK_EQ(builder.CreateReservedEntry(), OperandSize::kQuad);
+ }
+ CHECK_EQ(builder.CommitReservedEntry(OperandSize::kByte,
+ isolate()->factory()->NewNumber(1)),
+ 0);
+ CHECK_EQ(builder.CommitReservedEntry(OperandSize::kShort,
+ isolate()->factory()->NewNumber(2)),
+ 256);
+ CHECK_EQ(builder.CommitReservedEntry(OperandSize::kQuad,
+ isolate()->factory()->NewNumber(3)),
+ 65536);
+ Handle<FixedArray> constant_array = builder.ToFixedArray();
+ CHECK_EQ(constant_array->length(), 65537);
+ int count = 1;
+ for (int i = 0; i < constant_array->length(); ++i) {
+ Handle<Object> expected;
+ if (i == 0 || i == 256 || i == 65536) {
+ expected = isolate()->factory()->NewNumber(count++);
+ } else {
+ expected = isolate()->factory()->the_hole_value();
+ }
+ CHECK(constant_array->get(i)->SameValue(*expected));
+ }
+}
+
} // namespace interpreter
} // namespace internal
} // namespace v8
diff --git a/test/unittests/interpreter/interpreter-assembler-unittest.cc b/test/unittests/interpreter/interpreter-assembler-unittest.cc
index 3375a6b..0106c57 100644
--- a/test/unittests/interpreter/interpreter-assembler-unittest.cc
+++ b/test/unittests/interpreter/interpreter-assembler-unittest.cc
@@ -62,6 +62,18 @@
: IsWord32Or(lhs_matcher, rhs_matcher);
}
+InterpreterAssemblerTest::InterpreterAssemblerForTest::
+ ~InterpreterAssemblerForTest() {
+ // Tests don't necessarily read and write accumulator but
+ // InterpreterAssembler checks accumulator uses.
+ if (Bytecodes::ReadsAccumulator(bytecode())) {
+ GetAccumulator();
+ }
+ if (Bytecodes::WritesAccumulator(bytecode())) {
+ SetAccumulator(nullptr);
+ }
+}
+
Matcher<Node*> InterpreterAssemblerTest::InterpreterAssemblerForTest::IsLoad(
const Matcher<LoadRepresentation>& rep_matcher,
const Matcher<Node*>& base_matcher, const Matcher<Node*>& index_matcher) {
@@ -77,24 +89,25 @@
}
Matcher<Node*>
-InterpreterAssemblerTest::InterpreterAssemblerForTest::IsBytecodeOperand(
+InterpreterAssemblerTest::InterpreterAssemblerForTest::IsUnsignedByteOperand(
int offset) {
return IsLoad(
MachineType::Uint8(),
IsParameter(InterpreterDispatchDescriptor::kBytecodeArrayParameter),
IsIntPtrAdd(
IsParameter(InterpreterDispatchDescriptor::kBytecodeOffsetParameter),
- IsInt32Constant(offset)));
+ IsIntPtrConstant(offset)));
}
-Matcher<Node*> InterpreterAssemblerTest::InterpreterAssemblerForTest::
- IsBytecodeOperandSignExtended(int offset) {
+Matcher<Node*>
+InterpreterAssemblerTest::InterpreterAssemblerForTest::IsSignedByteOperand(
+ int offset) {
Matcher<Node*> load_matcher = IsLoad(
MachineType::Int8(),
IsParameter(InterpreterDispatchDescriptor::kBytecodeArrayParameter),
IsIntPtrAdd(
IsParameter(InterpreterDispatchDescriptor::kBytecodeOffsetParameter),
- IsInt32Constant(offset)));
+ IsIntPtrConstant(offset)));
if (kPointerSize == 8) {
load_matcher = IsChangeInt32ToInt64(load_matcher);
}
@@ -102,7 +115,7 @@
}
Matcher<Node*>
-InterpreterAssemblerTest::InterpreterAssemblerForTest::IsBytecodeOperandShort(
+InterpreterAssemblerTest::InterpreterAssemblerForTest::IsUnsignedShortOperand(
int offset) {
if (TargetSupportsUnalignedAccess()) {
return IsLoad(
@@ -111,36 +124,35 @@
IsIntPtrAdd(
IsParameter(
InterpreterDispatchDescriptor::kBytecodeOffsetParameter),
- IsInt32Constant(offset)));
+ IsIntPtrConstant(offset)));
} else {
- Matcher<Node*> first_byte = IsLoad(
- MachineType::Uint8(),
- IsParameter(InterpreterDispatchDescriptor::kBytecodeArrayParameter),
- IsIntPtrAdd(
- IsParameter(
- InterpreterDispatchDescriptor::kBytecodeOffsetParameter),
- IsInt32Constant(offset)));
- Matcher<Node*> second_byte = IsLoad(
- MachineType::Uint8(),
- IsParameter(InterpreterDispatchDescriptor::kBytecodeArrayParameter),
- IsIntPtrAdd(
- IsParameter(
- InterpreterDispatchDescriptor::kBytecodeOffsetParameter),
- IsInt32Constant(offset + 1)));
#if V8_TARGET_LITTLE_ENDIAN
- return IsWordOr(IsWordShl(second_byte, IsInt32Constant(kBitsPerByte)),
- first_byte);
+ const int kStep = -1;
+ const int kMsbOffset = 1;
#elif V8_TARGET_BIG_ENDIAN
- return IsWordOr(IsWordShl(first_byte, IsInt32Constant(kBitsPerByte)),
- second_byte);
+ const int kStep = 1;
+ const int kMsbOffset = 0;
#else
#error "Unknown Architecture"
#endif
+ Matcher<Node*> bytes[2];
+ for (int i = 0; i < static_cast<int>(arraysize(bytes)); i++) {
+ bytes[i] = IsLoad(
+ MachineType::Uint8(),
+ IsParameter(InterpreterDispatchDescriptor::kBytecodeArrayParameter),
+ IsIntPtrAdd(
+ IsParameter(
+ InterpreterDispatchDescriptor::kBytecodeOffsetParameter),
+ IsIntPtrConstant(offset + kMsbOffset + kStep * i)));
+ }
+ return IsWord32Or(IsWord32Shl(bytes[0], IsInt32Constant(kBitsPerByte)),
+ bytes[1]);
}
}
-Matcher<Node*> InterpreterAssemblerTest::InterpreterAssemblerForTest::
- IsBytecodeOperandShortSignExtended(int offset) {
+Matcher<Node*>
+InterpreterAssemblerTest::InterpreterAssemblerForTest::IsSignedShortOperand(
+ int offset) {
Matcher<Node*> load_matcher;
if (TargetSupportsUnalignedAccess()) {
load_matcher = IsLoad(
@@ -149,34 +161,29 @@
IsIntPtrAdd(
IsParameter(
InterpreterDispatchDescriptor::kBytecodeOffsetParameter),
- IsInt32Constant(offset)));
+ IsIntPtrConstant(offset)));
} else {
#if V8_TARGET_LITTLE_ENDIAN
- int hi_byte_offset = offset + 1;
- int lo_byte_offset = offset;
-
+ const int kStep = -1;
+ const int kMsbOffset = 1;
#elif V8_TARGET_BIG_ENDIAN
- int hi_byte_offset = offset;
- int lo_byte_offset = offset + 1;
+ const int kStep = 1;
+ const int kMsbOffset = 0;
#else
#error "Unknown Architecture"
#endif
- Matcher<Node*> hi_byte = IsLoad(
- MachineType::Int8(),
- IsParameter(InterpreterDispatchDescriptor::kBytecodeArrayParameter),
- IsIntPtrAdd(
- IsParameter(
- InterpreterDispatchDescriptor::kBytecodeOffsetParameter),
- IsInt32Constant(hi_byte_offset)));
- hi_byte = IsWord32Shl(hi_byte, IsInt32Constant(kBitsPerByte));
- Matcher<Node*> lo_byte = IsLoad(
- MachineType::Uint8(),
- IsParameter(InterpreterDispatchDescriptor::kBytecodeArrayParameter),
- IsIntPtrAdd(
- IsParameter(
- InterpreterDispatchDescriptor::kBytecodeOffsetParameter),
- IsInt32Constant(lo_byte_offset)));
- load_matcher = IsWord32Or(hi_byte, lo_byte);
+ Matcher<Node*> bytes[2];
+ for (int i = 0; i < static_cast<int>(arraysize(bytes)); i++) {
+ bytes[i] = IsLoad(
+ (i == 0) ? MachineType::Int8() : MachineType::Uint8(),
+ IsParameter(InterpreterDispatchDescriptor::kBytecodeArrayParameter),
+ IsIntPtrAdd(
+ IsParameter(
+ InterpreterDispatchDescriptor::kBytecodeOffsetParameter),
+ IsIntPtrConstant(offset + kMsbOffset + kStep * i)));
+ }
+ load_matcher = IsWord32Or(
+ IsWord32Shl(bytes[0], IsInt32Constant(kBitsPerByte)), bytes[1]);
}
if (kPointerSize == 8) {
@@ -185,6 +192,124 @@
return load_matcher;
}
+Matcher<Node*>
+InterpreterAssemblerTest::InterpreterAssemblerForTest::IsUnsignedQuadOperand(
+ int offset) {
+ if (TargetSupportsUnalignedAccess()) {
+ return IsLoad(
+ MachineType::Uint32(),
+ IsParameter(InterpreterDispatchDescriptor::kBytecodeArrayParameter),
+ IsIntPtrAdd(
+ IsParameter(
+ InterpreterDispatchDescriptor::kBytecodeOffsetParameter),
+ IsIntPtrConstant(offset)));
+ } else {
+#if V8_TARGET_LITTLE_ENDIAN
+ const int kStep = -1;
+ const int kMsbOffset = 3;
+#elif V8_TARGET_BIG_ENDIAN
+ const int kStep = 1;
+ const int kMsbOffset = 0;
+#else
+#error "Unknown Architecture"
+#endif
+ Matcher<Node*> bytes[4];
+ for (int i = 0; i < static_cast<int>(arraysize(bytes)); i++) {
+ bytes[i] = IsLoad(
+ MachineType::Uint8(),
+ IsParameter(InterpreterDispatchDescriptor::kBytecodeArrayParameter),
+ IsIntPtrAdd(
+ IsParameter(
+ InterpreterDispatchDescriptor::kBytecodeOffsetParameter),
+ IsIntPtrConstant(offset + kMsbOffset + kStep * i)));
+ }
+ return IsWord32Or(
+ IsWord32Shl(bytes[0], IsInt32Constant(3 * kBitsPerByte)),
+ IsWord32Or(
+ IsWord32Shl(bytes[1], IsInt32Constant(2 * kBitsPerByte)),
+ IsWord32Or(IsWord32Shl(bytes[2], IsInt32Constant(1 * kBitsPerByte)),
+ bytes[3])));
+ }
+}
+
+Matcher<Node*>
+InterpreterAssemblerTest::InterpreterAssemblerForTest::IsSignedQuadOperand(
+ int offset) {
+ Matcher<Node*> load_matcher;
+ if (TargetSupportsUnalignedAccess()) {
+ load_matcher = IsLoad(
+ MachineType::Int32(),
+ IsParameter(InterpreterDispatchDescriptor::kBytecodeArrayParameter),
+ IsIntPtrAdd(
+ IsParameter(
+ InterpreterDispatchDescriptor::kBytecodeOffsetParameter),
+ IsIntPtrConstant(offset)));
+ } else {
+#if V8_TARGET_LITTLE_ENDIAN
+ const int kStep = -1;
+ int kMsbOffset = 3;
+#elif V8_TARGET_BIG_ENDIAN
+ const int kStep = 1;
+ int kMsbOffset = 0;
+#else
+#error "Unknown Architecture"
+#endif
+ Matcher<Node*> bytes[4];
+ for (int i = 0; i < static_cast<int>(arraysize(bytes)); i++) {
+ bytes[i] = IsLoad(
+ (i == 0) ? MachineType::Int8() : MachineType::Uint8(),
+ IsParameter(InterpreterDispatchDescriptor::kBytecodeArrayParameter),
+ IsIntPtrAdd(
+ IsParameter(
+ InterpreterDispatchDescriptor::kBytecodeOffsetParameter),
+ IsIntPtrConstant(offset + kMsbOffset + kStep * i)));
+ }
+ load_matcher = IsWord32Or(
+ IsWord32Shl(bytes[0], IsInt32Constant(3 * kBitsPerByte)),
+ IsWord32Or(
+ IsWord32Shl(bytes[1], IsInt32Constant(2 * kBitsPerByte)),
+ IsWord32Or(IsWord32Shl(bytes[2], IsInt32Constant(1 * kBitsPerByte)),
+ bytes[3])));
+ }
+
+ if (kPointerSize == 8) {
+ load_matcher = IsChangeInt32ToInt64(load_matcher);
+ }
+ return load_matcher;
+}
+
+Matcher<Node*>
+InterpreterAssemblerTest::InterpreterAssemblerForTest::IsSignedOperand(
+ int offset, OperandSize operand_size) {
+ switch (operand_size) {
+ case OperandSize::kByte:
+ return IsSignedByteOperand(offset);
+ case OperandSize::kShort:
+ return IsSignedShortOperand(offset);
+ case OperandSize::kQuad:
+ return IsSignedQuadOperand(offset);
+ case OperandSize::kNone:
+ UNREACHABLE();
+ }
+ return nullptr;
+}
+
+Matcher<Node*>
+InterpreterAssemblerTest::InterpreterAssemblerForTest::IsUnsignedOperand(
+ int offset, OperandSize operand_size) {
+ switch (operand_size) {
+ case OperandSize::kByte:
+ return IsUnsignedByteOperand(offset);
+ case OperandSize::kShort:
+ return IsUnsignedShortOperand(offset);
+ case OperandSize::kQuad:
+ return IsUnsignedQuadOperand(offset);
+ case OperandSize::kNone:
+ UNREACHABLE();
+ }
+ return nullptr;
+}
+
TARGET_TEST_F(InterpreterAssemblerTest, Dispatch) {
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
InterpreterAssemblerForTest m(this, bytecode);
@@ -195,18 +320,22 @@
EXPECT_EQ(1, end->InputCount());
Node* tail_call_node = end->InputAt(0);
+ OperandScale operand_scale = OperandScale::kSingle;
Matcher<Node*> next_bytecode_offset_matcher = IsIntPtrAdd(
IsParameter(InterpreterDispatchDescriptor::kBytecodeOffsetParameter),
- IsInt32Constant(interpreter::Bytecodes::Size(bytecode)));
+ IsIntPtrConstant(
+ interpreter::Bytecodes::Size(bytecode, operand_scale)));
Matcher<Node*> target_bytecode_matcher = m.IsLoad(
MachineType::Uint8(),
IsParameter(InterpreterDispatchDescriptor::kBytecodeArrayParameter),
next_bytecode_offset_matcher);
+ if (kPointerSize == 8) {
+ target_bytecode_matcher = IsChangeUint32ToUint64(target_bytecode_matcher);
+ }
Matcher<Node*> code_target_matcher = m.IsLoad(
MachineType::Pointer(),
IsParameter(InterpreterDispatchDescriptor::kDispatchTableParameter),
- IsWord32Shl(target_bytecode_matcher,
- IsInt32Constant(kPointerSizeLog2)));
+ IsWordShl(target_bytecode_matcher, IsIntPtrConstant(kPointerSizeLog2)));
EXPECT_THAT(
tail_call_node,
@@ -230,7 +359,7 @@
TRACED_FOREACH(int, jump_offset, jump_offsets) {
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
InterpreterAssemblerForTest m(this, bytecode);
- m.Jump(m.Int32Constant(jump_offset));
+ m.Jump(m.IntPtrConstant(jump_offset));
Graph* graph = m.graph();
Node* end = graph->end();
EXPECT_EQ(1, end->InputCount());
@@ -238,14 +367,18 @@
Matcher<Node*> next_bytecode_offset_matcher = IsIntPtrAdd(
IsParameter(InterpreterDispatchDescriptor::kBytecodeOffsetParameter),
- IsInt32Constant(jump_offset));
+ IsIntPtrConstant(jump_offset));
Matcher<Node*> target_bytecode_matcher =
m.IsLoad(MachineType::Uint8(), _, next_bytecode_offset_matcher);
+ if (kPointerSize == 8) {
+ target_bytecode_matcher =
+ IsChangeUint32ToUint64(target_bytecode_matcher);
+ }
Matcher<Node*> code_target_matcher = m.IsLoad(
MachineType::Pointer(),
IsParameter(InterpreterDispatchDescriptor::kDispatchTableParameter),
- IsWord32Shl(target_bytecode_matcher,
- IsInt32Constant(kPointerSizeLog2)));
+ IsWordShl(target_bytecode_matcher,
+ IsIntPtrConstant(kPointerSizeLog2)));
EXPECT_THAT(
tail_call_node,
@@ -275,24 +408,29 @@
InterpreterAssemblerForTest m(this, bytecode);
Node* lhs = m.IntPtrConstant(0);
Node* rhs = m.IntPtrConstant(1);
- m.JumpIfWordEqual(lhs, rhs, m.Int32Constant(kJumpIfTrueOffset));
+ m.JumpIfWordEqual(lhs, rhs, m.IntPtrConstant(kJumpIfTrueOffset));
Graph* graph = m.graph();
Node* end = graph->end();
EXPECT_EQ(2, end->InputCount());
- int jump_offsets[] = {kJumpIfTrueOffset,
- interpreter::Bytecodes::Size(bytecode)};
+ OperandScale operand_scale = OperandScale::kSingle;
+ int jump_offsets[] = {kJumpIfTrueOffset, interpreter::Bytecodes::Size(
+ bytecode, operand_scale)};
for (int i = 0; i < static_cast<int>(arraysize(jump_offsets)); i++) {
Matcher<Node*> next_bytecode_offset_matcher = IsIntPtrAdd(
IsParameter(InterpreterDispatchDescriptor::kBytecodeOffsetParameter),
- IsInt32Constant(jump_offsets[i]));
+ IsIntPtrConstant(jump_offsets[i]));
Matcher<Node*> target_bytecode_matcher =
m.IsLoad(MachineType::Uint8(), _, next_bytecode_offset_matcher);
+ if (kPointerSize == 8) {
+ target_bytecode_matcher =
+ IsChangeUint32ToUint64(target_bytecode_matcher);
+ }
Matcher<Node*> code_target_matcher = m.IsLoad(
MachineType::Pointer(),
IsParameter(InterpreterDispatchDescriptor::kDispatchTableParameter),
- IsWord32Shl(target_bytecode_matcher,
- IsInt32Constant(kPointerSizeLog2)));
+ IsWordShl(target_bytecode_matcher,
+ IsIntPtrConstant(kPointerSizeLog2)));
EXPECT_THAT(
end->InputAt(i),
IsTailCall(
@@ -342,51 +480,55 @@
}
TARGET_TEST_F(InterpreterAssemblerTest, BytecodeOperand) {
+ static const OperandScale kOperandScales[] = {
+ OperandScale::kSingle, OperandScale::kDouble, OperandScale::kQuadruple};
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
- InterpreterAssemblerForTest m(this, bytecode);
- int number_of_operands = interpreter::Bytecodes::NumberOfOperands(bytecode);
- for (int i = 0; i < number_of_operands; i++) {
- int offset = interpreter::Bytecodes::GetOperandOffset(bytecode, i);
- switch (interpreter::Bytecodes::GetOperandType(bytecode, i)) {
- case interpreter::OperandType::kRegCount8:
- EXPECT_THAT(m.BytecodeOperandCount(i), m.IsBytecodeOperand(offset));
- break;
- case interpreter::OperandType::kIdx8:
- EXPECT_THAT(m.BytecodeOperandIdx(i), m.IsBytecodeOperand(offset));
- break;
- case interpreter::OperandType::kImm8:
- EXPECT_THAT(m.BytecodeOperandImm(i),
- m.IsBytecodeOperandSignExtended(offset));
- break;
- case interpreter::OperandType::kMaybeReg8:
- case interpreter::OperandType::kReg8:
- case interpreter::OperandType::kRegOut8:
- case interpreter::OperandType::kRegOutPair8:
- case interpreter::OperandType::kRegOutTriple8:
- case interpreter::OperandType::kRegPair8:
- EXPECT_THAT(m.BytecodeOperandReg(i),
- m.IsBytecodeOperandSignExtended(offset));
- break;
- case interpreter::OperandType::kRegCount16:
- EXPECT_THAT(m.BytecodeOperandCount(i),
- m.IsBytecodeOperandShort(offset));
- break;
- case interpreter::OperandType::kIdx16:
- EXPECT_THAT(m.BytecodeOperandIdx(i),
- m.IsBytecodeOperandShort(offset));
- break;
- case interpreter::OperandType::kMaybeReg16:
- case interpreter::OperandType::kReg16:
- case interpreter::OperandType::kRegOut16:
- case interpreter::OperandType::kRegOutPair16:
- case interpreter::OperandType::kRegOutTriple16:
- case interpreter::OperandType::kRegPair16:
- EXPECT_THAT(m.BytecodeOperandReg(i),
- m.IsBytecodeOperandShortSignExtended(offset));
- break;
- case interpreter::OperandType::kNone:
- UNREACHABLE();
- break;
+ TRACED_FOREACH(interpreter::OperandScale, operand_scale, kOperandScales) {
+ InterpreterAssemblerForTest m(this, bytecode, operand_scale);
+ int number_of_operands =
+ interpreter::Bytecodes::NumberOfOperands(bytecode);
+ for (int i = 0; i < number_of_operands; i++) {
+ int offset = interpreter::Bytecodes::GetOperandOffset(bytecode, i,
+ operand_scale);
+ OperandType operand_type =
+ interpreter::Bytecodes::GetOperandType(bytecode, i);
+ OperandSize operand_size =
+ Bytecodes::SizeOfOperand(operand_type, operand_scale);
+ switch (interpreter::Bytecodes::GetOperandType(bytecode, i)) {
+ case interpreter::OperandType::kRegCount:
+ EXPECT_THAT(m.BytecodeOperandCount(i),
+ m.IsUnsignedOperand(offset, operand_size));
+ break;
+ case interpreter::OperandType::kFlag8:
+ EXPECT_THAT(m.BytecodeOperandFlag(i),
+ m.IsUnsignedOperand(offset, operand_size));
+ break;
+ case interpreter::OperandType::kIdx:
+ EXPECT_THAT(m.BytecodeOperandIdx(i),
+ m.IsUnsignedOperand(offset, operand_size));
+ break;
+ case interpreter::OperandType::kImm: {
+ EXPECT_THAT(m.BytecodeOperandImm(i),
+ m.IsSignedOperand(offset, operand_size));
+ break;
+ }
+ case interpreter::OperandType::kMaybeReg:
+ case interpreter::OperandType::kReg:
+ case interpreter::OperandType::kRegOut:
+ case interpreter::OperandType::kRegOutPair:
+ case interpreter::OperandType::kRegOutTriple:
+ case interpreter::OperandType::kRegPair:
+ EXPECT_THAT(m.BytecodeOperandReg(i),
+ m.IsSignedOperand(offset, operand_size));
+ break;
+ case interpreter::OperandType::kRuntimeId:
+ EXPECT_THAT(m.BytecodeOperandRuntimeId(i),
+ m.IsUnsignedOperand(offset, operand_size));
+ break;
+ case interpreter::OperandType::kNone:
+ UNREACHABLE();
+ break;
+ }
}
}
}
@@ -394,12 +536,16 @@
TARGET_TEST_F(InterpreterAssemblerTest, GetSetAccumulator) {
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
+ if (!interpreter::Bytecodes::ReadsAccumulator(bytecode) ||
+ !interpreter::Bytecodes::WritesAccumulator(bytecode)) {
+ continue;
+ }
+
InterpreterAssemblerForTest m(this, bytecode);
// Should be incoming accumulator if not set.
EXPECT_THAT(
m.GetAccumulator(),
IsParameter(InterpreterDispatchDescriptor::kAccumulatorParameter));
-
// Should be set by SetAccumulator.
Node* accumulator_value_1 = m.Int32Constant(0xdeadbeef);
m.SetAccumulator(accumulator_value_1);
@@ -433,27 +579,27 @@
TARGET_TEST_F(InterpreterAssemblerTest, RegisterLocation) {
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
InterpreterAssemblerForTest m(this, bytecode);
- Node* reg_index_node = m.Int32Constant(44);
+ Node* reg_index_node = m.IntPtrConstant(44);
Node* reg_location_node = m.RegisterLocation(reg_index_node);
EXPECT_THAT(
reg_location_node,
IsIntPtrAdd(
IsParameter(InterpreterDispatchDescriptor::kRegisterFileParameter),
- IsWordShl(reg_index_node, IsInt32Constant(kPointerSizeLog2))));
+ IsWordShl(reg_index_node, IsIntPtrConstant(kPointerSizeLog2))));
}
}
TARGET_TEST_F(InterpreterAssemblerTest, LoadRegister) {
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
InterpreterAssemblerForTest m(this, bytecode);
- Node* reg_index_node = m.Int32Constant(44);
+ Node* reg_index_node = m.IntPtrConstant(44);
Node* load_reg_node = m.LoadRegister(reg_index_node);
EXPECT_THAT(
load_reg_node,
m.IsLoad(
MachineType::AnyTagged(),
IsParameter(InterpreterDispatchDescriptor::kRegisterFileParameter),
- IsWordShl(reg_index_node, IsInt32Constant(kPointerSizeLog2))));
+ IsWordShl(reg_index_node, IsIntPtrConstant(kPointerSizeLog2))));
}
}
@@ -461,7 +607,7 @@
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
InterpreterAssemblerForTest m(this, bytecode);
Node* store_value = m.Int32Constant(0xdeadbeef);
- Node* reg_index_node = m.Int32Constant(44);
+ Node* reg_index_node = m.IntPtrConstant(44);
Node* store_reg_node = m.StoreRegister(store_value, reg_index_node);
EXPECT_THAT(
store_reg_node,
@@ -469,7 +615,7 @@
StoreRepresentation(MachineRepresentation::kTagged,
kNoWriteBarrier),
IsParameter(InterpreterDispatchDescriptor::kRegisterFileParameter),
- IsWordShl(reg_index_node, IsInt32Constant(kPointerSizeLog2)),
+ IsWordShl(reg_index_node, IsIntPtrConstant(kPointerSizeLog2)),
store_value));
}
}
@@ -478,10 +624,12 @@
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
InterpreterAssemblerForTest m(this, bytecode);
Node* value = m.Int32Constant(44);
- EXPECT_THAT(m.SmiTag(value),
- IsWordShl(value, IsInt32Constant(kSmiShiftSize + kSmiTagSize)));
- EXPECT_THAT(m.SmiUntag(value),
- IsWordSar(value, IsInt32Constant(kSmiShiftSize + kSmiTagSize)));
+ EXPECT_THAT(
+ m.SmiTag(value),
+ IsWordShl(value, IsIntPtrConstant(kSmiShiftSize + kSmiTagSize)));
+ EXPECT_THAT(
+ m.SmiUntag(value),
+ IsWordSar(value, IsIntPtrConstant(kSmiShiftSize + kSmiTagSize)));
}
}
@@ -508,16 +656,16 @@
TARGET_TEST_F(InterpreterAssemblerTest, WordShl) {
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
InterpreterAssemblerForTest m(this, bytecode);
- Node* a = m.Int32Constant(0);
+ Node* a = m.IntPtrConstant(0);
Node* add = m.WordShl(a, 10);
- EXPECT_THAT(add, IsWordShl(a, IsInt32Constant(10)));
+ EXPECT_THAT(add, IsWordShl(a, IsIntPtrConstant(10)));
}
}
TARGET_TEST_F(InterpreterAssemblerTest, LoadConstantPoolEntry) {
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
InterpreterAssemblerForTest m(this, bytecode);
- Node* index = m.Int32Constant(2);
+ Node* index = m.IntPtrConstant(2);
Node* load_constant = m.LoadConstantPoolEntry(index);
Matcher<Node*> constant_pool_matcher = m.IsLoad(
MachineType::AnyTagged(),
@@ -528,23 +676,7 @@
m.IsLoad(MachineType::AnyTagged(), constant_pool_matcher,
IsIntPtrAdd(
IsIntPtrConstant(FixedArray::kHeaderSize - kHeapObjectTag),
- IsWordShl(index, IsInt32Constant(kPointerSizeLog2)))));
- }
-}
-
-TARGET_TEST_F(InterpreterAssemblerTest, LoadFixedArrayElement) {
- TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
- InterpreterAssemblerForTest m(this, bytecode);
- int index = 3;
- Node* fixed_array = m.IntPtrConstant(0xdeadbeef);
- Node* load_element = m.LoadFixedArrayElement(fixed_array, index);
- EXPECT_THAT(
- load_element,
- m.IsLoad(MachineType::AnyTagged(), fixed_array,
- IsIntPtrAdd(
- IsIntPtrConstant(FixedArray::kHeaderSize - kHeapObjectTag),
- IsWordShl(IsInt32Constant(index),
- IsInt32Constant(kPointerSizeLog2)))));
+ IsWordShl(index, IsIntPtrConstant(kPointerSizeLog2)))));
}
}
@@ -563,13 +695,13 @@
TARGET_TEST_F(InterpreterAssemblerTest, LoadContextSlot) {
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
InterpreterAssemblerForTest m(this, bytecode);
- Node* context = m.Int32Constant(1);
- Node* slot_index = m.Int32Constant(22);
+ Node* context = m.IntPtrConstant(1);
+ Node* slot_index = m.IntPtrConstant(22);
Node* load_context_slot = m.LoadContextSlot(context, slot_index);
Matcher<Node*> offset =
- IsIntPtrAdd(IsWordShl(slot_index, IsInt32Constant(kPointerSizeLog2)),
- IsInt32Constant(Context::kHeaderSize - kHeapObjectTag));
+ IsIntPtrAdd(IsWordShl(slot_index, IsIntPtrConstant(kPointerSizeLog2)),
+ IsIntPtrConstant(Context::kHeaderSize - kHeapObjectTag));
EXPECT_THAT(load_context_slot,
m.IsLoad(MachineType::AnyTagged(), context, offset));
}
@@ -578,14 +710,14 @@
TARGET_TEST_F(InterpreterAssemblerTest, StoreContextSlot) {
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
InterpreterAssemblerForTest m(this, bytecode);
- Node* context = m.Int32Constant(1);
- Node* slot_index = m.Int32Constant(22);
- Node* value = m.Int32Constant(100);
+ Node* context = m.IntPtrConstant(1);
+ Node* slot_index = m.IntPtrConstant(22);
+ Node* value = m.SmiConstant(Smi::FromInt(100));
Node* store_context_slot = m.StoreContextSlot(context, slot_index, value);
Matcher<Node*> offset =
- IsIntPtrAdd(IsWordShl(slot_index, IsInt32Constant(kPointerSizeLog2)),
- IsInt32Constant(Context::kHeaderSize - kHeapObjectTag));
+ IsIntPtrAdd(IsWordShl(slot_index, IsIntPtrConstant(kPointerSizeLog2)),
+ IsIntPtrConstant(Context::kHeaderSize - kHeapObjectTag));
EXPECT_THAT(store_context_slot,
m.IsStore(StoreRepresentation(MachineRepresentation::kTagged,
kFullWriteBarrier),
@@ -629,7 +761,7 @@
IsInt32Mul(function_id, IsInt32Constant(sizeof(Runtime::Function))));
Matcher<Node*> function_entry =
m.IsLoad(MachineType::Pointer(), function,
- IsInt32Constant(offsetof(Runtime::Function, entry)));
+ IsIntPtrConstant(offsetof(Runtime::Function, entry)));
Node* call_runtime = m.CallRuntimeN(function_id, context, first_arg,
arg_count, result_size);
diff --git a/test/unittests/interpreter/interpreter-assembler-unittest.h b/test/unittests/interpreter/interpreter-assembler-unittest.h
index 321c724..1ebdc77 100644
--- a/test/unittests/interpreter/interpreter-assembler-unittest.h
+++ b/test/unittests/interpreter/interpreter-assembler-unittest.h
@@ -23,10 +23,12 @@
class InterpreterAssemblerForTest final : public InterpreterAssembler {
public:
- InterpreterAssemblerForTest(InterpreterAssemblerTest* test,
- Bytecode bytecode)
- : InterpreterAssembler(test->isolate(), test->zone(), bytecode) {}
- ~InterpreterAssemblerForTest() override {}
+ InterpreterAssemblerForTest(
+ InterpreterAssemblerTest* test, Bytecode bytecode,
+ OperandScale operand_scale = OperandScale::kSingle)
+ : InterpreterAssembler(test->isolate(), test->zone(), bytecode,
+ operand_scale) {}
+ ~InterpreterAssemblerForTest() override;
Matcher<compiler::Node*> IsLoad(
const Matcher<compiler::LoadRepresentation>& rep_matcher,
@@ -38,10 +40,17 @@
const Matcher<compiler::Node*>& index_matcher,
const Matcher<compiler::Node*>& value_matcher);
- Matcher<compiler::Node*> IsBytecodeOperand(int offset);
- Matcher<compiler::Node*> IsBytecodeOperandSignExtended(int offset);
- Matcher<compiler::Node*> IsBytecodeOperandShort(int offset);
- Matcher<compiler::Node*> IsBytecodeOperandShortSignExtended(int offset);
+ Matcher<compiler::Node*> IsUnsignedByteOperand(int offset);
+ Matcher<compiler::Node*> IsSignedByteOperand(int offset);
+ Matcher<compiler::Node*> IsUnsignedShortOperand(int offset);
+ Matcher<compiler::Node*> IsSignedShortOperand(int offset);
+ Matcher<compiler::Node*> IsUnsignedQuadOperand(int offset);
+ Matcher<compiler::Node*> IsSignedQuadOperand(int offset);
+
+ Matcher<compiler::Node*> IsSignedOperand(int offset,
+ OperandSize operand_size);
+ Matcher<compiler::Node*> IsUnsignedOperand(int offset,
+ OperandSize operand_size);
using InterpreterAssembler::graph;
diff --git a/test/unittests/interpreter/register-translator-unittest.cc b/test/unittests/interpreter/register-translator-unittest.cc
deleted file mode 100644
index e9f65a6..0000000
--- a/test/unittests/interpreter/register-translator-unittest.cc
+++ /dev/null
@@ -1,260 +0,0 @@
-// Copyright 2014 the V8 project authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include <stack>
-
-#include "src/v8.h"
-
-#include "src/interpreter/register-translator.h"
-#include "src/isolate.h"
-#include "test/unittests/test-utils.h"
-
-namespace v8 {
-namespace internal {
-namespace interpreter {
-
-class RegisterTranslatorTest : public TestWithIsolateAndZone,
- private RegisterMover {
- public:
- RegisterTranslatorTest() : translator_(this), move_count_(0) {
- window_start_ =
- RegisterTranslator::DistanceToTranslationWindow(Register(0));
- window_width_ =
- Register::MaxRegisterIndexForByteOperand() - window_start_ + 1;
- }
-
- ~RegisterTranslatorTest() override {}
-
- bool PopMoveAndMatch(Register from, Register to) {
- if (!moves_.empty()) {
- CHECK(from.is_valid() && to.is_valid());
- const std::pair<Register, Register> top = moves_.top();
- moves_.pop();
- return top.first == from && top.second == to;
- } else {
- return false;
- }
- }
-
- int move_count() const { return move_count_; }
- RegisterTranslator* translator() { return &translator_; }
-
- int window_start() const { return window_start_; }
- int window_width() const { return window_width_; }
- int window_limit() const { return window_start_ + window_width_; }
-
- protected:
- static const char* const kBadOperandRegex;
-
- private:
- void MoveRegisterUntranslated(Register from, Register to) override {
- moves_.push(std::make_pair(from, to));
- move_count_++;
- }
-
- RegisterTranslator translator_;
- std::stack<std::pair<Register, Register>> moves_;
- int move_count_;
- int window_start_;
- int window_width_;
-};
-
-const char* const RegisterTranslatorTest::kBadOperandRegex =
- ".*OperandType::kReg8 \\|\\| .*OperandType::kRegOut8\\) && "
- "RegisterIsMovableToWindow.*";
-
-TEST_F(RegisterTranslatorTest, TestFrameSizeAdjustmentsForTranslationWindow) {
- EXPECT_EQ(0, RegisterTranslator::RegisterCountAdjustment(0, 0));
- EXPECT_EQ(0, RegisterTranslator::RegisterCountAdjustment(10, 10));
- EXPECT_EQ(window_width(),
- RegisterTranslator::RegisterCountAdjustment(173, 0));
- EXPECT_EQ(window_width(),
- RegisterTranslator::RegisterCountAdjustment(173, 137));
- EXPECT_EQ(window_width(),
- RegisterTranslator::RegisterCountAdjustment(173, 137));
- // TODO(oth): Add a kMaxParameters8 that derives this info from the frame.
- int param_limit = FLAG_enable_embedded_constant_pool ? 119 : 120;
- EXPECT_EQ(0, RegisterTranslator::RegisterCountAdjustment(0, param_limit));
- EXPECT_EQ(window_limit(),
- RegisterTranslator::RegisterCountAdjustment(0, 128));
- EXPECT_EQ(window_limit(),
- RegisterTranslator::RegisterCountAdjustment(0, 129));
- EXPECT_EQ(window_limit() - 32,
- RegisterTranslator::RegisterCountAdjustment(32, 129));
-}
-
-TEST_F(RegisterTranslatorTest, TestInTranslationWindow) {
- EXPECT_GE(window_start(), 0);
- EXPECT_FALSE(
- RegisterTranslator::InTranslationWindow(Register(window_start() - 1)));
- EXPECT_TRUE(RegisterTranslator::InTranslationWindow(
- Register(Register::MaxRegisterIndexForByteOperand())));
- EXPECT_FALSE(RegisterTranslator::InTranslationWindow(
- Register(Register::MaxRegisterIndexForByteOperand() + 1)));
- for (int index = window_start(); index < window_limit(); index += 1) {
- EXPECT_TRUE(RegisterTranslator::InTranslationWindow(Register(index)));
- }
-}
-
-TEST_F(RegisterTranslatorTest, FitsInReg8Operand) {
- EXPECT_GT(window_start(), 0);
- EXPECT_TRUE(RegisterTranslator::FitsInReg8Operand(
- Register::FromParameterIndex(0, 3)));
- EXPECT_TRUE(RegisterTranslator::FitsInReg8Operand(
- Register::FromParameterIndex(2, 3)));
- EXPECT_TRUE(RegisterTranslator::FitsInReg8Operand(Register(0)));
- EXPECT_TRUE(
- RegisterTranslator::FitsInReg8Operand(Register(window_start() - 1)));
- EXPECT_FALSE(RegisterTranslator::FitsInReg8Operand(Register(kMaxInt8)));
- EXPECT_FALSE(RegisterTranslator::FitsInReg8Operand(Register(kMaxInt8 + 1)));
- for (int index = window_start(); index < window_limit(); index += 1) {
- EXPECT_FALSE(RegisterTranslator::FitsInReg8Operand(Register(index)));
- }
-}
-
-TEST_F(RegisterTranslatorTest, FitsInReg16Operand) {
- EXPECT_GT(window_start(), 0);
- EXPECT_TRUE(RegisterTranslator::FitsInReg16Operand(
- Register::FromParameterIndex(0, 3)));
- EXPECT_TRUE(RegisterTranslator::FitsInReg16Operand(
- Register::FromParameterIndex(2, 3)));
- EXPECT_TRUE(RegisterTranslator::FitsInReg16Operand(
- Register::FromParameterIndex(0, 999)));
- EXPECT_TRUE(RegisterTranslator::FitsInReg16Operand(
- Register::FromParameterIndex(0, Register::MaxParameterIndex() + 1)));
- EXPECT_TRUE(RegisterTranslator::FitsInReg16Operand(Register(0)));
- EXPECT_TRUE(
- RegisterTranslator::FitsInReg16Operand(Register(window_start() - 1)));
- EXPECT_TRUE(RegisterTranslator::FitsInReg16Operand(Register(kMaxInt8 + 1)));
- EXPECT_TRUE(RegisterTranslator::FitsInReg16Operand(Register(kMaxInt8 + 2)));
- for (int index = 0; index <= kMaxInt16 - window_width(); index += 1) {
- EXPECT_TRUE(RegisterTranslator::FitsInReg16Operand(Register(index)));
- }
- for (int index = Register::MaxRegisterIndex() - window_width() + 1;
- index < Register::MaxRegisterIndex() + 2; index += 1) {
- EXPECT_FALSE(RegisterTranslator::FitsInReg16Operand(Register(index)));
- }
-}
-
-TEST_F(RegisterTranslatorTest, NoTranslationRequired) {
- Register window_reg(window_start());
- Register local_reg(57);
- uint32_t operands[] = {local_reg.ToRawOperand()};
- translator()->TranslateInputRegisters(Bytecode::kLdar, operands, 1);
- translator()->TranslateOutputRegisters();
- EXPECT_EQ(0, move_count());
-
- Register param_reg = Register::FromParameterIndex(129, 130);
- operands[0] = param_reg.ToRawOperand();
- translator()->TranslateInputRegisters(Bytecode::kAdd, operands, 1);
- translator()->TranslateOutputRegisters();
- EXPECT_EQ(0, move_count());
-}
-
-TEST_F(RegisterTranslatorTest, TranslationRequired) {
- Register window_reg(window_start());
- Register local_reg(137);
- Register local_reg_translated(local_reg.index() + window_width());
-
- uint32_t operands[] = {local_reg.ToRawOperand()};
- translator()->TranslateInputRegisters(Bytecode::kLdar, operands, 1);
- EXPECT_EQ(1, move_count());
- EXPECT_TRUE(PopMoveAndMatch(local_reg_translated, window_reg));
- translator()->TranslateOutputRegisters();
- EXPECT_EQ(1, move_count());
- EXPECT_FALSE(PopMoveAndMatch(window_reg, local_reg_translated));
-
- operands[0] = local_reg.ToRawOperand();
- translator()->TranslateInputRegisters(Bytecode::kStar, operands, 1);
- EXPECT_EQ(1, move_count());
- EXPECT_FALSE(PopMoveAndMatch(local_reg_translated, window_reg));
- translator()->TranslateOutputRegisters();
- EXPECT_EQ(2, move_count());
- EXPECT_TRUE(PopMoveAndMatch(window_reg, local_reg_translated));
-
- Register param_reg = Register::FromParameterIndex(0, 130);
- operands[0] = {param_reg.ToRawOperand()};
- translator()->TranslateInputRegisters(Bytecode::kLdar, operands, 1);
- EXPECT_EQ(3, move_count());
- EXPECT_TRUE(PopMoveAndMatch(param_reg, window_reg));
- translator()->TranslateOutputRegisters();
- EXPECT_EQ(3, move_count());
- EXPECT_FALSE(PopMoveAndMatch(window_reg, param_reg));
-
- operands[0] = {param_reg.ToRawOperand()};
- translator()->TranslateInputRegisters(Bytecode::kStar, operands, 1);
- EXPECT_EQ(3, move_count());
- EXPECT_FALSE(PopMoveAndMatch(local_reg_translated, window_reg));
- translator()->TranslateOutputRegisters();
- EXPECT_EQ(4, move_count());
- EXPECT_TRUE(PopMoveAndMatch(window_reg, param_reg));
-}
-
-TEST_F(RegisterTranslatorTest, RangeTranslation) {
- Register window0(window_start());
- Register window1(window_start() + 1);
- Register window2(window_start() + 2);
- uint32_t operands[3];
-
- // Bytecode::kNew with valid range operand.
- Register constructor0(0);
- Register args0(1);
- operands[0] = constructor0.ToRawOperand();
- operands[1] = args0.ToRawOperand();
- operands[2] = 1;
- translator()->TranslateInputRegisters(Bytecode::kNew, operands, 3);
- translator()->TranslateOutputRegisters();
- EXPECT_EQ(0, move_count());
-
- // Bytecode::kNewWide with valid range operand.
- Register constructor1(128);
- Register constructor1_translated(constructor1.index() + window_width());
- Register args1(129);
- Register args1_translated(args1.index() + window_width());
- operands[0] = constructor1.ToRawOperand();
- operands[1] = args1.ToRawOperand();
- operands[2] = 3;
- translator()->TranslateInputRegisters(Bytecode::kNewWide, operands, 3);
- translator()->TranslateOutputRegisters();
- EXPECT_EQ(0, move_count());
-}
-
-TEST_F(RegisterTranslatorTest, BadRange0) {
- // Bytecode::kNew with invalid range operand (kMaybeReg8).
- Register constructor1(128);
- Register args1(129);
- uint32_t operands[] = {constructor1.ToRawOperand(), args1.ToRawOperand(), 3};
- ASSERT_DEATH_IF_SUPPORTED(
- translator()->TranslateInputRegisters(Bytecode::kNew, operands, 3),
- kBadOperandRegex);
-}
-
-TEST_F(RegisterTranslatorTest, BadRange1) {
- // Bytecode::kForInPrepare with invalid range operand (kRegTriple8)
- Register for_in_state(160);
- Register for_in_state_translated(for_in_state.index() + window_width());
- uint32_t operands[] = {for_in_state.ToRawOperand()};
- ASSERT_DEATH_IF_SUPPORTED(translator()->TranslateInputRegisters(
- Bytecode::kForInPrepare, operands, 1),
- kBadOperandRegex);
-}
-
-TEST_F(RegisterTranslatorTest, BadRange2) {
- // Bytecode::kForInNext with invalid range operand (kRegPair8)
- Register receiver(192);
- Register receiver_translated(receiver.index() + window_width());
- Register index(193);
- Register index_translated(index.index() + window_width());
- Register cache_info_pair(194);
- Register cache_info_pair_translated(cache_info_pair.index() + window_width());
- uint32_t operands[] = {receiver.ToRawOperand(), index.ToRawOperand(),
- cache_info_pair.ToRawOperand()};
- ASSERT_DEATH_IF_SUPPORTED(
- translator()->TranslateInputRegisters(Bytecode::kForInNext, operands, 3),
- kBadOperandRegex);
-}
-
-} // namespace interpreter
-} // namespace internal
-} // namespace v8
diff --git a/test/unittests/interpreter/source-position-table-unittest.cc b/test/unittests/interpreter/source-position-table-unittest.cc
new file mode 100644
index 0000000..d62302a
--- /dev/null
+++ b/test/unittests/interpreter/source-position-table-unittest.cc
@@ -0,0 +1,84 @@
+// Copyright 2016 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "src/v8.h"
+
+#include "src/interpreter/source-position-table.h"
+#include "test/unittests/test-utils.h"
+
+namespace v8 {
+namespace internal {
+namespace interpreter {
+
+class SourcePositionTableTest : public TestWithIsolateAndZone {
+ public:
+ SourcePositionTableTest() {}
+ ~SourcePositionTableTest() override {}
+};
+
+// Some random offsets, mostly at 'suspicious' bit boundaries.
+static int offsets[] = {0, 1, 2, 3, 4, 30, 31, 32,
+ 33, 62, 63, 64, 65, 126, 127, 128,
+ 129, 250, 1000, 9999, 12000, 31415926};
+
+TEST_F(SourcePositionTableTest, EncodeStatement) {
+ SourcePositionTableBuilder builder(isolate(), zone());
+ for (int i = 0; i < arraysize(offsets); i++) {
+ builder.AddStatementPosition(offsets[i], offsets[i]);
+ }
+
+ // To test correctness, we rely on the assertions in ToSourcePositionTable().
+ // (Also below.)
+ CHECK(!builder.ToSourcePositionTable().is_null());
+}
+
+TEST_F(SourcePositionTableTest, EncodeStatementDuplicates) {
+ SourcePositionTableBuilder builder(isolate(), zone());
+ for (int i = 0; i < arraysize(offsets); i++) {
+ builder.AddStatementPosition(offsets[i], offsets[i]);
+ builder.AddStatementPosition(offsets[i], offsets[i] + 1);
+ }
+
+ // To test correctness, we rely on the assertions in ToSourcePositionTable().
+ // (Also below.)
+ CHECK(!builder.ToSourcePositionTable().is_null());
+}
+
+TEST_F(SourcePositionTableTest, EncodeExpression) {
+ SourcePositionTableBuilder builder(isolate(), zone());
+ for (int i = 0; i < arraysize(offsets); i++) {
+ builder.AddExpressionPosition(offsets[i], offsets[i]);
+ }
+ CHECK(!builder.ToSourcePositionTable().is_null());
+}
+
+TEST_F(SourcePositionTableTest, EncodeAscending) {
+ SourcePositionTableBuilder builder(isolate(), zone());
+
+ int accumulator = 0;
+ for (int i = 0; i < arraysize(offsets); i++) {
+ accumulator += offsets[i];
+ if (i % 2) {
+ builder.AddStatementPosition(accumulator, accumulator);
+ } else {
+ builder.AddExpressionPosition(accumulator, accumulator);
+ }
+ }
+
+ // Also test negative offsets:
+ for (int i = 0; i < arraysize(offsets); i++) {
+ accumulator -= offsets[i];
+ if (i % 2) {
+ builder.AddStatementPosition(accumulator, accumulator);
+ } else {
+ builder.AddExpressionPosition(accumulator, accumulator);
+ }
+ }
+
+ CHECK(!builder.ToSourcePositionTable().is_null());
+}
+
+} // namespace interpreter
+} // namespace internal
+} // namespace v8
diff --git a/test/unittests/runtime/runtime-interpreter-unittest.cc b/test/unittests/runtime/runtime-interpreter-unittest.cc
deleted file mode 100644
index c10ddcd..0000000
--- a/test/unittests/runtime/runtime-interpreter-unittest.cc
+++ /dev/null
@@ -1,73 +0,0 @@
-// Copyright 2015 the V8 project authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "src/v8.h"
-
-#include "src/factory.h"
-#include "src/heap/heap.h"
-#include "src/heap/heap-inl.h"
-#include "src/runtime/runtime.h"
-#include "test/unittests/test-utils.h"
-
-namespace v8 {
-namespace internal {
-namespace interpreter {
-
-class RuntimeInterpreterTest : public TestWithIsolateAndZone {
- public:
- typedef Object* (*RuntimeMethod)(int, Object**, Isolate*);
-
- RuntimeInterpreterTest() {}
- ~RuntimeInterpreterTest() override {}
-
- bool TestOperatorWithObjects(RuntimeMethod method, Handle<Object> lhs,
- Handle<Object> rhs, bool expected);
-};
-
-
-bool RuntimeInterpreterTest::TestOperatorWithObjects(RuntimeMethod method,
- Handle<Object> lhs,
- Handle<Object> rhs,
- bool expected) {
- Object* args_object[] = {*rhs, *lhs};
- Handle<Object> result =
- handle(method(2, &args_object[1], isolate()), isolate());
- CHECK(result->IsTrue() || result->IsFalse());
- return result->IsTrue() == expected;
-}
-
-
-TEST_F(RuntimeInterpreterTest, ToBoolean) {
- double quiet_nan = std::numeric_limits<double>::quiet_NaN();
- std::pair<Handle<Object>, bool> cases[] = {
- std::make_pair(isolate()->factory()->NewNumberFromInt(0), false),
- std::make_pair(isolate()->factory()->NewNumberFromInt(1), true),
- std::make_pair(isolate()->factory()->NewNumberFromInt(100), true),
- std::make_pair(isolate()->factory()->NewNumberFromInt(-1), true),
- std::make_pair(isolate()->factory()->NewNumber(7.7), true),
- std::make_pair(isolate()->factory()->NewNumber(0.00001), true),
- std::make_pair(isolate()->factory()->NewNumber(quiet_nan), false),
- std::make_pair(isolate()->factory()->NewHeapNumber(0.0), false),
- std::make_pair(isolate()->factory()->undefined_value(), false),
- std::make_pair(isolate()->factory()->null_value(), false),
- std::make_pair(isolate()->factory()->true_value(), true),
- std::make_pair(isolate()->factory()->false_value(), false),
- std::make_pair(isolate()->factory()->NewStringFromStaticChars(""), false),
- std::make_pair(isolate()->factory()->NewStringFromStaticChars("_"), true),
- };
-
- for (size_t i = 0; i < arraysize(cases); i++) {
- auto& value_expected_tuple = cases[i];
- Object* args_object[] = {*value_expected_tuple.first};
- Handle<Object> result = handle(
- Runtime_InterpreterToBoolean(1, &args_object[0], isolate()), isolate());
- CHECK(result->IsBoolean());
- CHECK_EQ(result->IsTrue(), value_expected_tuple.second);
- }
-}
-
-
-} // namespace interpreter
-} // namespace internal
-} // namespace v8
diff --git a/test/unittests/test-utils.h b/test/unittests/test-utils.h
index 78283bf..1342510 100644
--- a/test/unittests/test-utils.h
+++ b/test/unittests/test-utils.h
@@ -93,12 +93,13 @@
class TestWithZone : public virtual ::testing::Test {
public:
- TestWithZone() {}
+ TestWithZone() : zone_(&allocator_) {}
virtual ~TestWithZone();
Zone* zone() { return &zone_; }
private:
+ base::AccountingAllocator allocator_;
Zone zone_;
DISALLOW_COPY_AND_ASSIGN(TestWithZone);
@@ -107,12 +108,13 @@
class TestWithIsolateAndZone : public virtual TestWithIsolate {
public:
- TestWithIsolateAndZone() {}
+ TestWithIsolateAndZone() : zone_(&allocator_) {}
virtual ~TestWithIsolateAndZone();
Zone* zone() { return &zone_; }
private:
+ base::AccountingAllocator allocator_;
Zone zone_;
DISALLOW_COPY_AND_ASSIGN(TestWithIsolateAndZone);
diff --git a/test/unittests/unittests.gyp b/test/unittests/unittests.gyp
index 638fd84..003281b 100644
--- a/test/unittests/unittests.gyp
+++ b/test/unittests/unittests.gyp
@@ -83,7 +83,6 @@
'compiler/opcodes-unittest.cc',
'compiler/register-allocator-unittest.cc',
'compiler/schedule-unittest.cc',
- 'compiler/select-lowering-unittest.cc',
'compiler/scheduler-unittest.cc',
'compiler/scheduler-rpo-unittest.cc',
'compiler/simplified-operator-reducer-unittest.cc',
@@ -101,22 +100,23 @@
'interpreter/constant-array-builder-unittest.cc',
'interpreter/interpreter-assembler-unittest.cc',
'interpreter/interpreter-assembler-unittest.h',
- 'interpreter/register-translator-unittest.cc',
+ 'interpreter/source-position-table-unittest.cc',
'libplatform/default-platform-unittest.cc',
'libplatform/task-queue-unittest.cc',
'libplatform/worker-thread-unittest.cc',
'heap/bitmap-unittest.cc',
'heap/gc-idle-time-handler-unittest.cc',
+ 'heap/gc-tracer-unittest.cc',
'heap/memory-reducer-unittest.cc',
'heap/heap-unittest.cc',
'heap/scavenge-job-unittest.cc',
'heap/slot-set-unittest.cc',
'locked-queue-unittest.cc',
'run-all-unittests.cc',
- 'runtime/runtime-interpreter-unittest.cc',
'test-utils.h',
'test-utils.cc',
'wasm/ast-decoder-unittest.cc',
+ 'wasm/decoder-unittest.cc',
'wasm/encoder-unittest.cc',
'wasm/loop-assignment-analysis-unittest.cc',
'wasm/module-decoder-unittest.cc',
@@ -158,6 +158,11 @@
'compiler/ppc/instruction-selector-ppc-unittest.cc',
],
}],
+ ['v8_target_arch=="s390" or v8_target_arch=="s390x"', {
+ 'sources': [ ### gcmole(arch:s390) ###
+ 'compiler/s390/instruction-selector-s390-unittest.cc',
+ ],
+ }],
['OS=="aix"', {
'ldflags': [ '-Wl,-bbigtoc' ],
}],
diff --git a/test/unittests/unittests.status b/test/unittests/unittests.status
index 18201cd..40b5754 100644
--- a/test/unittests/unittests.status
+++ b/test/unittests/unittests.status
@@ -9,6 +9,8 @@
'WasmFunctionVerifyTest*': [SKIP],
'WasmDecoderTest.TableSwitch*': [SKIP],
'WasmDecoderTest.AllLoadMemCombinations': [SKIP],
+ 'AstDecoderTest.AllLoadMemCombinations': [SKIP],
+ 'AstDecoderTest.AllStoreMemCombinations': [SKIP],
+ 'Bytecodes.DecodeBytecodeAndOperands': [SKIP],
}], # 'byteorder == big'
-
]
diff --git a/test/unittests/wasm/ast-decoder-unittest.cc b/test/unittests/wasm/ast-decoder-unittest.cc
index 6721587..0b1b79e 100644
--- a/test/unittests/wasm/ast-decoder-unittest.cc
+++ b/test/unittests/wasm/ast-decoder-unittest.cc
@@ -55,51 +55,34 @@
Verify(kError, env, code, code + arraysize(code)); \
} while (false)
-#define VERIFY(...) \
- do { \
- static const byte code[] = {__VA_ARGS__}; \
- Verify(kSuccess, &env_v_i, code, code + sizeof(code)); \
+#define VERIFY(...) \
+ do { \
+ static const byte code[] = {__VA_ARGS__}; \
+ Verify(kSuccess, sigs.v_i(), code, code + sizeof(code)); \
} while (false)
-
-class WasmDecoderTest : public TestWithZone {
+class AstDecoderTest : public TestWithZone {
public:
- WasmDecoderTest() : TestWithZone(), sigs() {
- init_env(&env_i_i, sigs.i_i());
- init_env(&env_v_v, sigs.v_v());
- init_env(&env_v_i, sigs.v_i());
- init_env(&env_i_f, sigs.i_f());
- init_env(&env_i_d, sigs.i_d());
- init_env(&env_l_l, sigs.l_l());
- init_env(&env_f_ff, sigs.f_ff());
- init_env(&env_d_dd, sigs.d_dd());
- }
+ typedef std::pair<uint32_t, LocalType> LocalsDecl;
+ AstDecoderTest() : module(nullptr) {}
TestSignatures sigs;
+ ModuleEnv* module;
+ LocalDeclEncoder local_decls;
- FunctionEnv env_i_i;
- FunctionEnv env_v_v;
- FunctionEnv env_v_i;
- FunctionEnv env_i_f;
- FunctionEnv env_i_d;
- FunctionEnv env_l_l;
- FunctionEnv env_f_ff;
- FunctionEnv env_d_dd;
-
- static void init_env(FunctionEnv* env, FunctionSig* sig) {
- env->module = nullptr;
- env->sig = sig;
- env->local_i32_count = 0;
- env->local_i64_count = 0;
- env->local_f32_count = 0;
- env->local_f64_count = 0;
- env->SumLocals();
+ void AddLocals(LocalType type, uint32_t count) {
+ local_decls.AddLocals(count, type);
}
- // A wrapper around VerifyWasmCode() that renders a nice failure message.
- void Verify(ErrorCode expected, FunctionEnv* env, const byte* start,
+ // Preprends local variable declarations and renders nice error messages for
+ // verification failures.
+ void Verify(ErrorCode expected, FunctionSig* sig, const byte* start,
const byte* end) {
- TreeResult result = VerifyWasmCode(env, start, end);
+ local_decls.Prepend(&start, &end);
+ // Verify the code.
+ TreeResult result =
+ VerifyWasmCode(zone()->allocator(), module, sig, start, end);
+
if (result.error_code != expected) {
ptrdiff_t pc = result.error_pc - result.start;
ptrdiff_t pt = result.error_pt - result.start;
@@ -118,15 +101,15 @@
}
FATAL(str.str().c_str());
}
+
+ delete[] start; // local_decls.Prepend() allocated a new buffer.
}
void TestBinop(WasmOpcode opcode, FunctionSig* success) {
// op(local[0], local[1])
byte code[] = {static_cast<byte>(opcode), kExprGetLocal, 0, kExprGetLocal,
1};
- FunctionEnv env;
- init_env(&env, success);
- EXPECT_VERIFIES(&env, code);
+ EXPECT_VERIFIES(success, code);
// Try all combinations of return and parameter types.
for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
@@ -138,8 +121,7 @@
types[2] != success->GetParam(1)) {
// Test signature mismatch.
FunctionSig sig(1, 2, types);
- init_env(&env, &sig);
- EXPECT_FAILURE(&env, code);
+ EXPECT_FAILURE(&sig, code);
}
}
}
@@ -153,12 +135,10 @@
void TestUnop(WasmOpcode opcode, LocalType ret_type, LocalType param_type) {
// Return(op(local[0]))
byte code[] = {static_cast<byte>(opcode), kExprGetLocal, 0};
- FunctionEnv env;
{
LocalType types[] = {ret_type, param_type};
FunctionSig sig(1, 1, types);
- init_env(&env, &sig);
- EXPECT_VERIFIES(&env, code);
+ EXPECT_VERIFIES(&sig, code);
}
// Try all combinations of return and parameter types.
@@ -168,8 +148,7 @@
if (types[0] != ret_type || types[1] != param_type) {
// Test signature mismatch.
FunctionSig sig(1, 1, types);
- init_env(&env, &sig);
- EXPECT_FAILURE(&env, code);
+ EXPECT_FAILURE(&sig, code);
}
}
}
@@ -177,211 +156,164 @@
};
-static FunctionEnv CreateInt32FunctionEnv(FunctionSig* sig, int count) {
- FunctionEnv env;
- env.module = nullptr;
- env.sig = sig;
- env.local_i32_count = count;
- env.local_f64_count = 0;
- env.local_f32_count = 0;
- env.total_locals = static_cast<unsigned>(count + sig->parameter_count());
- return env;
-}
-
-
-TEST_F(WasmDecoderTest, Int8Const) {
+TEST_F(AstDecoderTest, Int8Const) {
byte code[] = {kExprI8Const, 0};
for (int i = -128; i < 128; i++) {
code[1] = static_cast<byte>(i);
- EXPECT_VERIFIES(&env_i_i, code);
+ EXPECT_VERIFIES(sigs.i_i(), code);
}
}
-
-TEST_F(WasmDecoderTest, EmptyFunction) {
+TEST_F(AstDecoderTest, EmptyFunction) {
byte code[] = {0};
- Verify(kSuccess, &env_v_v, code, code);
- Verify(kError, &env_i_i, code, code);
+ Verify(kSuccess, sigs.v_v(), code, code);
+ Verify(kError, sigs.i_i(), code, code);
}
-
-TEST_F(WasmDecoderTest, IncompleteIf1) {
+TEST_F(AstDecoderTest, IncompleteIf1) {
byte code[] = {kExprIf};
- EXPECT_FAILURE(&env_v_v, code);
- EXPECT_FAILURE(&env_i_i, code);
+ EXPECT_FAILURE(sigs.v_v(), code);
+ EXPECT_FAILURE(sigs.i_i(), code);
}
-
-TEST_F(WasmDecoderTest, IncompleteIf2) {
+TEST_F(AstDecoderTest, IncompleteIf2) {
byte code[] = {kExprIf, kExprI8Const, 0};
- EXPECT_FAILURE(&env_v_v, code);
- EXPECT_FAILURE(&env_i_i, code);
+ EXPECT_FAILURE(sigs.v_v(), code);
+ EXPECT_FAILURE(sigs.i_i(), code);
}
-
-TEST_F(WasmDecoderTest, Int8Const_fallthru) {
+TEST_F(AstDecoderTest, Int8Const_fallthru) {
byte code[] = {kExprI8Const, 0, kExprI8Const, 1};
- EXPECT_VERIFIES(&env_i_i, code);
+ EXPECT_VERIFIES(sigs.i_i(), code);
}
-
-TEST_F(WasmDecoderTest, Int32Const) {
- byte code[] = {kExprI32Const, 0, 0, 0, 0};
- int32_t* ptr = reinterpret_cast<int32_t*>(code + 1);
+TEST_F(AstDecoderTest, Int32Const) {
const int kInc = 4498211;
for (int32_t i = kMinInt; i < kMaxInt - kInc; i = i + kInc) {
- *ptr = i;
- EXPECT_VERIFIES(&env_i_i, code);
+ // TODO(binji): expand test for other sized int32s; 1 through 5 bytes.
+ byte code[] = {WASM_I32V(i)};
+ EXPECT_VERIFIES(sigs.i_i(), code);
}
}
-
-TEST_F(WasmDecoderTest, Int8Const_fallthru2) {
- byte code[] = {kExprI8Const, 0, kExprI32Const, 1, 2, 3, 4};
- EXPECT_VERIFIES(&env_i_i, code);
+TEST_F(AstDecoderTest, Int8Const_fallthru2) {
+ byte code[] = {WASM_I8(0), WASM_I32V_4(0x1122334)};
+ EXPECT_VERIFIES(sigs.i_i(), code);
}
-
-TEST_F(WasmDecoderTest, Int64Const) {
- byte code[] = {kExprI64Const, 0, 0, 0, 0, 0, 0, 0, 0};
- int64_t* ptr = reinterpret_cast<int64_t*>(code + 1);
+TEST_F(AstDecoderTest, Int64Const) {
const int kInc = 4498211;
for (int32_t i = kMinInt; i < kMaxInt - kInc; i = i + kInc) {
- *ptr = (static_cast<int64_t>(i) << 32) | i;
- EXPECT_VERIFIES(&env_l_l, code);
+ byte code[] = {WASM_I64V((static_cast<int64_t>(i) << 32) | i)};
+ EXPECT_VERIFIES(sigs.l_l(), code);
}
}
-
-TEST_F(WasmDecoderTest, Float32Const) {
+TEST_F(AstDecoderTest, Float32Const) {
byte code[] = {kExprF32Const, 0, 0, 0, 0};
float* ptr = reinterpret_cast<float*>(code + 1);
for (int i = 0; i < 30; i++) {
*ptr = i * -7.75f;
- EXPECT_VERIFIES(&env_f_ff, code);
+ EXPECT_VERIFIES(sigs.f_ff(), code);
}
}
-
-TEST_F(WasmDecoderTest, Float64Const) {
+TEST_F(AstDecoderTest, Float64Const) {
byte code[] = {kExprF64Const, 0, 0, 0, 0, 0, 0, 0, 0};
double* ptr = reinterpret_cast<double*>(code + 1);
for (int i = 0; i < 30; i++) {
*ptr = i * 33.45;
- EXPECT_VERIFIES(&env_d_dd, code);
+ EXPECT_VERIFIES(sigs.d_dd(), code);
}
}
-
-TEST_F(WasmDecoderTest, Int32Const_off_end) {
+TEST_F(AstDecoderTest, Int32Const_off_end) {
byte code[] = {kExprI32Const, 0xaa, 0xbb, 0xcc, 0x44};
for (int size = 1; size <= 4; size++) {
- Verify(kError, &env_i_i, code, code + size);
+ Verify(kError, sigs.i_i(), code, code + size);
}
}
-
-TEST_F(WasmDecoderTest, GetLocal0_param) {
- EXPECT_VERIFIES(&env_i_i, kCodeGetLocal0);
+TEST_F(AstDecoderTest, GetLocal0_param) {
+ EXPECT_VERIFIES(sigs.i_i(), kCodeGetLocal0);
}
-
-TEST_F(WasmDecoderTest, GetLocal0_local) {
- FunctionEnv env;
- init_env(&env, sigs.i_v());
- env.AddLocals(kAstI32, 1);
- EXPECT_VERIFIES(&env, kCodeGetLocal0);
+TEST_F(AstDecoderTest, GetLocal0_local) {
+ AddLocals(kAstI32, 1);
+ EXPECT_VERIFIES(sigs.i_v(), kCodeGetLocal0);
}
-
-TEST_F(WasmDecoderTest, GetLocal0_param_n) {
+TEST_F(AstDecoderTest, GetLocal0_param_n) {
FunctionSig* array[] = {sigs.i_i(), sigs.i_ii(), sigs.i_iii()};
for (size_t i = 0; i < arraysize(array); i++) {
- FunctionEnv env = CreateInt32FunctionEnv(array[i], 0);
- EXPECT_VERIFIES(&env, kCodeGetLocal0);
+ EXPECT_VERIFIES(array[i], kCodeGetLocal0);
}
}
-
-TEST_F(WasmDecoderTest, GetLocalN_local) {
+TEST_F(AstDecoderTest, GetLocalN_local) {
for (byte i = 1; i < 8; i++) {
- FunctionEnv env = CreateInt32FunctionEnv(sigs.i_v(), i);
+ AddLocals(kAstI32, 1);
for (byte j = 0; j < i; j++) {
byte code[] = {kExprGetLocal, j};
- EXPECT_VERIFIES(&env, code);
+ EXPECT_VERIFIES(sigs.i_v(), code);
}
}
}
-
-TEST_F(WasmDecoderTest, GetLocal0_fail_no_params) {
- FunctionEnv env = CreateInt32FunctionEnv(sigs.i_v(), 0);
-
- EXPECT_FAILURE(&env, kCodeGetLocal0);
+TEST_F(AstDecoderTest, GetLocal0_fail_no_params) {
+ EXPECT_FAILURE(sigs.i_v(), kCodeGetLocal0);
}
-
-TEST_F(WasmDecoderTest, GetLocal1_fail_no_locals) {
- EXPECT_FAILURE(&env_i_i, kCodeGetLocal1);
+TEST_F(AstDecoderTest, GetLocal1_fail_no_locals) {
+ EXPECT_FAILURE(sigs.i_i(), kCodeGetLocal1);
}
-
-TEST_F(WasmDecoderTest, GetLocal_off_end) {
+TEST_F(AstDecoderTest, GetLocal_off_end) {
static const byte code[] = {kExprGetLocal};
- EXPECT_FAILURE(&env_i_i, code);
+ EXPECT_FAILURE(sigs.i_i(), code);
}
+TEST_F(AstDecoderTest, GetLocal_varint) {
+ const int kMaxLocals = 8000000;
+ AddLocals(kAstI32, kMaxLocals);
-TEST_F(WasmDecoderTest, GetLocal_varint) {
- env_i_i.local_i32_count = 1000000000;
- env_i_i.total_locals += 1000000000;
-
- {
- static const byte code[] = {kExprGetLocal, 0xFF, 0x01};
- EXPECT_VERIFIES(&env_i_i, code);
- EXPECT_FAILURE(&env_i_f, code);
+ for (int index = 0; index < kMaxLocals; index = index * 11 + 5) {
+ EXPECT_VERIFIES_INLINE(sigs.i_i(), kExprGetLocal, U32V_1(index));
+ EXPECT_VERIFIES_INLINE(sigs.i_i(), kExprGetLocal, U32V_2(index));
+ EXPECT_VERIFIES_INLINE(sigs.i_i(), kExprGetLocal, U32V_3(index));
+ EXPECT_VERIFIES_INLINE(sigs.i_i(), kExprGetLocal, U32V_4(index));
}
- {
- static const byte code[] = {kExprGetLocal, 0xF0, 0x80, 0x01};
- EXPECT_VERIFIES(&env_i_i, code);
- EXPECT_FAILURE(&env_i_f, code);
- }
+ EXPECT_VERIFIES_INLINE(sigs.i_i(), kExprGetLocal, U32V_5(kMaxLocals - 1));
- {
- static const byte code[] = {kExprGetLocal, 0xF2, 0x81, 0x82, 0x01};
- EXPECT_VERIFIES(&env_i_i, code);
- EXPECT_FAILURE(&env_i_f, code);
- }
+ EXPECT_VERIFIES_INLINE(sigs.i_i(), kExprGetLocal, U32V_4(kMaxLocals - 1));
+ EXPECT_VERIFIES_INLINE(sigs.i_i(), kExprGetLocal, U32V_4(kMaxLocals));
+ EXPECT_FAILURE_INLINE(sigs.i_i(), kExprGetLocal, U32V_4(kMaxLocals + 1));
- {
- static const byte code[] = {kExprGetLocal, 0xF3, 0xA1, 0xB1, 0xC1, 0x01};
- EXPECT_VERIFIES(&env_i_i, code);
- EXPECT_FAILURE(&env_i_f, code);
- }
+ EXPECT_FAILURE_INLINE(sigs.i_v(), kExprGetLocal, U32V_4(kMaxLocals));
+ EXPECT_FAILURE_INLINE(sigs.i_v(), kExprGetLocal, U32V_4(kMaxLocals + 1));
}
-
-TEST_F(WasmDecoderTest, Binops_off_end) {
+TEST_F(AstDecoderTest, Binops_off_end) {
byte code1[] = {0}; // [opcode]
for (size_t i = 0; i < arraysize(kInt32BinopOpcodes); i++) {
code1[0] = kInt32BinopOpcodes[i];
- EXPECT_FAILURE(&env_i_i, code1);
+ EXPECT_FAILURE(sigs.i_i(), code1);
}
byte code3[] = {0, kExprGetLocal, 0}; // [opcode] [expr]
for (size_t i = 0; i < arraysize(kInt32BinopOpcodes); i++) {
code3[0] = kInt32BinopOpcodes[i];
- EXPECT_FAILURE(&env_i_i, code3);
+ EXPECT_FAILURE(sigs.i_i(), code3);
}
byte code4[] = {0, kExprGetLocal, 0, 0}; // [opcode] [expr] [opcode]
for (size_t i = 0; i < arraysize(kInt32BinopOpcodes); i++) {
code4[0] = kInt32BinopOpcodes[i];
code4[3] = kInt32BinopOpcodes[i];
- EXPECT_FAILURE(&env_i_i, code4);
+ EXPECT_FAILURE(sigs.i_i(), code4);
}
}
@@ -389,79 +321,68 @@
//===================================================================
//== Statements
//===================================================================
-TEST_F(WasmDecoderTest, Nop) {
+TEST_F(AstDecoderTest, Nop) {
static const byte code[] = {kExprNop};
- EXPECT_VERIFIES(&env_v_v, code);
+ EXPECT_VERIFIES(sigs.v_v(), code);
}
-
-TEST_F(WasmDecoderTest, SetLocal0_param) {
+TEST_F(AstDecoderTest, SetLocal0_param) {
static const byte code[] = {kExprSetLocal, 0, kExprI8Const, 0};
- EXPECT_VERIFIES(&env_i_i, code);
+ EXPECT_VERIFIES(sigs.i_i(), code);
}
-
-TEST_F(WasmDecoderTest, SetLocal0_local) {
+TEST_F(AstDecoderTest, SetLocal0_local) {
byte code[] = {kExprSetLocal, 0, kExprI8Const, 0};
- FunctionEnv env = CreateInt32FunctionEnv(sigs.i_v(), 1);
-
- EXPECT_VERIFIES(&env, code);
+ AddLocals(kAstI32, 1);
+ EXPECT_VERIFIES(sigs.i_v(), code);
}
-
-TEST_F(WasmDecoderTest, SetLocalN_local) {
+TEST_F(AstDecoderTest, SetLocalN_local) {
for (byte i = 1; i < 8; i++) {
- FunctionEnv env = CreateInt32FunctionEnv(sigs.i_v(), i);
+ AddLocals(kAstI32, 1);
for (byte j = 0; j < i; j++) {
byte code[] = {kExprSetLocal, j, kExprI8Const, i};
- EXPECT_VERIFIES(&env, code);
+ EXPECT_VERIFIES(sigs.v_v(), code);
}
}
}
-
-TEST_F(WasmDecoderTest, Block0) {
+TEST_F(AstDecoderTest, Block0) {
static const byte code[] = {kExprBlock, 0};
- EXPECT_VERIFIES(&env_v_v, code);
+ EXPECT_VERIFIES(sigs.v_v(), code);
}
-
-TEST_F(WasmDecoderTest, Block0_fallthru1) {
+TEST_F(AstDecoderTest, Block0_fallthru1) {
static const byte code[] = {kExprBlock, 0, kExprBlock, 0};
- EXPECT_VERIFIES(&env_v_v, code);
+ EXPECT_VERIFIES(sigs.v_v(), code);
}
-
-TEST_F(WasmDecoderTest, Block1) {
+TEST_F(AstDecoderTest, Block1) {
static const byte code[] = {kExprBlock, 1, kExprSetLocal, 0, kExprI8Const, 0};
- EXPECT_VERIFIES(&env_i_i, code);
+ EXPECT_VERIFIES(sigs.i_i(), code);
}
-
-TEST_F(WasmDecoderTest, Block0_fallthru2) {
+TEST_F(AstDecoderTest, Block0_fallthru2) {
static const byte code[] = {kExprBlock, 0, kExprSetLocal, 0, kExprI8Const, 0};
- EXPECT_VERIFIES(&env_i_i, code);
+ EXPECT_VERIFIES(sigs.i_i(), code);
}
-
-TEST_F(WasmDecoderTest, Block2) {
+TEST_F(AstDecoderTest, Block2) {
static const byte code[] = {kExprBlock, 2, // --
kExprSetLocal, 0, kExprI8Const, 0, // --
kExprSetLocal, 0, kExprI8Const, 0}; // --
- EXPECT_VERIFIES(&env_i_i, code);
+ EXPECT_VERIFIES(sigs.i_i(), code);
}
-
-TEST_F(WasmDecoderTest, Block2_fallthru) {
+TEST_F(AstDecoderTest, Block2_fallthru) {
static const byte code[] = {kExprBlock, 2, // --
kExprSetLocal, 0, kExprI8Const, 0, // --
kExprSetLocal, 0, kExprI8Const, 0, // --
kExprI8Const, 11}; // --
- EXPECT_VERIFIES(&env_i_i, code);
+ EXPECT_VERIFIES(sigs.i_i(), code);
}
-
-TEST_F(WasmDecoderTest, BlockN) {
+TEST_F(AstDecoderTest, BlockN) {
byte block[] = {kExprBlock, 2};
for (size_t i = 0; i < 10; i++) {
@@ -473,106 +394,91 @@
memcpy(code + sizeof(block) + j * sizeof(kCodeSetLocal0), kCodeSetLocal0,
sizeof(kCodeSetLocal0));
}
- Verify(kSuccess, &env_v_i, code, code + total);
+ Verify(kSuccess, sigs.v_i(), code, code + total);
free(code);
}
}
-
-TEST_F(WasmDecoderTest, BlockN_off_end) {
+TEST_F(AstDecoderTest, BlockN_off_end) {
for (byte i = 2; i < 10; i++) {
byte code[] = {kExprBlock, i, kExprNop};
- EXPECT_FAILURE(&env_v_v, code);
+ EXPECT_FAILURE(sigs.v_v(), code);
}
}
-
-TEST_F(WasmDecoderTest, Block1_break) {
+TEST_F(AstDecoderTest, Block1_break) {
static const byte code[] = {kExprBlock, 1, kExprBr, 0, kExprNop};
- EXPECT_VERIFIES(&env_v_v, code);
+ EXPECT_VERIFIES(sigs.v_v(), code);
}
-
-TEST_F(WasmDecoderTest, Block2_break) {
+TEST_F(AstDecoderTest, Block2_break) {
static const byte code[] = {kExprBlock, 2, kExprNop, kExprBr, 0, kExprNop};
- EXPECT_VERIFIES(&env_v_v, code);
+ EXPECT_VERIFIES(sigs.v_v(), code);
}
-
-TEST_F(WasmDecoderTest, Block1_continue) {
+TEST_F(AstDecoderTest, Block1_continue) {
static const byte code[] = {kExprBlock, 1, kExprBr, 1, kExprNop};
- EXPECT_FAILURE(&env_v_v, code);
+ EXPECT_FAILURE(sigs.v_v(), code);
}
-
-TEST_F(WasmDecoderTest, Block2_continue) {
+TEST_F(AstDecoderTest, Block2_continue) {
static const byte code[] = {kExprBlock, 2, kExprNop, kExprBr, 1, kExprNop};
- EXPECT_FAILURE(&env_v_v, code);
+ EXPECT_FAILURE(sigs.v_v(), code);
}
-
-TEST_F(WasmDecoderTest, ExprBlock0) {
+TEST_F(AstDecoderTest, ExprBlock0) {
static const byte code[] = {kExprBlock, 0};
- EXPECT_VERIFIES(&env_v_v, code);
+ EXPECT_VERIFIES(sigs.v_v(), code);
}
-
-TEST_F(WasmDecoderTest, ExprBlock1a) {
+TEST_F(AstDecoderTest, ExprBlock1a) {
static const byte code[] = {kExprBlock, 1, kExprI8Const, 0};
- EXPECT_VERIFIES(&env_i_i, code);
+ EXPECT_VERIFIES(sigs.i_i(), code);
}
-
-TEST_F(WasmDecoderTest, ExprBlock1b) {
+TEST_F(AstDecoderTest, ExprBlock1b) {
static const byte code[] = {kExprBlock, 1, kExprI8Const, 0};
- EXPECT_FAILURE(&env_f_ff, code);
+ EXPECT_FAILURE(sigs.f_ff(), code);
}
-
-TEST_F(WasmDecoderTest, ExprBlock1c) {
+TEST_F(AstDecoderTest, ExprBlock1c) {
static const byte code[] = {kExprBlock, 1, kExprF32Const, 0, 0, 0, 0};
- EXPECT_VERIFIES(&env_f_ff, code);
+ EXPECT_VERIFIES(sigs.f_ff(), code);
}
-
-TEST_F(WasmDecoderTest, IfEmpty) {
+TEST_F(AstDecoderTest, IfEmpty) {
static const byte code[] = {kExprIf, kExprGetLocal, 0, kExprNop};
- EXPECT_VERIFIES(&env_v_i, code);
+ EXPECT_VERIFIES(sigs.v_i(), code);
}
-
-TEST_F(WasmDecoderTest, IfSet) {
+TEST_F(AstDecoderTest, IfSet) {
static const byte code[] = {kExprIfElse, kExprGetLocal, 0, kExprSetLocal,
0, kExprI8Const, 0, kExprNop};
- EXPECT_VERIFIES(&env_v_i, code);
+ EXPECT_VERIFIES(sigs.v_i(), code);
}
-
-TEST_F(WasmDecoderTest, IfBlock1) {
+TEST_F(AstDecoderTest, IfBlock1) {
static const byte code[] = {kExprIfElse, kExprGetLocal, 0, kExprBlock,
1, kExprSetLocal, 0, kExprI8Const,
0, kExprNop};
- EXPECT_VERIFIES(&env_v_i, code);
+ EXPECT_VERIFIES(sigs.v_i(), code);
}
-
-TEST_F(WasmDecoderTest, IfBlock2) {
+TEST_F(AstDecoderTest, IfBlock2) {
static const byte code[] = {kExprIf, kExprGetLocal, 0, kExprBlock,
2, kExprSetLocal, 0, kExprI8Const,
0, kExprSetLocal, 0, kExprI8Const,
0};
- EXPECT_VERIFIES(&env_v_i, code);
+ EXPECT_VERIFIES(sigs.v_i(), code);
}
-
-TEST_F(WasmDecoderTest, IfElseEmpty) {
+TEST_F(AstDecoderTest, IfElseEmpty) {
static const byte code[] = {kExprIfElse, kExprGetLocal, 0, kExprNop,
kExprNop};
- EXPECT_VERIFIES(&env_v_i, code);
+ EXPECT_VERIFIES(sigs.v_i(), code);
}
-
-TEST_F(WasmDecoderTest, IfElseSet) {
+TEST_F(AstDecoderTest, IfElseSet) {
static const byte code[] = {kExprIfElse,
kExprGetLocal,
0, // --
@@ -584,218 +490,192 @@
0,
kExprI8Const,
1}; // --
- EXPECT_VERIFIES(&env_v_i, code);
+ EXPECT_VERIFIES(sigs.v_i(), code);
}
-
-TEST_F(WasmDecoderTest, IfElseUnreachable) {
+TEST_F(AstDecoderTest, IfElseUnreachable) {
static const byte code[] = {kExprIfElse, kExprI8Const, 0,
kExprUnreachable, kExprGetLocal, 0};
for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
LocalType types[] = {kAstI32, kLocalTypes[i]};
- FunctionEnv env;
FunctionSig sig(1, 1, types);
- init_env(&env, &sig);
if (kLocalTypes[i] == kAstI32) {
- EXPECT_VERIFIES(&env, code);
+ EXPECT_VERIFIES(&sig, code);
} else {
- EXPECT_FAILURE(&env, code);
+ EXPECT_FAILURE(&sig, code);
}
}
}
-
-TEST_F(WasmDecoderTest, Loop0) {
+TEST_F(AstDecoderTest, Loop0) {
static const byte code[] = {kExprLoop, 0};
- EXPECT_VERIFIES(&env_v_v, code);
+ EXPECT_VERIFIES(sigs.v_v(), code);
}
-
-TEST_F(WasmDecoderTest, Loop1) {
+TEST_F(AstDecoderTest, Loop1) {
static const byte code[] = {kExprLoop, 1, kExprSetLocal, 0, kExprI8Const, 0};
- EXPECT_VERIFIES(&env_v_i, code);
+ EXPECT_VERIFIES(sigs.v_i(), code);
}
-
-TEST_F(WasmDecoderTest, Loop2) {
+TEST_F(AstDecoderTest, Loop2) {
static const byte code[] = {kExprLoop, 2, // --
kExprSetLocal, 0, kExprI8Const, 0, // --
kExprSetLocal, 0, kExprI8Const, 0}; // --
- EXPECT_VERIFIES(&env_v_i, code);
+ EXPECT_VERIFIES(sigs.v_i(), code);
}
-
-TEST_F(WasmDecoderTest, Loop1_continue) {
+TEST_F(AstDecoderTest, Loop1_continue) {
static const byte code[] = {kExprLoop, 1, kExprBr, 0, kExprNop};
- EXPECT_VERIFIES(&env_v_v, code);
+ EXPECT_VERIFIES(sigs.v_v(), code);
}
-
-TEST_F(WasmDecoderTest, Loop1_break) {
+TEST_F(AstDecoderTest, Loop1_break) {
static const byte code[] = {kExprLoop, 1, kExprBr, 1, kExprNop};
- EXPECT_VERIFIES(&env_v_v, code);
+ EXPECT_VERIFIES(sigs.v_v(), code);
}
-
-TEST_F(WasmDecoderTest, Loop2_continue) {
+TEST_F(AstDecoderTest, Loop2_continue) {
static const byte code[] = {kExprLoop, 2, // --
kExprSetLocal, 0, kExprI8Const, 0, // --
kExprBr, 0, kExprNop}; // --
- EXPECT_VERIFIES(&env_v_i, code);
+ EXPECT_VERIFIES(sigs.v_i(), code);
}
-
-TEST_F(WasmDecoderTest, Loop2_break) {
+TEST_F(AstDecoderTest, Loop2_break) {
static const byte code[] = {kExprLoop, 2, // --
kExprSetLocal, 0, kExprI8Const, 0, // --
kExprBr, 1, kExprNop}; // --
- EXPECT_VERIFIES(&env_v_i, code);
+ EXPECT_VERIFIES(sigs.v_i(), code);
}
-
-TEST_F(WasmDecoderTest, ExprLoop0) {
+TEST_F(AstDecoderTest, ExprLoop0) {
static const byte code[] = {kExprLoop, 0};
- EXPECT_VERIFIES(&env_v_v, code);
+ EXPECT_VERIFIES(sigs.v_v(), code);
}
-
-TEST_F(WasmDecoderTest, ExprLoop1a) {
+TEST_F(AstDecoderTest, ExprLoop1a) {
static const byte code[] = {kExprLoop, 1, kExprBr, 0, kExprI8Const, 0};
- EXPECT_VERIFIES(&env_i_i, code);
+ EXPECT_VERIFIES(sigs.i_i(), code);
}
-
-TEST_F(WasmDecoderTest, ExprLoop1b) {
+TEST_F(AstDecoderTest, ExprLoop1b) {
static const byte code[] = {kExprLoop, 1, kExprBr, 0, kExprI8Const, 0};
- EXPECT_VERIFIES(&env_i_i, code);
+ EXPECT_VERIFIES(sigs.i_i(), code);
}
-
-TEST_F(WasmDecoderTest, ExprLoop2_unreachable) {
+TEST_F(AstDecoderTest, ExprLoop2_unreachable) {
static const byte code[] = {kExprLoop, 2, kExprBr, 0,
kExprI8Const, 0, kExprNop};
- EXPECT_VERIFIES(&env_i_i, code);
+ EXPECT_VERIFIES(sigs.i_i(), code);
}
-
-TEST_F(WasmDecoderTest, ReturnVoid1) {
+TEST_F(AstDecoderTest, ReturnVoid1) {
static const byte code[] = {kExprNop};
- EXPECT_VERIFIES(&env_v_v, code);
- EXPECT_FAILURE(&env_i_i, code);
- EXPECT_FAILURE(&env_i_f, code);
+ EXPECT_VERIFIES(sigs.v_v(), code);
+ EXPECT_FAILURE(sigs.i_i(), code);
+ EXPECT_FAILURE(sigs.i_f(), code);
}
-
-TEST_F(WasmDecoderTest, ReturnVoid2) {
+TEST_F(AstDecoderTest, ReturnVoid2) {
static const byte code[] = {kExprBlock, 1, kExprBr, 0, kExprNop};
- EXPECT_VERIFIES(&env_v_v, code);
- EXPECT_FAILURE(&env_i_i, code);
- EXPECT_FAILURE(&env_i_f, code);
+ EXPECT_VERIFIES(sigs.v_v(), code);
+ EXPECT_FAILURE(sigs.i_i(), code);
+ EXPECT_FAILURE(sigs.i_f(), code);
}
+TEST_F(AstDecoderTest, ReturnVoid3) {
+ EXPECT_VERIFIES_INLINE(sigs.v_v(), kExprI8Const, 0);
+ EXPECT_VERIFIES_INLINE(sigs.v_v(), kExprI32Const, 0, 0, 0, 0);
+ EXPECT_VERIFIES_INLINE(sigs.v_v(), kExprI64Const, 0, 0, 0, 0, 0, 0, 0, 0);
+ EXPECT_VERIFIES_INLINE(sigs.v_v(), kExprF32Const, 0, 0, 0, 0);
+ EXPECT_VERIFIES_INLINE(sigs.v_v(), kExprF64Const, 0, 0, 0, 0, 0, 0, 0, 0);
-TEST_F(WasmDecoderTest, ReturnVoid3) {
- EXPECT_VERIFIES_INLINE(&env_v_v, kExprI8Const, 0);
- EXPECT_VERIFIES_INLINE(&env_v_v, kExprI32Const, 0, 0, 0, 0);
- EXPECT_VERIFIES_INLINE(&env_v_v, kExprI64Const, 0, 0, 0, 0, 0, 0, 0, 0);
- EXPECT_VERIFIES_INLINE(&env_v_v, kExprF32Const, 0, 0, 0, 0);
- EXPECT_VERIFIES_INLINE(&env_v_v, kExprF64Const, 0, 0, 0, 0, 0, 0, 0, 0);
-
- EXPECT_VERIFIES_INLINE(&env_v_i, kExprGetLocal, 0);
+ EXPECT_VERIFIES_INLINE(sigs.v_i(), kExprGetLocal, 0);
}
-
-TEST_F(WasmDecoderTest, Unreachable1) {
- EXPECT_VERIFIES_INLINE(&env_v_v, kExprUnreachable);
- EXPECT_VERIFIES_INLINE(&env_v_v, kExprUnreachable, kExprUnreachable);
- EXPECT_VERIFIES_INLINE(&env_v_v, WASM_BLOCK(2, WASM_UNREACHABLE, WASM_ZERO));
- EXPECT_VERIFIES_INLINE(&env_v_v, WASM_BLOCK(2, WASM_BR(0), WASM_ZERO));
- EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(2, WASM_UNREACHABLE, WASM_ZERO));
- EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(2, WASM_BR(0), WASM_ZERO));
+TEST_F(AstDecoderTest, Unreachable1) {
+ EXPECT_VERIFIES_INLINE(sigs.v_v(), kExprUnreachable);
+ EXPECT_VERIFIES_INLINE(sigs.v_v(), kExprUnreachable, kExprUnreachable);
+ EXPECT_VERIFIES_INLINE(sigs.v_v(),
+ WASM_BLOCK(2, WASM_UNREACHABLE, WASM_ZERO));
+ EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_BLOCK(2, WASM_BR(0), WASM_ZERO));
+ EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(2, WASM_UNREACHABLE, WASM_ZERO));
+ EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(2, WASM_BR(0), WASM_ZERO));
}
-
-TEST_F(WasmDecoderTest, Codeiness) {
+TEST_F(AstDecoderTest, Codeiness) {
VERIFY(kExprLoop, 2, // --
kExprSetLocal, 0, kExprI8Const, 0, // --
kExprBr, 0, kExprNop); // --
}
-
-TEST_F(WasmDecoderTest, ExprIf1) {
+TEST_F(AstDecoderTest, ExprIf1) {
VERIFY(kExprIf, kExprGetLocal, 0, kExprI8Const, 0, kExprI8Const, 1);
VERIFY(kExprIf, kExprGetLocal, 0, kExprGetLocal, 0, kExprGetLocal, 0);
VERIFY(kExprIf, kExprGetLocal, 0, kExprI32Add, kExprGetLocal, 0,
kExprGetLocal, 0, kExprI8Const, 1);
}
-
-TEST_F(WasmDecoderTest, ExprIf_off_end) {
+TEST_F(AstDecoderTest, ExprIf_off_end) {
static const byte kCode[] = {kExprIf, kExprGetLocal, 0, kExprGetLocal,
0, kExprGetLocal, 0};
for (size_t len = 1; len < arraysize(kCode); len++) {
- Verify(kError, &env_i_i, kCode, kCode + len);
+ Verify(kError, sigs.i_i(), kCode, kCode + len);
}
}
-
-TEST_F(WasmDecoderTest, ExprIf_type) {
+TEST_F(AstDecoderTest, ExprIf_type) {
{
// float|double ? 1 : 2
static const byte kCode[] = {kExprIfElse, kExprGetLocal, 0, kExprI8Const,
1, kExprI8Const, 2};
- EXPECT_FAILURE(&env_i_f, kCode);
- EXPECT_FAILURE(&env_i_d, kCode);
+ EXPECT_FAILURE(sigs.i_f(), kCode);
+ EXPECT_FAILURE(sigs.i_d(), kCode);
}
{
// 1 ? float|double : 2
static const byte kCode[] = {kExprIfElse, kExprI8Const, 1, kExprGetLocal,
0, kExprI8Const, 2};
- EXPECT_FAILURE(&env_i_f, kCode);
- EXPECT_FAILURE(&env_i_d, kCode);
+ EXPECT_FAILURE(sigs.i_f(), kCode);
+ EXPECT_FAILURE(sigs.i_d(), kCode);
}
{
// stmt ? 0 : 1
static const byte kCode[] = {kExprIfElse, kExprNop, kExprI8Const,
0, kExprI8Const, 1};
- EXPECT_FAILURE(&env_i_i, kCode);
+ EXPECT_FAILURE(sigs.i_i(), kCode);
}
{
// 0 ? stmt : 1
static const byte kCode[] = {kExprIfElse, kExprI8Const, 0,
kExprNop, kExprI8Const, 1};
- EXPECT_FAILURE(&env_i_i, kCode);
+ EXPECT_FAILURE(sigs.i_i(), kCode);
}
{
// 0 ? 1 : stmt
static const byte kCode[] = {kExprIfElse, kExprI8Const, 0, kExprI8Const, 1,
0, kExprBlock};
- EXPECT_FAILURE(&env_i_i, kCode);
+ EXPECT_FAILURE(sigs.i_i(), kCode);
}
}
-
-TEST_F(WasmDecoderTest, Int64Local_param) {
- EXPECT_VERIFIES(&env_l_l, kCodeGetLocal0);
+TEST_F(AstDecoderTest, Int64Local_param) {
+ EXPECT_VERIFIES(sigs.l_l(), kCodeGetLocal0);
}
-
-TEST_F(WasmDecoderTest, Int64Locals) {
+TEST_F(AstDecoderTest, Int64Locals) {
for (byte i = 1; i < 8; i++) {
- FunctionEnv env;
- init_env(&env, sigs.l_v());
- env.AddLocals(kAstI64, i);
+ AddLocals(kAstI64, 1);
for (byte j = 0; j < i; j++) {
byte code[] = {kExprGetLocal, j};
- EXPECT_VERIFIES(&env, code);
+ EXPECT_VERIFIES(sigs.l_v(), code);
}
}
}
-
-TEST_F(WasmDecoderTest, Int32Binops) {
+TEST_F(AstDecoderTest, Int32Binops) {
TestBinop(kExprI32Add, sigs.i_ii());
TestBinop(kExprI32Sub, sigs.i_ii());
TestBinop(kExprI32Mul, sigs.i_ii());
@@ -816,8 +696,7 @@
TestBinop(kExprI32LeU, sigs.i_ii());
}
-
-TEST_F(WasmDecoderTest, DoubleBinops) {
+TEST_F(AstDecoderTest, DoubleBinops) {
TestBinop(kExprF64Add, sigs.d_dd());
TestBinop(kExprF64Sub, sigs.d_dd());
TestBinop(kExprF64Mul, sigs.d_dd());
@@ -828,8 +707,7 @@
TestBinop(kExprF64Le, sigs.i_dd());
}
-
-TEST_F(WasmDecoderTest, FloatBinops) {
+TEST_F(AstDecoderTest, FloatBinops) {
TestBinop(kExprF32Add, sigs.f_ff());
TestBinop(kExprF32Sub, sigs.f_ff());
TestBinop(kExprF32Mul, sigs.f_ff());
@@ -840,8 +718,7 @@
TestBinop(kExprF32Le, sigs.i_ff());
}
-
-TEST_F(WasmDecoderTest, TypeConversions) {
+TEST_F(AstDecoderTest, TypeConversions) {
TestUnop(kExprI32SConvertF32, kAstI32, kAstF32);
TestUnop(kExprI32SConvertF64, kAstI32, kAstF64);
TestUnop(kExprI32UConvertF32, kAstI32, kAstF32);
@@ -854,9 +731,8 @@
TestUnop(kExprF32ConvertF64, kAstF32, kAstF64);
}
-
-TEST_F(WasmDecoderTest, MacrosStmt) {
- VERIFY(WASM_SET_LOCAL(0, WASM_I32(87348)));
+TEST_F(AstDecoderTest, MacrosStmt) {
+ VERIFY(WASM_SET_LOCAL(0, WASM_I32V_3(87348)));
VERIFY(WASM_STORE_MEM(MachineType::Int32(), WASM_I8(24), WASM_I8(40)));
VERIFY(WASM_IF(WASM_GET_LOCAL(0), WASM_NOP));
VERIFY(WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP));
@@ -867,33 +743,30 @@
VERIFY(WASM_LOOP(1, WASM_CONTINUE(0)));
}
+TEST_F(AstDecoderTest, MacrosBreak) {
+ EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(1, WASM_BREAK(0)));
-TEST_F(WasmDecoderTest, MacrosBreak) {
- EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(1, WASM_BREAK(0)));
-
- EXPECT_VERIFIES_INLINE(&env_i_i, WASM_LOOP(1, WASM_BREAKV(0, WASM_ZERO)));
- EXPECT_VERIFIES_INLINE(&env_l_l, WASM_LOOP(1, WASM_BREAKV(0, WASM_I64(0))));
- EXPECT_VERIFIES_INLINE(&env_f_ff,
+ EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_LOOP(1, WASM_BREAKV(0, WASM_ZERO)));
+ EXPECT_VERIFIES_INLINE(sigs.l_l(),
+ WASM_LOOP(1, WASM_BREAKV(0, WASM_I64V_1(0))));
+ EXPECT_VERIFIES_INLINE(sigs.f_ff(),
WASM_LOOP(1, WASM_BREAKV(0, WASM_F32(0.0))));
- EXPECT_VERIFIES_INLINE(&env_d_dd,
+ EXPECT_VERIFIES_INLINE(sigs.d_dd(),
WASM_LOOP(1, WASM_BREAKV(0, WASM_F64(0.0))));
}
-
-TEST_F(WasmDecoderTest, MacrosContinue) {
- EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(1, WASM_CONTINUE(0)));
+TEST_F(AstDecoderTest, MacrosContinue) {
+ EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(1, WASM_CONTINUE(0)));
}
-
-TEST_F(WasmDecoderTest, MacrosVariadic) {
+TEST_F(AstDecoderTest, MacrosVariadic) {
VERIFY(WASM_BLOCK(2, WASM_NOP, WASM_NOP));
VERIFY(WASM_BLOCK(3, WASM_NOP, WASM_NOP, WASM_NOP));
VERIFY(WASM_LOOP(2, WASM_NOP, WASM_NOP));
VERIFY(WASM_LOOP(3, WASM_NOP, WASM_NOP, WASM_NOP));
}
-
-TEST_F(WasmDecoderTest, MacrosNestedBlocks) {
+TEST_F(AstDecoderTest, MacrosNestedBlocks) {
VERIFY(WASM_BLOCK(2, WASM_NOP, WASM_BLOCK(2, WASM_NOP, WASM_NOP)));
VERIFY(WASM_BLOCK(3, WASM_NOP, // --
WASM_BLOCK(2, WASM_NOP, WASM_NOP), // --
@@ -901,42 +774,31 @@
VERIFY(WASM_BLOCK(1, WASM_BLOCK(1, WASM_BLOCK(2, WASM_NOP, WASM_NOP))));
}
-
-TEST_F(WasmDecoderTest, MultipleReturn) {
+TEST_F(AstDecoderTest, MultipleReturn) {
static LocalType kIntTypes5[] = {kAstI32, kAstI32, kAstI32, kAstI32, kAstI32};
FunctionSig sig_ii_v(2, 0, kIntTypes5);
- FunctionEnv env_ii_v;
- init_env(&env_ii_v, &sig_ii_v);
- EXPECT_VERIFIES_INLINE(&env_ii_v, WASM_RETURN(WASM_ZERO, WASM_ONE));
- EXPECT_FAILURE_INLINE(&env_ii_v, WASM_RETURN(WASM_ZERO));
+ EXPECT_VERIFIES_INLINE(&sig_ii_v, WASM_RETURN(WASM_ZERO, WASM_ONE));
+ EXPECT_FAILURE_INLINE(&sig_ii_v, WASM_RETURN(WASM_ZERO));
FunctionSig sig_iii_v(3, 0, kIntTypes5);
- FunctionEnv env_iii_v;
- init_env(&env_iii_v, &sig_iii_v);
- EXPECT_VERIFIES_INLINE(&env_iii_v,
+ EXPECT_VERIFIES_INLINE(&sig_iii_v,
WASM_RETURN(WASM_ZERO, WASM_ONE, WASM_I8(44)));
- EXPECT_FAILURE_INLINE(&env_iii_v, WASM_RETURN(WASM_ZERO, WASM_ONE));
+ EXPECT_FAILURE_INLINE(&sig_iii_v, WASM_RETURN(WASM_ZERO, WASM_ONE));
}
-
-TEST_F(WasmDecoderTest, MultipleReturn_fallthru) {
+TEST_F(AstDecoderTest, MultipleReturn_fallthru) {
static LocalType kIntTypes5[] = {kAstI32, kAstI32, kAstI32, kAstI32, kAstI32};
FunctionSig sig_ii_v(2, 0, kIntTypes5);
- FunctionEnv env_ii_v;
- init_env(&env_ii_v, &sig_ii_v);
- EXPECT_VERIFIES_INLINE(&env_ii_v, WASM_ZERO, WASM_ONE);
- EXPECT_FAILURE_INLINE(&env_ii_v, WASM_ZERO);
+ EXPECT_VERIFIES_INLINE(&sig_ii_v, WASM_ZERO, WASM_ONE);
+ EXPECT_FAILURE_INLINE(&sig_ii_v, WASM_ZERO);
FunctionSig sig_iii_v(3, 0, kIntTypes5);
- FunctionEnv env_iii_v;
- init_env(&env_iii_v, &sig_iii_v);
- EXPECT_VERIFIES_INLINE(&env_iii_v, WASM_ZERO, WASM_ONE, WASM_I8(44));
- EXPECT_FAILURE_INLINE(&env_iii_v, WASM_ZERO, WASM_ONE);
+ EXPECT_VERIFIES_INLINE(&sig_iii_v, WASM_ZERO, WASM_ONE, WASM_I8(44));
+ EXPECT_FAILURE_INLINE(&sig_iii_v, WASM_ZERO, WASM_ONE);
}
-
-TEST_F(WasmDecoderTest, MacrosInt32) {
+TEST_F(AstDecoderTest, MacrosInt32) {
VERIFY(WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_I8(12)));
VERIFY(WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(13)));
VERIFY(WASM_I32_MUL(WASM_GET_LOCAL(0), WASM_I8(14)));
@@ -950,6 +812,8 @@
VERIFY(WASM_I32_SHL(WASM_GET_LOCAL(0), WASM_I8(22)));
VERIFY(WASM_I32_SHR(WASM_GET_LOCAL(0), WASM_I8(23)));
VERIFY(WASM_I32_SAR(WASM_GET_LOCAL(0), WASM_I8(24)));
+ VERIFY(WASM_I32_ROR(WASM_GET_LOCAL(0), WASM_I8(24)));
+ VERIFY(WASM_I32_ROL(WASM_GET_LOCAL(0), WASM_I8(24)));
VERIFY(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(25)));
VERIFY(WASM_I32_NE(WASM_GET_LOCAL(0), WASM_I8(25)));
@@ -964,47 +828,42 @@
VERIFY(WASM_I32_GEU(WASM_GET_LOCAL(0), WASM_I8(29)));
}
+TEST_F(AstDecoderTest, MacrosInt64) {
+#define VERIFY_L_LL(...) EXPECT_VERIFIES_INLINE(sigs.l_ll(), __VA_ARGS__)
+#define VERIFY_I_LL(...) EXPECT_VERIFIES_INLINE(sigs.i_ll(), __VA_ARGS__)
-TEST_F(WasmDecoderTest, MacrosInt64) {
- FunctionEnv env_i_ll;
- FunctionEnv env_l_ll;
- init_env(&env_i_ll, sigs.i_ll());
- init_env(&env_l_ll, sigs.l_ll());
+ VERIFY_L_LL(WASM_I64_ADD(WASM_GET_LOCAL(0), WASM_I64V_1(12)));
+ VERIFY_L_LL(WASM_I64_SUB(WASM_GET_LOCAL(0), WASM_I64V_1(13)));
+ VERIFY_L_LL(WASM_I64_MUL(WASM_GET_LOCAL(0), WASM_I64V_1(14)));
+ VERIFY_L_LL(WASM_I64_DIVS(WASM_GET_LOCAL(0), WASM_I64V_1(15)));
+ VERIFY_L_LL(WASM_I64_DIVU(WASM_GET_LOCAL(0), WASM_I64V_1(16)));
+ VERIFY_L_LL(WASM_I64_REMS(WASM_GET_LOCAL(0), WASM_I64V_1(17)));
+ VERIFY_L_LL(WASM_I64_REMU(WASM_GET_LOCAL(0), WASM_I64V_1(18)));
+ VERIFY_L_LL(WASM_I64_AND(WASM_GET_LOCAL(0), WASM_I64V_1(19)));
+ VERIFY_L_LL(WASM_I64_IOR(WASM_GET_LOCAL(0), WASM_I64V_1(20)));
+ VERIFY_L_LL(WASM_I64_XOR(WASM_GET_LOCAL(0), WASM_I64V_1(21)));
-#define VERIFY_L_LL(...) EXPECT_VERIFIES_INLINE(&env_l_ll, __VA_ARGS__)
-#define VERIFY_I_LL(...) EXPECT_VERIFIES_INLINE(&env_i_ll, __VA_ARGS__)
+ VERIFY_L_LL(WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_I64V_1(22)));
+ VERIFY_L_LL(WASM_I64_SHR(WASM_GET_LOCAL(0), WASM_I64V_1(23)));
+ VERIFY_L_LL(WASM_I64_SAR(WASM_GET_LOCAL(0), WASM_I64V_1(24)));
+ VERIFY_L_LL(WASM_I64_ROR(WASM_GET_LOCAL(0), WASM_I64V_1(24)));
+ VERIFY_L_LL(WASM_I64_ROL(WASM_GET_LOCAL(0), WASM_I64V_1(24)));
- VERIFY_L_LL(WASM_I64_ADD(WASM_GET_LOCAL(0), WASM_I64(12)));
- VERIFY_L_LL(WASM_I64_SUB(WASM_GET_LOCAL(0), WASM_I64(13)));
- VERIFY_L_LL(WASM_I64_MUL(WASM_GET_LOCAL(0), WASM_I64(14)));
- VERIFY_L_LL(WASM_I64_DIVS(WASM_GET_LOCAL(0), WASM_I64(15)));
- VERIFY_L_LL(WASM_I64_DIVU(WASM_GET_LOCAL(0), WASM_I64(16)));
- VERIFY_L_LL(WASM_I64_REMS(WASM_GET_LOCAL(0), WASM_I64(17)));
- VERIFY_L_LL(WASM_I64_REMU(WASM_GET_LOCAL(0), WASM_I64(18)));
- VERIFY_L_LL(WASM_I64_AND(WASM_GET_LOCAL(0), WASM_I64(19)));
- VERIFY_L_LL(WASM_I64_IOR(WASM_GET_LOCAL(0), WASM_I64(20)));
- VERIFY_L_LL(WASM_I64_XOR(WASM_GET_LOCAL(0), WASM_I64(21)));
+ VERIFY_I_LL(WASM_I64_LTS(WASM_GET_LOCAL(0), WASM_I64V_1(26)));
+ VERIFY_I_LL(WASM_I64_LES(WASM_GET_LOCAL(0), WASM_I64V_1(27)));
+ VERIFY_I_LL(WASM_I64_LTU(WASM_GET_LOCAL(0), WASM_I64V_1(28)));
+ VERIFY_I_LL(WASM_I64_LEU(WASM_GET_LOCAL(0), WASM_I64V_1(29)));
- VERIFY_L_LL(WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_I64(22)));
- VERIFY_L_LL(WASM_I64_SHR(WASM_GET_LOCAL(0), WASM_I64(23)));
- VERIFY_L_LL(WASM_I64_SAR(WASM_GET_LOCAL(0), WASM_I64(24)));
+ VERIFY_I_LL(WASM_I64_GTS(WASM_GET_LOCAL(0), WASM_I64V_1(26)));
+ VERIFY_I_LL(WASM_I64_GES(WASM_GET_LOCAL(0), WASM_I64V_1(27)));
+ VERIFY_I_LL(WASM_I64_GTU(WASM_GET_LOCAL(0), WASM_I64V_1(28)));
+ VERIFY_I_LL(WASM_I64_GEU(WASM_GET_LOCAL(0), WASM_I64V_1(29)));
- VERIFY_I_LL(WASM_I64_LTS(WASM_GET_LOCAL(0), WASM_I64(26)));
- VERIFY_I_LL(WASM_I64_LES(WASM_GET_LOCAL(0), WASM_I64(27)));
- VERIFY_I_LL(WASM_I64_LTU(WASM_GET_LOCAL(0), WASM_I64(28)));
- VERIFY_I_LL(WASM_I64_LEU(WASM_GET_LOCAL(0), WASM_I64(29)));
-
- VERIFY_I_LL(WASM_I64_GTS(WASM_GET_LOCAL(0), WASM_I64(26)));
- VERIFY_I_LL(WASM_I64_GES(WASM_GET_LOCAL(0), WASM_I64(27)));
- VERIFY_I_LL(WASM_I64_GTU(WASM_GET_LOCAL(0), WASM_I64(28)));
- VERIFY_I_LL(WASM_I64_GEU(WASM_GET_LOCAL(0), WASM_I64(29)));
-
- VERIFY_I_LL(WASM_I64_EQ(WASM_GET_LOCAL(0), WASM_I64(25)));
- VERIFY_I_LL(WASM_I64_NE(WASM_GET_LOCAL(0), WASM_I64(25)));
+ VERIFY_I_LL(WASM_I64_EQ(WASM_GET_LOCAL(0), WASM_I64V_1(25)));
+ VERIFY_I_LL(WASM_I64_NE(WASM_GET_LOCAL(0), WASM_I64V_1(25)));
}
-
-TEST_F(WasmDecoderTest, AllSimpleExpressions) {
+TEST_F(AstDecoderTest, AllSimpleExpressions) {
// Test all simple expressions which are described by a signature.
#define DECODE_TEST(name, opcode, sig) \
{ \
@@ -1021,86 +880,55 @@
#undef DECODE_TEST
}
-
-TEST_F(WasmDecoderTest, MemorySize) {
+TEST_F(AstDecoderTest, MemorySize) {
byte code[] = {kExprMemorySize};
- EXPECT_VERIFIES(&env_i_i, code);
- EXPECT_FAILURE(&env_f_ff, code);
+ EXPECT_VERIFIES(sigs.i_i(), code);
+ EXPECT_FAILURE(sigs.f_ff(), code);
}
-
-TEST_F(WasmDecoderTest, GrowMemory) {
+TEST_F(AstDecoderTest, GrowMemory) {
byte code[] = {kExprGrowMemory, kExprGetLocal, 0};
- EXPECT_VERIFIES(&env_i_i, code);
- EXPECT_FAILURE(&env_i_d, code);
+ EXPECT_VERIFIES(sigs.i_i(), code);
+ EXPECT_FAILURE(sigs.i_d(), code);
}
-
-TEST_F(WasmDecoderTest, LoadMemOffset) {
+TEST_F(AstDecoderTest, LoadMemOffset) {
for (int offset = 0; offset < 128; offset += 7) {
- byte code[] = {kExprI32LoadMem, WasmOpcodes::LoadStoreAccessOf(true),
- static_cast<byte>(offset), kExprI8Const, 0};
- EXPECT_VERIFIES(&env_i_i, code);
+ byte code[] = {kExprI32LoadMem, ZERO_ALIGNMENT, static_cast<byte>(offset),
+ kExprI8Const, 0};
+ EXPECT_VERIFIES(sigs.i_i(), code);
}
}
-
-TEST_F(WasmDecoderTest, StoreMemOffset) {
+TEST_F(AstDecoderTest, StoreMemOffset) {
for (int offset = 0; offset < 128; offset += 7) {
- byte code[] = {kExprI32StoreMem,
- WasmOpcodes::LoadStoreAccessOf(true),
- static_cast<byte>(offset),
- kExprI8Const,
- 0,
- kExprI8Const,
- 0};
- EXPECT_VERIFIES(&env_i_i, code);
+ byte code[] = {
+ kExprI32StoreMem, 0, static_cast<byte>(offset), kExprI8Const, 0,
+ kExprI8Const, 0};
+ EXPECT_VERIFIES(sigs.i_i(), code);
}
}
+TEST_F(AstDecoderTest, LoadMemOffset_varint) {
+ byte code1[] = {kExprI32LoadMem, ZERO_ALIGNMENT, ZERO_OFFSET, kExprI8Const,
+ 0};
+ byte code2[] = {kExprI32LoadMem, ZERO_ALIGNMENT, 0x80, 1, kExprI8Const, 0};
+ byte code3[] = {
+ kExprI32LoadMem, ZERO_ALIGNMENT, 0x81, 0x82, 5, kExprI8Const, 0};
+ byte code4[] = {
+ kExprI32LoadMem, ZERO_ALIGNMENT, 0x83, 0x84, 0x85, 7, kExprI8Const, 0};
-TEST_F(WasmDecoderTest, LoadMemOffset_varint) {
- byte code1[] = {kExprI32LoadMem, WasmOpcodes::LoadStoreAccessOf(true), 0,
- kExprI8Const, 0};
- byte code2[] = {kExprI32LoadMem,
- WasmOpcodes::LoadStoreAccessOf(true),
- 0x80,
- 1,
- kExprI8Const,
- 0};
- byte code3[] = {kExprI32LoadMem,
- WasmOpcodes::LoadStoreAccessOf(true),
- 0x81,
- 0x82,
- 5,
- kExprI8Const,
- 0};
- byte code4[] = {kExprI32LoadMem,
- WasmOpcodes::LoadStoreAccessOf(true),
- 0x83,
- 0x84,
- 0x85,
- 7,
- kExprI8Const,
- 0};
-
- EXPECT_VERIFIES(&env_i_i, code1);
- EXPECT_VERIFIES(&env_i_i, code2);
- EXPECT_VERIFIES(&env_i_i, code3);
- EXPECT_VERIFIES(&env_i_i, code4);
+ EXPECT_VERIFIES(sigs.i_i(), code1);
+ EXPECT_VERIFIES(sigs.i_i(), code2);
+ EXPECT_VERIFIES(sigs.i_i(), code3);
+ EXPECT_VERIFIES(sigs.i_i(), code4);
}
-
-TEST_F(WasmDecoderTest, StoreMemOffset_varint) {
- byte code1[] = {kExprI32StoreMem,
- WasmOpcodes::LoadStoreAccessOf(true),
- 0,
- kExprI8Const,
- 0,
- kExprI8Const,
- 0};
+TEST_F(AstDecoderTest, StoreMemOffset_varint) {
+ byte code1[] = {
+ kExprI32StoreMem, ZERO_ALIGNMENT, 0, kExprI8Const, 0, kExprI8Const, 0};
byte code2[] = {kExprI32StoreMem,
- WasmOpcodes::LoadStoreAccessOf(true),
+ ZERO_ALIGNMENT,
0x80,
1,
kExprI8Const,
@@ -1108,7 +936,7 @@
kExprI8Const,
0};
byte code3[] = {kExprI32StoreMem,
- WasmOpcodes::LoadStoreAccessOf(true),
+ ZERO_ALIGNMENT,
0x81,
0x82,
5,
@@ -1117,7 +945,7 @@
kExprI8Const,
0};
byte code4[] = {kExprI32StoreMem,
- WasmOpcodes::LoadStoreAccessOf(true),
+ ZERO_ALIGNMENT,
0x83,
0x84,
0x85,
@@ -1127,53 +955,48 @@
kExprI8Const,
0};
- EXPECT_VERIFIES(&env_i_i, code1);
- EXPECT_VERIFIES(&env_i_i, code2);
- EXPECT_VERIFIES(&env_i_i, code3);
- EXPECT_VERIFIES(&env_i_i, code4);
+ EXPECT_VERIFIES(sigs.i_i(), code1);
+ EXPECT_VERIFIES(sigs.i_i(), code2);
+ EXPECT_VERIFIES(sigs.i_i(), code3);
+ EXPECT_VERIFIES(sigs.i_i(), code4);
}
-
-TEST_F(WasmDecoderTest, AllLoadMemCombinations) {
+TEST_F(AstDecoderTest, AllLoadMemCombinations) {
for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
LocalType local_type = kLocalTypes[i];
for (size_t j = 0; j < arraysize(machineTypes); j++) {
MachineType mem_type = machineTypes[j];
byte code[] = {
static_cast<byte>(WasmOpcodes::LoadStoreOpcodeOf(mem_type, false)),
- WasmOpcodes::LoadStoreAccessOf(false), kExprI8Const, 0};
- FunctionEnv env;
+ ZERO_ALIGNMENT, ZERO_OFFSET, kExprI8Const, 0};
FunctionSig sig(1, 0, &local_type);
- init_env(&env, &sig);
if (local_type == WasmOpcodes::LocalTypeFor(mem_type)) {
- EXPECT_VERIFIES(&env, code);
+ EXPECT_VERIFIES(&sig, code);
} else {
- EXPECT_FAILURE(&env, code);
+ EXPECT_FAILURE(&sig, code);
}
}
}
}
-
-TEST_F(WasmDecoderTest, AllStoreMemCombinations) {
+TEST_F(AstDecoderTest, AllStoreMemCombinations) {
for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
LocalType local_type = kLocalTypes[i];
for (size_t j = 0; j < arraysize(machineTypes); j++) {
MachineType mem_type = machineTypes[j];
byte code[] = {
static_cast<byte>(WasmOpcodes::LoadStoreOpcodeOf(mem_type, true)),
- WasmOpcodes::LoadStoreAccessOf(false),
+ ZERO_ALIGNMENT,
+ ZERO_OFFSET,
kExprI8Const,
0,
kExprGetLocal,
0};
- FunctionEnv env;
FunctionSig sig(0, 1, &local_type);
- init_env(&env, &sig);
if (local_type == WasmOpcodes::LocalTypeFor(mem_type)) {
- EXPECT_VERIFIES(&env, code);
+ EXPECT_VERIFIES(&sig, code);
} else {
- EXPECT_FAILURE(&env, code);
+ EXPECT_FAILURE(&sig, code);
}
}
}
@@ -1189,30 +1012,26 @@
instance = nullptr;
module = &mod;
linker = nullptr;
- mod.globals = new std::vector<WasmGlobal>;
- mod.signatures = new std::vector<FunctionSig*>;
- mod.functions = new std::vector<WasmFunction>;
- mod.import_table = new std::vector<WasmImport>;
}
byte AddGlobal(MachineType mem_type) {
- mod.globals->push_back({0, mem_type, 0, false});
- CHECK(mod.globals->size() <= 127);
- return static_cast<byte>(mod.globals->size() - 1);
+ mod.globals.push_back({0, 0, mem_type, 0, false});
+ CHECK(mod.globals.size() <= 127);
+ return static_cast<byte>(mod.globals.size() - 1);
}
byte AddSignature(FunctionSig* sig) {
- mod.signatures->push_back(sig);
- CHECK(mod.signatures->size() <= 127);
- return static_cast<byte>(mod.signatures->size() - 1);
+ mod.signatures.push_back(sig);
+ CHECK(mod.signatures.size() <= 127);
+ return static_cast<byte>(mod.signatures.size() - 1);
}
byte AddFunction(FunctionSig* sig) {
- mod.functions->push_back({sig, 0, 0, 0, 0, 0, 0, 0, false, false});
- CHECK(mod.functions->size() <= 127);
- return static_cast<byte>(mod.functions->size() - 1);
+ mod.functions.push_back({sig, 0, 0, 0, 0, 0, 0, 0, false, false});
+ CHECK(mod.functions.size() <= 127);
+ return static_cast<byte>(mod.functions.size() - 1);
}
byte AddImport(FunctionSig* sig) {
- mod.import_table->push_back({sig, 0, 0});
- CHECK(mod.import_table->size() <= 127);
- return static_cast<byte>(mod.import_table->size() - 1);
+ mod.import_table.push_back({sig, 0, 0});
+ CHECK(mod.import_table.size() <= 127);
+ return static_cast<byte>(mod.import_table.size() - 1);
}
private:
@@ -1220,194 +1039,184 @@
};
} // namespace
-
-TEST_F(WasmDecoderTest, SimpleCalls) {
- FunctionEnv* env = &env_i_i;
+TEST_F(AstDecoderTest, SimpleCalls) {
+ FunctionSig* sig = sigs.i_i();
TestModuleEnv module_env;
- env->module = &module_env;
+ module = &module_env;
module_env.AddFunction(sigs.i_v());
module_env.AddFunction(sigs.i_i());
module_env.AddFunction(sigs.i_ii());
- EXPECT_VERIFIES_INLINE(env, WASM_CALL_FUNCTION(0));
- EXPECT_VERIFIES_INLINE(env, WASM_CALL_FUNCTION(1, WASM_I8(27)));
- EXPECT_VERIFIES_INLINE(env, WASM_CALL_FUNCTION(2, WASM_I8(37), WASM_I8(77)));
+ EXPECT_VERIFIES_INLINE(sig, WASM_CALL_FUNCTION(0));
+ EXPECT_VERIFIES_INLINE(sig, WASM_CALL_FUNCTION(1, WASM_I8(27)));
+ EXPECT_VERIFIES_INLINE(sig, WASM_CALL_FUNCTION(2, WASM_I8(37), WASM_I8(77)));
}
-
-TEST_F(WasmDecoderTest, CallsWithTooFewArguments) {
- FunctionEnv* env = &env_i_i;
+TEST_F(AstDecoderTest, CallsWithTooFewArguments) {
+ FunctionSig* sig = sigs.i_i();
TestModuleEnv module_env;
- env->module = &module_env;
+ module = &module_env;
module_env.AddFunction(sigs.i_i());
module_env.AddFunction(sigs.i_ii());
module_env.AddFunction(sigs.f_ff());
- EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION0(0));
- EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(1, WASM_ZERO));
- EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(2, WASM_GET_LOCAL(0)));
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION0(0));
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION(1, WASM_ZERO));
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION(2, WASM_GET_LOCAL(0)));
}
-
-TEST_F(WasmDecoderTest, CallsWithSpilloverArgs) {
+TEST_F(AstDecoderTest, CallsWithSpilloverArgs) {
static LocalType a_i_ff[] = {kAstI32, kAstF32, kAstF32};
FunctionSig sig_i_ff(1, 2, a_i_ff);
- FunctionEnv env_i_ff;
- init_env(&env_i_ff, &sig_i_ff);
TestModuleEnv module_env;
- env_i_ff.module = &module_env;
- env_i_i.module = &module_env;
- env_f_ff.module = &module_env;
+ module = &module_env;
module_env.AddFunction(&sig_i_ff);
- EXPECT_VERIFIES_INLINE(&env_i_i,
+ EXPECT_VERIFIES_INLINE(sigs.i_i(),
WASM_CALL_FUNCTION(0, WASM_F32(0.1), WASM_F32(0.1)));
- EXPECT_VERIFIES_INLINE(&env_i_ff,
+ EXPECT_VERIFIES_INLINE(sigs.i_ff(),
WASM_CALL_FUNCTION(0, WASM_F32(0.1), WASM_F32(0.1)));
- EXPECT_FAILURE_INLINE(&env_f_ff,
+ EXPECT_FAILURE_INLINE(sigs.f_ff(),
WASM_CALL_FUNCTION(0, WASM_F32(0.1), WASM_F32(0.1)));
EXPECT_FAILURE_INLINE(
- &env_i_i,
+ sigs.i_i(),
WASM_CALL_FUNCTION(0, WASM_F32(0.1), WASM_F32(0.1), WASM_F32(0.2)));
EXPECT_VERIFIES_INLINE(
- &env_f_ff,
+ sigs.f_ff(),
WASM_CALL_FUNCTION(0, WASM_F32(0.1), WASM_F32(0.1), WASM_F32(11)));
}
-
-TEST_F(WasmDecoderTest, CallsWithMismatchedSigs2) {
- FunctionEnv* env = &env_i_i;
+TEST_F(AstDecoderTest, CallsWithMismatchedSigs2) {
+ FunctionSig* sig = sigs.i_i();
TestModuleEnv module_env;
- env->module = &module_env;
+ module = &module_env;
module_env.AddFunction(sigs.i_i());
- EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(0, WASM_I64(17)));
- EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(0, WASM_F32(17.1)));
- EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(0, WASM_F64(17.1)));
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION(0, WASM_I64V_1(17)));
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION(0, WASM_F32(17.1)));
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION(0, WASM_F64(17.1)));
}
-
-TEST_F(WasmDecoderTest, CallsWithMismatchedSigs3) {
- FunctionEnv* env = &env_i_i;
+TEST_F(AstDecoderTest, CallsWithMismatchedSigs3) {
+ FunctionSig* sig = sigs.i_i();
TestModuleEnv module_env;
- env->module = &module_env;
+ module = &module_env;
module_env.AddFunction(sigs.i_f());
- EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(0, WASM_I8(17)));
- EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(0, WASM_I64(27)));
- EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(0, WASM_F64(37.2)));
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION(0, WASM_I8(17)));
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION(0, WASM_I64V_1(27)));
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION(0, WASM_F64(37.2)));
module_env.AddFunction(sigs.i_d());
- EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(1, WASM_I8(16)));
- EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(1, WASM_I64(16)));
- EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(1, WASM_F32(17.6)));
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION(1, WASM_I8(16)));
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION(1, WASM_I64V_1(16)));
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION(1, WASM_F32(17.6)));
}
-
-TEST_F(WasmDecoderTest, SimpleIndirectCalls) {
- FunctionEnv* env = &env_i_i;
+TEST_F(AstDecoderTest, SimpleIndirectCalls) {
+ FunctionSig* sig = sigs.i_i();
TestModuleEnv module_env;
- env->module = &module_env;
+ module = &module_env;
byte f0 = module_env.AddSignature(sigs.i_v());
byte f1 = module_env.AddSignature(sigs.i_i());
byte f2 = module_env.AddSignature(sigs.i_ii());
- EXPECT_VERIFIES_INLINE(env, WASM_CALL_INDIRECT0(f0, WASM_ZERO));
- EXPECT_VERIFIES_INLINE(env, WASM_CALL_INDIRECT(f1, WASM_ZERO, WASM_I8(22)));
+ EXPECT_VERIFIES_INLINE(sig, WASM_CALL_INDIRECT0(f0, WASM_ZERO));
+ EXPECT_VERIFIES_INLINE(sig, WASM_CALL_INDIRECT(f1, WASM_ZERO, WASM_I8(22)));
EXPECT_VERIFIES_INLINE(
- env, WASM_CALL_INDIRECT(f2, WASM_ZERO, WASM_I8(32), WASM_I8(72)));
+ sig, WASM_CALL_INDIRECT(f2, WASM_ZERO, WASM_I8(32), WASM_I8(72)));
}
-
-TEST_F(WasmDecoderTest, IndirectCallsOutOfBounds) {
- FunctionEnv* env = &env_i_i;
+TEST_F(AstDecoderTest, IndirectCallsOutOfBounds) {
+ FunctionSig* sig = sigs.i_i();
TestModuleEnv module_env;
- env->module = &module_env;
+ module = &module_env;
- EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT0(0, WASM_ZERO));
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT0(0, WASM_ZERO));
module_env.AddSignature(sigs.i_v());
- EXPECT_VERIFIES_INLINE(env, WASM_CALL_INDIRECT0(0, WASM_ZERO));
+ EXPECT_VERIFIES_INLINE(sig, WASM_CALL_INDIRECT0(0, WASM_ZERO));
- EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT(1, WASM_ZERO, WASM_I8(22)));
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT(1, WASM_ZERO, WASM_I8(22)));
module_env.AddSignature(sigs.i_i());
- EXPECT_VERIFIES_INLINE(env, WASM_CALL_INDIRECT(1, WASM_ZERO, WASM_I8(27)));
+ EXPECT_VERIFIES_INLINE(sig, WASM_CALL_INDIRECT(1, WASM_ZERO, WASM_I8(27)));
- EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT(2, WASM_ZERO, WASM_I8(27)));
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT(2, WASM_ZERO, WASM_I8(27)));
}
-
-TEST_F(WasmDecoderTest, IndirectCallsWithMismatchedSigs3) {
- FunctionEnv* env = &env_i_i;
+TEST_F(AstDecoderTest, IndirectCallsWithMismatchedSigs3) {
+ FunctionSig* sig = sigs.i_i();
TestModuleEnv module_env;
- env->module = &module_env;
+ module = &module_env;
byte f0 = module_env.AddFunction(sigs.i_f());
- EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT(f0, WASM_ZERO, WASM_I8(17)));
- EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT(f0, WASM_ZERO, WASM_I64(27)));
- EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT(f0, WASM_ZERO, WASM_F64(37.2)));
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT(f0, WASM_ZERO, WASM_I8(17)));
+ EXPECT_FAILURE_INLINE(sig,
+ WASM_CALL_INDIRECT(f0, WASM_ZERO, WASM_I64V_1(27)));
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT(f0, WASM_ZERO, WASM_F64(37.2)));
- EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT0(f0, WASM_I8(17)));
- EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT0(f0, WASM_I64(27)));
- EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT0(f0, WASM_F64(37.2)));
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT0(f0, WASM_I8(17)));
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT0(f0, WASM_I64V_1(27)));
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT0(f0, WASM_F64(37.2)));
byte f1 = module_env.AddFunction(sigs.i_d());
- EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT(f1, WASM_ZERO, WASM_I8(16)));
- EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT(f1, WASM_ZERO, WASM_I64(16)));
- EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT(f1, WASM_ZERO, WASM_F32(17.6)));
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT(f1, WASM_ZERO, WASM_I8(16)));
+ EXPECT_FAILURE_INLINE(sig,
+ WASM_CALL_INDIRECT(f1, WASM_ZERO, WASM_I64V_1(16)));
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT(f1, WASM_ZERO, WASM_F32(17.6)));
}
-TEST_F(WasmDecoderTest, SimpleImportCalls) {
- FunctionEnv* env = &env_i_i;
+TEST_F(AstDecoderTest, SimpleImportCalls) {
+ FunctionSig* sig = sigs.i_i();
TestModuleEnv module_env;
- env->module = &module_env;
+ module = &module_env;
byte f0 = module_env.AddImport(sigs.i_v());
byte f1 = module_env.AddImport(sigs.i_i());
byte f2 = module_env.AddImport(sigs.i_ii());
- EXPECT_VERIFIES_INLINE(env, WASM_CALL_IMPORT0(f0));
- EXPECT_VERIFIES_INLINE(env, WASM_CALL_IMPORT(f1, WASM_I8(22)));
- EXPECT_VERIFIES_INLINE(env, WASM_CALL_IMPORT(f2, WASM_I8(32), WASM_I8(72)));
+ EXPECT_VERIFIES_INLINE(sig, WASM_CALL_IMPORT0(f0));
+ EXPECT_VERIFIES_INLINE(sig, WASM_CALL_IMPORT(f1, WASM_I8(22)));
+ EXPECT_VERIFIES_INLINE(sig, WASM_CALL_IMPORT(f2, WASM_I8(32), WASM_I8(72)));
}
-TEST_F(WasmDecoderTest, ImportCallsWithMismatchedSigs3) {
- FunctionEnv* env = &env_i_i;
+TEST_F(AstDecoderTest, ImportCallsWithMismatchedSigs3) {
+ FunctionSig* sig = sigs.i_i();
TestModuleEnv module_env;
- env->module = &module_env;
+ module = &module_env;
byte f0 = module_env.AddImport(sigs.i_f());
- EXPECT_FAILURE_INLINE(env, WASM_CALL_IMPORT0(f0));
- EXPECT_FAILURE_INLINE(env, WASM_CALL_IMPORT(f0, WASM_I8(17)));
- EXPECT_FAILURE_INLINE(env, WASM_CALL_IMPORT(f0, WASM_I64(27)));
- EXPECT_FAILURE_INLINE(env, WASM_CALL_IMPORT(f0, WASM_F64(37.2)));
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT0(f0));
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT(f0, WASM_I8(17)));
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT(f0, WASM_I64V_1(27)));
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT(f0, WASM_F64(37.2)));
byte f1 = module_env.AddImport(sigs.i_d());
- EXPECT_FAILURE_INLINE(env, WASM_CALL_IMPORT0(f1));
- EXPECT_FAILURE_INLINE(env, WASM_CALL_IMPORT(f1, WASM_I8(16)));
- EXPECT_FAILURE_INLINE(env, WASM_CALL_IMPORT(f1, WASM_I64(16)));
- EXPECT_FAILURE_INLINE(env, WASM_CALL_IMPORT(f1, WASM_F32(17.6)));
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT0(f1));
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT(f1, WASM_I8(16)));
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT(f1, WASM_I64V_1(16)));
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT(f1, WASM_F32(17.6)));
}
-TEST_F(WasmDecoderTest, Int32Globals) {
- FunctionEnv* env = &env_i_i;
+TEST_F(AstDecoderTest, Int32Globals) {
+ FunctionSig* sig = sigs.i_i();
TestModuleEnv module_env;
- env->module = &module_env;
+ module = &module_env;
module_env.AddGlobal(MachineType::Int8());
module_env.AddGlobal(MachineType::Uint8());
@@ -1416,131 +1225,116 @@
module_env.AddGlobal(MachineType::Int32());
module_env.AddGlobal(MachineType::Uint32());
- EXPECT_VERIFIES_INLINE(env, WASM_LOAD_GLOBAL(0));
- EXPECT_VERIFIES_INLINE(env, WASM_LOAD_GLOBAL(1));
- EXPECT_VERIFIES_INLINE(env, WASM_LOAD_GLOBAL(2));
- EXPECT_VERIFIES_INLINE(env, WASM_LOAD_GLOBAL(3));
- EXPECT_VERIFIES_INLINE(env, WASM_LOAD_GLOBAL(4));
- EXPECT_VERIFIES_INLINE(env, WASM_LOAD_GLOBAL(5));
+ EXPECT_VERIFIES_INLINE(sig, WASM_LOAD_GLOBAL(0));
+ EXPECT_VERIFIES_INLINE(sig, WASM_LOAD_GLOBAL(1));
+ EXPECT_VERIFIES_INLINE(sig, WASM_LOAD_GLOBAL(2));
+ EXPECT_VERIFIES_INLINE(sig, WASM_LOAD_GLOBAL(3));
+ EXPECT_VERIFIES_INLINE(sig, WASM_LOAD_GLOBAL(4));
+ EXPECT_VERIFIES_INLINE(sig, WASM_LOAD_GLOBAL(5));
- EXPECT_VERIFIES_INLINE(env, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0)));
- EXPECT_VERIFIES_INLINE(env, WASM_STORE_GLOBAL(1, WASM_GET_LOCAL(0)));
- EXPECT_VERIFIES_INLINE(env, WASM_STORE_GLOBAL(2, WASM_GET_LOCAL(0)));
- EXPECT_VERIFIES_INLINE(env, WASM_STORE_GLOBAL(3, WASM_GET_LOCAL(0)));
- EXPECT_VERIFIES_INLINE(env, WASM_STORE_GLOBAL(4, WASM_GET_LOCAL(0)));
- EXPECT_VERIFIES_INLINE(env, WASM_STORE_GLOBAL(5, WASM_GET_LOCAL(0)));
+ EXPECT_VERIFIES_INLINE(sig, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0)));
+ EXPECT_VERIFIES_INLINE(sig, WASM_STORE_GLOBAL(1, WASM_GET_LOCAL(0)));
+ EXPECT_VERIFIES_INLINE(sig, WASM_STORE_GLOBAL(2, WASM_GET_LOCAL(0)));
+ EXPECT_VERIFIES_INLINE(sig, WASM_STORE_GLOBAL(3, WASM_GET_LOCAL(0)));
+ EXPECT_VERIFIES_INLINE(sig, WASM_STORE_GLOBAL(4, WASM_GET_LOCAL(0)));
+ EXPECT_VERIFIES_INLINE(sig, WASM_STORE_GLOBAL(5, WASM_GET_LOCAL(0)));
}
-
-TEST_F(WasmDecoderTest, Int32Globals_fail) {
- FunctionEnv* env = &env_i_i;
+TEST_F(AstDecoderTest, Int32Globals_fail) {
+ FunctionSig* sig = sigs.i_i();
TestModuleEnv module_env;
- env->module = &module_env;
+ module = &module_env;
module_env.AddGlobal(MachineType::Int64());
module_env.AddGlobal(MachineType::Uint64());
module_env.AddGlobal(MachineType::Float32());
module_env.AddGlobal(MachineType::Float64());
- EXPECT_FAILURE_INLINE(env, WASM_LOAD_GLOBAL(0));
- EXPECT_FAILURE_INLINE(env, WASM_LOAD_GLOBAL(1));
- EXPECT_FAILURE_INLINE(env, WASM_LOAD_GLOBAL(2));
- EXPECT_FAILURE_INLINE(env, WASM_LOAD_GLOBAL(3));
+ EXPECT_FAILURE_INLINE(sig, WASM_LOAD_GLOBAL(0));
+ EXPECT_FAILURE_INLINE(sig, WASM_LOAD_GLOBAL(1));
+ EXPECT_FAILURE_INLINE(sig, WASM_LOAD_GLOBAL(2));
+ EXPECT_FAILURE_INLINE(sig, WASM_LOAD_GLOBAL(3));
- EXPECT_FAILURE_INLINE(env, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0)));
- EXPECT_FAILURE_INLINE(env, WASM_STORE_GLOBAL(1, WASM_GET_LOCAL(0)));
- EXPECT_FAILURE_INLINE(env, WASM_STORE_GLOBAL(2, WASM_GET_LOCAL(0)));
- EXPECT_FAILURE_INLINE(env, WASM_STORE_GLOBAL(3, WASM_GET_LOCAL(0)));
+ EXPECT_FAILURE_INLINE(sig, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0)));
+ EXPECT_FAILURE_INLINE(sig, WASM_STORE_GLOBAL(1, WASM_GET_LOCAL(0)));
+ EXPECT_FAILURE_INLINE(sig, WASM_STORE_GLOBAL(2, WASM_GET_LOCAL(0)));
+ EXPECT_FAILURE_INLINE(sig, WASM_STORE_GLOBAL(3, WASM_GET_LOCAL(0)));
}
-
-TEST_F(WasmDecoderTest, Int64Globals) {
- FunctionEnv* env = &env_l_l;
+TEST_F(AstDecoderTest, Int64Globals) {
+ FunctionSig* sig = sigs.l_l();
TestModuleEnv module_env;
- env->module = &module_env;
+ module = &module_env;
module_env.AddGlobal(MachineType::Int64());
module_env.AddGlobal(MachineType::Uint64());
- EXPECT_VERIFIES_INLINE(env, WASM_LOAD_GLOBAL(0));
- EXPECT_VERIFIES_INLINE(env, WASM_LOAD_GLOBAL(1));
+ EXPECT_VERIFIES_INLINE(sig, WASM_LOAD_GLOBAL(0));
+ EXPECT_VERIFIES_INLINE(sig, WASM_LOAD_GLOBAL(1));
- EXPECT_VERIFIES_INLINE(env, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0)));
- EXPECT_VERIFIES_INLINE(env, WASM_STORE_GLOBAL(1, WASM_GET_LOCAL(0)));
+ EXPECT_VERIFIES_INLINE(sig, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0)));
+ EXPECT_VERIFIES_INLINE(sig, WASM_STORE_GLOBAL(1, WASM_GET_LOCAL(0)));
}
-
-TEST_F(WasmDecoderTest, Float32Globals) {
- FunctionEnv env_f_ff;
- FunctionEnv* env = &env_f_ff;
- init_env(env, sigs.f_ff());
+TEST_F(AstDecoderTest, Float32Globals) {
+ FunctionSig* sig = sigs.f_ff();
TestModuleEnv module_env;
- env->module = &module_env;
+ module = &module_env;
module_env.AddGlobal(MachineType::Float32());
- EXPECT_VERIFIES_INLINE(env, WASM_LOAD_GLOBAL(0));
- EXPECT_VERIFIES_INLINE(env, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0)));
+ EXPECT_VERIFIES_INLINE(sig, WASM_LOAD_GLOBAL(0));
+ EXPECT_VERIFIES_INLINE(sig, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0)));
}
-
-TEST_F(WasmDecoderTest, Float64Globals) {
- FunctionEnv env_d_dd;
- FunctionEnv* env = &env_d_dd;
- init_env(env, sigs.d_dd());
+TEST_F(AstDecoderTest, Float64Globals) {
+ FunctionSig* sig = sigs.d_dd();
TestModuleEnv module_env;
- env->module = &module_env;
+ module = &module_env;
module_env.AddGlobal(MachineType::Float64());
- EXPECT_VERIFIES_INLINE(env, WASM_LOAD_GLOBAL(0));
- EXPECT_VERIFIES_INLINE(env, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0)));
+ EXPECT_VERIFIES_INLINE(sig, WASM_LOAD_GLOBAL(0));
+ EXPECT_VERIFIES_INLINE(sig, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0)));
}
-
-TEST_F(WasmDecoderTest, AllLoadGlobalCombinations) {
+TEST_F(AstDecoderTest, AllLoadGlobalCombinations) {
for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
LocalType local_type = kLocalTypes[i];
for (size_t j = 0; j < arraysize(machineTypes); j++) {
MachineType mem_type = machineTypes[j];
- FunctionEnv env;
FunctionSig sig(1, 0, &local_type);
TestModuleEnv module_env;
- init_env(&env, &sig);
- env.module = &module_env;
+ module = &module_env;
module_env.AddGlobal(mem_type);
if (local_type == WasmOpcodes::LocalTypeFor(mem_type)) {
- EXPECT_VERIFIES_INLINE(&env, WASM_LOAD_GLOBAL(0));
+ EXPECT_VERIFIES_INLINE(&sig, WASM_LOAD_GLOBAL(0));
} else {
- EXPECT_FAILURE_INLINE(&env, WASM_LOAD_GLOBAL(0));
+ EXPECT_FAILURE_INLINE(&sig, WASM_LOAD_GLOBAL(0));
}
}
}
}
-
-TEST_F(WasmDecoderTest, AllStoreGlobalCombinations) {
+TEST_F(AstDecoderTest, AllStoreGlobalCombinations) {
for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
LocalType local_type = kLocalTypes[i];
for (size_t j = 0; j < arraysize(machineTypes); j++) {
MachineType mem_type = machineTypes[j];
- FunctionEnv env;
FunctionSig sig(0, 1, &local_type);
TestModuleEnv module_env;
- init_env(&env, &sig);
- env.module = &module_env;
+ module = &module_env;
module_env.AddGlobal(mem_type);
if (local_type == WasmOpcodes::LocalTypeFor(mem_type)) {
- EXPECT_VERIFIES_INLINE(&env, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0)));
+ EXPECT_VERIFIES_INLINE(&sig, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0)));
} else {
- EXPECT_FAILURE_INLINE(&env, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0)));
+ EXPECT_FAILURE_INLINE(&sig, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0)));
}
}
}
}
-
-TEST_F(WasmDecoderTest, BreakNesting1) {
+TEST_F(AstDecoderTest, BreakNesting1) {
for (int i = 0; i < 5; i++) {
// (block[2] (loop[2] (if (get p) break[N]) (set p 1)) p)
byte code[] = {WASM_BLOCK(
@@ -1548,65 +1342,60 @@
WASM_SET_LOCAL(0, WASM_I8(1))),
WASM_GET_LOCAL(0))};
if (i < 3) {
- EXPECT_VERIFIES(&env_i_i, code);
+ EXPECT_VERIFIES(sigs.i_i(), code);
} else {
- EXPECT_FAILURE(&env_i_i, code);
+ EXPECT_FAILURE(sigs.i_i(), code);
}
}
}
-
-TEST_F(WasmDecoderTest, BreakNesting2) {
- env_v_v.AddLocals(kAstI32, 1);
+TEST_F(AstDecoderTest, BreakNesting2) {
+ AddLocals(kAstI32, 1);
for (int i = 0; i < 5; i++) {
- // (block[2] (loop[2] (if (get p) break[N]) (set p 1)) (return p)) (11)
- byte code[] = {
- WASM_BLOCK(1, WASM_LOOP(2, WASM_IF(WASM_GET_LOCAL(0), WASM_BREAK(i)),
- WASM_SET_LOCAL(0, WASM_I8(1)))),
- WASM_I8(11)};
+ // (block[2] (loop[2] (if 0 break[N]) (set p 1)) (return p)) (11)
+ byte code[] = {WASM_BLOCK(1, WASM_LOOP(2, WASM_IF(WASM_ZERO, WASM_BREAK(i)),
+ WASM_SET_LOCAL(0, WASM_I8(1)))),
+ WASM_I8(11)};
if (i < 2) {
- EXPECT_VERIFIES(&env_v_v, code);
+ EXPECT_VERIFIES(sigs.v_v(), code);
} else {
- EXPECT_FAILURE(&env_v_v, code);
+ EXPECT_FAILURE(sigs.v_v(), code);
}
}
}
-
-TEST_F(WasmDecoderTest, BreakNesting3) {
- env_v_v.AddLocals(kAstI32, 1);
+TEST_F(AstDecoderTest, BreakNesting3) {
for (int i = 0; i < 5; i++) {
- // (block[1] (loop[1] (block[1] (if (get p) break[N])
+ // (block[1] (loop[1] (block[1] (if 0 break[N])
byte code[] = {WASM_BLOCK(
- 1, WASM_LOOP(
- 1, WASM_BLOCK(1, WASM_IF(WASM_GET_LOCAL(0), WASM_BREAK(i)))))};
+ 1, WASM_LOOP(1, WASM_BLOCK(1, WASM_IF(WASM_ZERO, WASM_BREAK(i)))))};
if (i < 3) {
- EXPECT_VERIFIES(&env_v_v, code);
+ EXPECT_VERIFIES(sigs.v_v(), code);
} else {
- EXPECT_FAILURE(&env_v_v, code);
+ EXPECT_FAILURE(sigs.v_v(), code);
}
}
}
-
-TEST_F(WasmDecoderTest, BreaksWithMultipleTypes) {
+TEST_F(AstDecoderTest, BreaksWithMultipleTypes) {
EXPECT_FAILURE_INLINE(
- &env_i_i, WASM_BLOCK(2, WASM_BRV_IF_ZERO(0, WASM_I8(7)), WASM_F32(7.7)));
+ sigs.i_i(),
+ WASM_BLOCK(2, WASM_BRV_IF_ZERO(0, WASM_I8(7)), WASM_F32(7.7)));
- EXPECT_FAILURE_INLINE(&env_i_i,
+ EXPECT_FAILURE_INLINE(sigs.i_i(),
WASM_BLOCK(2, WASM_BRV_IF_ZERO(0, WASM_I8(7)),
WASM_BRV_IF_ZERO(0, WASM_F32(7.7))));
- EXPECT_FAILURE_INLINE(&env_i_i,
+ EXPECT_FAILURE_INLINE(sigs.i_i(),
WASM_BLOCK(3, WASM_BRV_IF_ZERO(0, WASM_I8(8)),
WASM_BRV_IF_ZERO(0, WASM_I8(0)),
WASM_BRV_IF_ZERO(0, WASM_F32(7.7))));
- EXPECT_FAILURE_INLINE(&env_i_i, WASM_BLOCK(3, WASM_BRV_IF_ZERO(0, WASM_I8(9)),
- WASM_BRV_IF_ZERO(0, WASM_F32(7.7)),
- WASM_BRV_IF_ZERO(0, WASM_I8(11))));
+ EXPECT_FAILURE_INLINE(sigs.i_i(),
+ WASM_BLOCK(3, WASM_BRV_IF_ZERO(0, WASM_I8(9)),
+ WASM_BRV_IF_ZERO(0, WASM_F32(7.7)),
+ WASM_BRV_IF_ZERO(0, WASM_I8(11))));
}
-
-TEST_F(WasmDecoderTest, BreakNesting_6_levels) {
+TEST_F(AstDecoderTest, BreakNesting_6_levels) {
for (int mask = 0; mask < 64; mask++) {
for (int i = 0; i < 14; i++) {
byte code[] = {
@@ -1629,39 +1418,37 @@
}
if (i < depth) {
- EXPECT_VERIFIES(&env_v_v, code);
+ EXPECT_VERIFIES(sigs.v_v(), code);
} else {
- EXPECT_FAILURE(&env_v_v, code);
+ EXPECT_FAILURE(sigs.v_v(), code);
}
}
}
}
-
-TEST_F(WasmDecoderTest, ExprBreak_TypeCheck) {
- FunctionEnv* envs[] = {&env_i_i, &env_l_l, &env_f_ff, &env_d_dd};
- for (size_t i = 0; i < arraysize(envs); i++) {
- FunctionEnv* env = envs[i];
+TEST_F(AstDecoderTest, ExprBreak_TypeCheck) {
+ FunctionSig* sigarray[] = {sigs.i_i(), sigs.l_l(), sigs.f_ff(), sigs.d_dd()};
+ for (size_t i = 0; i < arraysize(sigarray); i++) {
+ FunctionSig* sig = sigarray[i];
// unify X and X => OK
EXPECT_VERIFIES_INLINE(
- env, WASM_BLOCK(2, WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))),
+ sig, WASM_BLOCK(2, WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))),
WASM_GET_LOCAL(0)));
}
// unify i32 and f32 => fail
EXPECT_FAILURE_INLINE(
- &env_i_i,
+ sigs.i_i(),
WASM_BLOCK(2, WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_ZERO)), WASM_F32(1.2)));
// unify f64 and f64 => OK
EXPECT_VERIFIES_INLINE(
- &env_d_dd,
+ sigs.d_dd(),
WASM_BLOCK(2, WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))),
WASM_F64(1.2)));
}
-
-TEST_F(WasmDecoderTest, ExprBreak_TypeCheckAll) {
+TEST_F(AstDecoderTest, ExprBreak_TypeCheckAll) {
byte code1[] = {WASM_BLOCK(2,
WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))),
WASM_GET_LOCAL(1))};
@@ -1671,32 +1458,26 @@
for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
for (size_t j = 0; j < arraysize(kLocalTypes); j++) {
- FunctionEnv env;
LocalType storage[] = {kLocalTypes[i], kLocalTypes[i], kLocalTypes[j]};
FunctionSig sig(1, 2, storage);
- init_env(&env, &sig);
if (i == j) {
- EXPECT_VERIFIES(&env, code1);
- EXPECT_VERIFIES(&env, code2);
+ EXPECT_VERIFIES(&sig, code1);
+ EXPECT_VERIFIES(&sig, code2);
} else {
- EXPECT_FAILURE(&env, code1);
- EXPECT_FAILURE(&env, code2);
+ EXPECT_FAILURE(&sig, code1);
+ EXPECT_FAILURE(&sig, code2);
}
}
}
}
-
-TEST_F(WasmDecoderTest, ExprBr_Unify) {
- FunctionEnv env;
-
+TEST_F(AstDecoderTest, ExprBr_Unify) {
for (int which = 0; which < 2; which++) {
for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
LocalType type = kLocalTypes[i];
LocalType storage[] = {kAstI32, kAstI32, type};
FunctionSig sig(1, 2, storage);
- init_env(&env, &sig); // (i32, X) -> i32
byte code1[] = {
WASM_BLOCK(2, WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(which))),
@@ -1707,37 +1488,34 @@
if (type == kAstI32) {
- EXPECT_VERIFIES(&env, code1);
- EXPECT_VERIFIES(&env, code2);
+ EXPECT_VERIFIES(&sig, code1);
+ EXPECT_VERIFIES(&sig, code2);
} else {
- EXPECT_FAILURE(&env, code1);
- EXPECT_FAILURE(&env, code2);
+ EXPECT_FAILURE(&sig, code1);
+ EXPECT_FAILURE(&sig, code2);
}
}
}
}
-TEST_F(WasmDecoderTest, ExprBrIf_cond_type) {
- FunctionEnv env;
+TEST_F(AstDecoderTest, ExprBrIf_cond_type) {
byte code[] = {
WASM_BLOCK(1, WASM_BRV_IF(0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)))};
for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
for (size_t j = 0; j < arraysize(kLocalTypes); j++) {
LocalType types[] = {kLocalTypes[i], kLocalTypes[j]};
FunctionSig sig(0, 2, types);
- init_env(&env, &sig);
if (types[1] == kAstI32) {
- EXPECT_VERIFIES(&env, code);
+ EXPECT_VERIFIES(&sig, code);
} else {
- EXPECT_FAILURE(&env, code);
+ EXPECT_FAILURE(&sig, code);
}
}
}
}
-TEST_F(WasmDecoderTest, ExprBrIf_val_type) {
- FunctionEnv env;
+TEST_F(AstDecoderTest, ExprBrIf_val_type) {
byte code[] = {
WASM_BLOCK(2, WASM_BRV_IF(0, WASM_GET_LOCAL(1), WASM_GET_LOCAL(2)),
WASM_GET_LOCAL(0))};
@@ -1746,27 +1524,22 @@
LocalType types[] = {kLocalTypes[i], kLocalTypes[i], kLocalTypes[j],
kAstI32};
FunctionSig sig(1, 3, types);
- init_env(&env, &sig);
if (i == j) {
- EXPECT_VERIFIES(&env, code);
+ EXPECT_VERIFIES(&sig, code);
} else {
- EXPECT_FAILURE(&env, code);
+ EXPECT_FAILURE(&sig, code);
}
}
}
}
-
-TEST_F(WasmDecoderTest, ExprBrIf_Unify) {
- FunctionEnv env;
-
+TEST_F(AstDecoderTest, ExprBrIf_Unify) {
for (int which = 0; which < 2; which++) {
for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
LocalType type = kLocalTypes[i];
LocalType storage[] = {kAstI32, kAstI32, type};
FunctionSig sig(1, 2, storage);
- init_env(&env, &sig); // (i32, X) -> i32
byte code1[] = {WASM_BLOCK(2, WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(which)),
WASM_GET_LOCAL(which ^ 1))};
@@ -1774,221 +1547,171 @@
WASM_GET_LOCAL(which ^ 1))};
if (type == kAstI32) {
- EXPECT_VERIFIES(&env, code1);
- EXPECT_VERIFIES(&env, code2);
+ EXPECT_VERIFIES(&sig, code1);
+ EXPECT_VERIFIES(&sig, code2);
} else {
- EXPECT_FAILURE(&env, code1);
- EXPECT_FAILURE(&env, code2);
+ EXPECT_FAILURE(&sig, code1);
+ EXPECT_FAILURE(&sig, code2);
}
}
}
}
-
-TEST_F(WasmDecoderTest, TableSwitch0) {
- static byte code[] = {kExprTableSwitch, 0, 0, 0, 0};
- EXPECT_FAILURE(&env_v_v, code);
+TEST_F(AstDecoderTest, BrTable0) {
+ static byte code[] = {kExprBrTable, 0, 0};
+ EXPECT_FAILURE(sigs.v_v(), code);
}
-
-TEST_F(WasmDecoderTest, TableSwitch0b) {
- static byte code[] = {kExprTableSwitch, 0, 0, 0, 0, kExprI8Const, 11};
- EXPECT_FAILURE(&env_v_v, code);
- EXPECT_FAILURE(&env_i_i, code);
+TEST_F(AstDecoderTest, BrTable0b) {
+ static byte code[] = {kExprBrTable, 0, 0, kExprI32Const, 11};
+ EXPECT_FAILURE(sigs.v_v(), code);
+ EXPECT_FAILURE(sigs.i_i(), code);
}
+TEST_F(AstDecoderTest, BrTable0c) {
+ static byte code[] = {kExprBrTable, 0, 1, 0, 0, kExprI32Const, 11};
+ EXPECT_FAILURE(sigs.v_v(), code);
+ EXPECT_FAILURE(sigs.i_i(), code);
+}
-TEST_F(WasmDecoderTest, TableSwitch0c) {
+TEST_F(AstDecoderTest, BrTable1a) {
static byte code[] = {
- WASM_BLOCK(1, WASM_TABLESWITCH_OP(0, 1, WASM_CASE_BR(0)), WASM_I8(67))};
- EXPECT_VERIFIES(&env_v_v, code);
+ WASM_BLOCK(1, WASM_BR_TABLE(WASM_I8(67), 0, BR_TARGET(0)))};
+ EXPECT_VERIFIES(sigs.v_v(), code);
}
-TEST_F(WasmDecoderTest, TableSwitch0d) {
+TEST_F(AstDecoderTest, BrTable1b) {
static byte code[] = {
- WASM_BLOCK(1, WASM_TABLESWITCH_OP(0, 2, WASM_CASE_BR(0), WASM_CASE_BR(1)),
- WASM_I8(67))};
- EXPECT_VERIFIES(&env_v_v, code);
+ WASM_BLOCK(1, WASM_BR_TABLE(WASM_ZERO, 0, BR_TARGET(0)))};
+ EXPECT_VERIFIES(sigs.v_v(), code);
+ EXPECT_FAILURE(sigs.i_i(), code);
+ EXPECT_FAILURE(sigs.f_ff(), code);
+ EXPECT_FAILURE(sigs.d_dd(), code);
}
-TEST_F(WasmDecoderTest, TableSwitch1) {
- static byte code[] = {WASM_TABLESWITCH_OP(1, 1, WASM_CASE(0)),
- WASM_TABLESWITCH_BODY(WASM_I8(0), WASM_I8(9))};
- EXPECT_VERIFIES(&env_i_i, code);
- EXPECT_VERIFIES(&env_v_v, code);
- EXPECT_FAILURE(&env_f_ff, code);
- EXPECT_FAILURE(&env_d_dd, code);
+TEST_F(AstDecoderTest, BrTable2a) {
+ static byte code[] = {
+ WASM_BLOCK(1, WASM_BR_TABLE(WASM_I8(67), 1, BR_TARGET(0), BR_TARGET(0)))};
+ EXPECT_VERIFIES(sigs.v_v(), code);
}
+TEST_F(AstDecoderTest, BrTable2b) {
+ static byte code[] = {WASM_BLOCK(
+ 1, WASM_BLOCK(
+ 1, WASM_BR_TABLE(WASM_I8(67), 1, BR_TARGET(0), BR_TARGET(1))))};
+ EXPECT_VERIFIES(sigs.v_v(), code);
+}
-TEST_F(WasmDecoderTest, TableSwitch_off_end) {
- static byte code[] = {WASM_TABLESWITCH_OP(1, 1, WASM_CASE(0)),
- WASM_TABLESWITCH_BODY(WASM_I8(0), WASM_I8(9))};
- for (size_t len = arraysize(code) - 1; len > 0; len--) {
- Verify(kError, &env_v_v, code, code + len);
+TEST_F(AstDecoderTest, BrTable_off_end) {
+ static byte code[] = {
+ WASM_BLOCK(1, WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(0)))};
+ for (size_t len = 1; len < sizeof(code); len++) {
+ Verify(kError, sigs.i_i(), code, code + len);
}
}
-
-TEST_F(WasmDecoderTest, TableSwitch2) {
- static byte code[] = {
- WASM_TABLESWITCH_OP(2, 2, WASM_CASE(0), WASM_CASE(1)),
- WASM_TABLESWITCH_BODY(WASM_I8(3), WASM_I8(10), WASM_I8(11))};
- EXPECT_VERIFIES(&env_i_i, code);
- EXPECT_VERIFIES(&env_v_v, code);
- EXPECT_FAILURE(&env_f_ff, code);
- EXPECT_FAILURE(&env_d_dd, code);
-}
-
-
-TEST_F(WasmDecoderTest, TableSwitch1b) {
- EXPECT_VERIFIES_INLINE(&env_i_i, WASM_TABLESWITCH_OP(1, 1, WASM_CASE(0)),
- WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0), WASM_ZERO));
-
- EXPECT_VERIFIES_INLINE(&env_f_ff, WASM_TABLESWITCH_OP(1, 1, WASM_CASE(0)),
- WASM_TABLESWITCH_BODY(WASM_ZERO, WASM_F32(0.0)));
-
- EXPECT_VERIFIES_INLINE(&env_d_dd, WASM_TABLESWITCH_OP(1, 1, WASM_CASE(0)),
- WASM_TABLESWITCH_BODY(WASM_ZERO, WASM_F64(0.0)));
-}
-
-TEST_F(WasmDecoderTest, TableSwitch_br1) {
- for (int depth = 0; depth < 2; depth++) {
- byte code[] = {WASM_BLOCK(1, WASM_TABLESWITCH_OP(0, 1, WASM_CASE_BR(depth)),
- WASM_GET_LOCAL(0))};
- EXPECT_VERIFIES(&env_v_i, code);
- EXPECT_FAILURE(&env_i_i, code);
+TEST_F(AstDecoderTest, BrTable_invalid_br1) {
+ for (int depth = 0; depth < 4; depth++) {
+ byte code[] = {
+ WASM_BLOCK(1, WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(depth)))};
+ if (depth == 0) {
+ EXPECT_VERIFIES(sigs.v_i(), code);
+ } else {
+ EXPECT_FAILURE(sigs.v_i(), code);
+ }
}
}
-
-TEST_F(WasmDecoderTest, TableSwitch_invalid_br) {
- for (int depth = 1; depth < 4; depth++) {
- EXPECT_FAILURE_INLINE(&env_v_i,
- WASM_TABLESWITCH_OP(0, 1, WASM_CASE_BR(depth)),
- WASM_GET_LOCAL(0));
- EXPECT_FAILURE_INLINE(
- &env_v_i,
- WASM_TABLESWITCH_OP(0, 2, WASM_CASE_BR(depth), WASM_CASE_BR(depth)),
- WASM_GET_LOCAL(0));
+TEST_F(AstDecoderTest, BrTable_invalid_br2) {
+ for (int depth = 0; depth < 4; depth++) {
+ byte code[] = {
+ WASM_LOOP(1, WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(depth)))};
+ if (depth <= 1) {
+ EXPECT_VERIFIES(sigs.v_i(), code);
+ } else {
+ EXPECT_FAILURE(sigs.v_i(), code);
+ }
}
}
-
-TEST_F(WasmDecoderTest, TableSwitch_invalid_case_ref) {
- EXPECT_FAILURE_INLINE(&env_i_i, WASM_TABLESWITCH_OP(0, 1, WASM_CASE(0)),
- WASM_GET_LOCAL(0));
- EXPECT_FAILURE_INLINE(&env_i_i, WASM_TABLESWITCH_OP(1, 1, WASM_CASE(1)),
- WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0), WASM_ZERO));
-}
-
-
-TEST_F(WasmDecoderTest, TableSwitch1_br) {
- EXPECT_VERIFIES_INLINE(
- &env_i_i, WASM_TABLESWITCH_OP(1, 1, WASM_CASE(0)),
- WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0), WASM_BRV(0, WASM_ZERO)));
-}
-
-
-TEST_F(WasmDecoderTest, TableSwitch2_br) {
- EXPECT_VERIFIES_INLINE(
- &env_i_i, WASM_TABLESWITCH_OP(2, 2, WASM_CASE(0), WASM_CASE(1)),
- WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0), WASM_BRV(0, WASM_I8(0)),
- WASM_BRV(0, WASM_I8(1))));
-
- EXPECT_FAILURE_INLINE(
- &env_f_ff, WASM_TABLESWITCH_OP(2, 2, WASM_CASE(0), WASM_CASE(1)),
- WASM_TABLESWITCH_BODY(WASM_ZERO, WASM_BRV(0, WASM_I8(3)),
- WASM_BRV(0, WASM_I8(4))));
-}
-
-
-TEST_F(WasmDecoderTest, TableSwitch2x2) {
- EXPECT_VERIFIES_INLINE(
- &env_i_i, WASM_TABLESWITCH_OP(2, 4, WASM_CASE(0), WASM_CASE(1),
- WASM_CASE(0), WASM_CASE(1)),
- WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0), WASM_BRV(0, WASM_I8(3)),
- WASM_BRV(0, WASM_I8(4))));
-}
-
-
-TEST_F(WasmDecoderTest, ExprBreakNesting1) {
- EXPECT_VERIFIES_INLINE(&env_v_v, WASM_BLOCK(1, WASM_BRV(0, WASM_ZERO)));
- EXPECT_VERIFIES_INLINE(&env_v_v, WASM_BLOCK(1, WASM_BR(0)));
- EXPECT_VERIFIES_INLINE(&env_v_v,
+TEST_F(AstDecoderTest, ExprBreakNesting1) {
+ EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_BLOCK(1, WASM_BRV(0, WASM_ZERO)));
+ EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_BLOCK(1, WASM_BR(0)));
+ EXPECT_VERIFIES_INLINE(sigs.v_v(),
WASM_BLOCK(1, WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO)));
- EXPECT_VERIFIES_INLINE(&env_v_v, WASM_BLOCK(1, WASM_BR_IF(0, WASM_ZERO)));
+ EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_BLOCK(1, WASM_BR_IF(0, WASM_ZERO)));
- EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(1, WASM_BRV(0, WASM_ZERO)));
- EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(1, WASM_BR(0)));
- EXPECT_VERIFIES_INLINE(&env_v_v,
+ EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(1, WASM_BRV(0, WASM_ZERO)));
+ EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(1, WASM_BR(0)));
+ EXPECT_VERIFIES_INLINE(sigs.v_v(),
WASM_LOOP(1, WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO)));
- EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(1, WASM_BR_IF(0, WASM_ZERO)));
+ EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(1, WASM_BR_IF(0, WASM_ZERO)));
- EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(1, WASM_BRV(1, WASM_ZERO)));
- EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(1, WASM_BR(1)));
+ EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(1, WASM_BRV(1, WASM_ZERO)));
+ EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(1, WASM_BR(1)));
}
-
-TEST_F(WasmDecoderTest, Select) {
+TEST_F(AstDecoderTest, Select) {
EXPECT_VERIFIES_INLINE(
- &env_i_i, WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_ZERO));
- EXPECT_VERIFIES_INLINE(&env_f_ff,
+ sigs.i_i(), WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_ZERO));
+ EXPECT_VERIFIES_INLINE(sigs.f_ff(),
WASM_SELECT(WASM_F32(0.0), WASM_F32(0.0), WASM_ZERO));
- EXPECT_VERIFIES_INLINE(&env_d_dd,
+ EXPECT_VERIFIES_INLINE(sigs.d_dd(),
WASM_SELECT(WASM_F64(0.0), WASM_F64(0.0), WASM_ZERO));
- EXPECT_VERIFIES_INLINE(&env_l_l,
- WASM_SELECT(WASM_I64(0), WASM_I64(0), WASM_ZERO));
+ EXPECT_VERIFIES_INLINE(
+ sigs.l_l(), WASM_SELECT(WASM_I64V_1(0), WASM_I64V_1(0), WASM_ZERO));
}
-TEST_F(WasmDecoderTest, Select_fail1) {
- EXPECT_FAILURE_INLINE(&env_i_i, WASM_SELECT(WASM_F32(0.0), WASM_GET_LOCAL(0),
- WASM_GET_LOCAL(0)));
- EXPECT_FAILURE_INLINE(&env_i_i, WASM_SELECT(WASM_GET_LOCAL(0), WASM_F32(0.0),
- WASM_GET_LOCAL(0)));
+TEST_F(AstDecoderTest, Select_fail1) {
EXPECT_FAILURE_INLINE(
- &env_i_i,
+ sigs.i_i(),
+ WASM_SELECT(WASM_F32(0.0), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0)));
+ EXPECT_FAILURE_INLINE(
+ sigs.i_i(),
+ WASM_SELECT(WASM_GET_LOCAL(0), WASM_F32(0.0), WASM_GET_LOCAL(0)));
+ EXPECT_FAILURE_INLINE(
+ sigs.i_i(),
WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_F32(0.0)));
}
-TEST_F(WasmDecoderTest, Select_fail2) {
+TEST_F(AstDecoderTest, Select_fail2) {
for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
LocalType type = kLocalTypes[i];
if (type == kAstI32) continue;
LocalType types[] = {type, kAstI32, type};
FunctionSig sig(1, 2, types);
- FunctionEnv env;
- init_env(&env, &sig);
EXPECT_VERIFIES_INLINE(
- &env,
+ &sig,
WASM_SELECT(WASM_GET_LOCAL(1), WASM_GET_LOCAL(1), WASM_GET_LOCAL(0)));
EXPECT_FAILURE_INLINE(
- &env,
+ &sig,
WASM_SELECT(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0)));
EXPECT_FAILURE_INLINE(
- &env,
+ &sig,
WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), WASM_GET_LOCAL(0)));
EXPECT_FAILURE_INLINE(
- &env,
+ &sig,
WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
}
}
-
-TEST_F(WasmDecoderTest, Select_TypeCheck) {
- EXPECT_FAILURE_INLINE(&env_i_i, WASM_SELECT(WASM_F32(9.9), WASM_GET_LOCAL(0),
- WASM_GET_LOCAL(0)));
-
- EXPECT_FAILURE_INLINE(&env_i_i, WASM_SELECT(WASM_GET_LOCAL(0), WASM_F64(0.25),
- WASM_GET_LOCAL(0)));
+TEST_F(AstDecoderTest, Select_TypeCheck) {
+ EXPECT_FAILURE_INLINE(
+ sigs.i_i(),
+ WASM_SELECT(WASM_F32(9.9), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0)));
EXPECT_FAILURE_INLINE(
- &env_i_i, WASM_SELECT(WASM_F32(9.9), WASM_GET_LOCAL(0), WASM_I64(0)));
+ sigs.i_i(),
+ WASM_SELECT(WASM_GET_LOCAL(0), WASM_F64(0.25), WASM_GET_LOCAL(0)));
+
+ EXPECT_FAILURE_INLINE(
+ sigs.i_i(),
+ WASM_SELECT(WASM_F32(9.9), WASM_GET_LOCAL(0), WASM_I64V_1(0)));
}
@@ -2003,6 +1726,12 @@
EXPECT_EQ(expected, OpcodeLength(code, code + sizeof(code))); \
}
+#define EXPECT_LENGTH_N(expected, ...) \
+ { \
+ static const byte code[] = {__VA_ARGS__}; \
+ EXPECT_EQ(expected, OpcodeLength(code, code + sizeof(code))); \
+ }
+
TEST_F(WasmOpcodeLengthTest, Statements) {
EXPECT_LENGTH(1, kExprNop);
EXPECT_LENGTH(2, kExprBlock);
@@ -2017,9 +1746,7 @@
TEST_F(WasmOpcodeLengthTest, MiscExpressions) {
EXPECT_LENGTH(2, kExprI8Const);
- EXPECT_LENGTH(5, kExprI32Const);
EXPECT_LENGTH(5, kExprF32Const);
- EXPECT_LENGTH(9, kExprI64Const);
EXPECT_LENGTH(9, kExprF64Const);
EXPECT_LENGTH(2, kExprGetLocal);
EXPECT_LENGTH(2, kExprSetLocal);
@@ -2036,47 +1763,59 @@
EXPECT_LENGTH(2, kExprBrIf);
}
-
-TEST_F(WasmOpcodeLengthTest, VariableLength) {
- byte size2[] = {kExprLoadGlobal, 1};
- byte size3[] = {kExprLoadGlobal, 1 | 0x80, 2};
- byte size4[] = {kExprLoadGlobal, 1 | 0x80, 2 | 0x80, 3};
- byte size5[] = {kExprLoadGlobal, 1 | 0x80, 2 | 0x80, 3 | 0x80, 4};
- byte size6[] = {kExprLoadGlobal, 1 | 0x80, 2 | 0x80, 3 | 0x80, 4 | 0x80, 5};
-
- EXPECT_EQ(2, OpcodeLength(size2, size2 + sizeof(size2)));
- EXPECT_EQ(3, OpcodeLength(size3, size3 + sizeof(size3)));
- EXPECT_EQ(4, OpcodeLength(size4, size4 + sizeof(size4)));
- EXPECT_EQ(5, OpcodeLength(size5, size5 + sizeof(size5)));
- EXPECT_EQ(6, OpcodeLength(size6, size6 + sizeof(size6)));
+TEST_F(WasmOpcodeLengthTest, I32Const) {
+ EXPECT_LENGTH_N(2, kExprI32Const, U32V_1(1));
+ EXPECT_LENGTH_N(3, kExprI32Const, U32V_2(999));
+ EXPECT_LENGTH_N(4, kExprI32Const, U32V_3(9999));
+ EXPECT_LENGTH_N(5, kExprI32Const, U32V_4(999999));
+ EXPECT_LENGTH_N(6, kExprI32Const, U32V_5(99999999));
}
+TEST_F(WasmOpcodeLengthTest, I64Const) {
+ EXPECT_LENGTH_N(2, kExprI64Const, U32V_1(1));
+ EXPECT_LENGTH_N(3, kExprI64Const, U32V_2(99));
+ EXPECT_LENGTH_N(4, kExprI64Const, U32V_3(9999));
+ EXPECT_LENGTH_N(5, kExprI64Const, U32V_4(99999));
+ EXPECT_LENGTH_N(6, kExprI64Const, U32V_5(9999999));
+ EXPECT_LENGTH_N(7, WASM_I64V_6(777777));
+ EXPECT_LENGTH_N(8, WASM_I64V_7(7777777));
+ EXPECT_LENGTH_N(9, WASM_I64V_8(77777777));
+ EXPECT_LENGTH_N(10, WASM_I64V_9(777777777));
+}
+
+TEST_F(WasmOpcodeLengthTest, VariableLength) {
+ EXPECT_LENGTH_N(2, kExprLoadGlobal, U32V_1(1));
+ EXPECT_LENGTH_N(3, kExprLoadGlobal, U32V_2(33));
+ EXPECT_LENGTH_N(4, kExprLoadGlobal, U32V_3(44));
+ EXPECT_LENGTH_N(5, kExprLoadGlobal, U32V_4(66));
+ EXPECT_LENGTH_N(6, kExprLoadGlobal, U32V_5(77));
+}
TEST_F(WasmOpcodeLengthTest, LoadsAndStores) {
- EXPECT_LENGTH(2, kExprI32LoadMem8S);
- EXPECT_LENGTH(2, kExprI32LoadMem8U);
- EXPECT_LENGTH(2, kExprI32LoadMem16S);
- EXPECT_LENGTH(2, kExprI32LoadMem16U);
- EXPECT_LENGTH(2, kExprI32LoadMem);
- EXPECT_LENGTH(2, kExprI64LoadMem8S);
- EXPECT_LENGTH(2, kExprI64LoadMem8U);
- EXPECT_LENGTH(2, kExprI64LoadMem16S);
- EXPECT_LENGTH(2, kExprI64LoadMem16U);
- EXPECT_LENGTH(2, kExprI64LoadMem32S);
- EXPECT_LENGTH(2, kExprI64LoadMem32U);
- EXPECT_LENGTH(2, kExprI64LoadMem);
- EXPECT_LENGTH(2, kExprF32LoadMem);
- EXPECT_LENGTH(2, kExprF64LoadMem);
+ EXPECT_LENGTH(3, kExprI32LoadMem8S);
+ EXPECT_LENGTH(3, kExprI32LoadMem8U);
+ EXPECT_LENGTH(3, kExprI32LoadMem16S);
+ EXPECT_LENGTH(3, kExprI32LoadMem16U);
+ EXPECT_LENGTH(3, kExprI32LoadMem);
+ EXPECT_LENGTH(3, kExprI64LoadMem8S);
+ EXPECT_LENGTH(3, kExprI64LoadMem8U);
+ EXPECT_LENGTH(3, kExprI64LoadMem16S);
+ EXPECT_LENGTH(3, kExprI64LoadMem16U);
+ EXPECT_LENGTH(3, kExprI64LoadMem32S);
+ EXPECT_LENGTH(3, kExprI64LoadMem32U);
+ EXPECT_LENGTH(3, kExprI64LoadMem);
+ EXPECT_LENGTH(3, kExprF32LoadMem);
+ EXPECT_LENGTH(3, kExprF64LoadMem);
- EXPECT_LENGTH(2, kExprI32StoreMem8);
- EXPECT_LENGTH(2, kExprI32StoreMem16);
- EXPECT_LENGTH(2, kExprI32StoreMem);
- EXPECT_LENGTH(2, kExprI64StoreMem8);
- EXPECT_LENGTH(2, kExprI64StoreMem16);
- EXPECT_LENGTH(2, kExprI64StoreMem32);
- EXPECT_LENGTH(2, kExprI64StoreMem);
- EXPECT_LENGTH(2, kExprF32StoreMem);
- EXPECT_LENGTH(2, kExprF64StoreMem);
+ EXPECT_LENGTH(3, kExprI32StoreMem8);
+ EXPECT_LENGTH(3, kExprI32StoreMem16);
+ EXPECT_LENGTH(3, kExprI32StoreMem);
+ EXPECT_LENGTH(3, kExprI64StoreMem8);
+ EXPECT_LENGTH(3, kExprI64StoreMem16);
+ EXPECT_LENGTH(3, kExprI64StoreMem32);
+ EXPECT_LENGTH(3, kExprI64StoreMem);
+ EXPECT_LENGTH(3, kExprF32StoreMem);
+ EXPECT_LENGTH(3, kExprF64StoreMem);
}
@@ -2113,7 +1852,7 @@
EXPECT_LENGTH(1, kExprI32Clz);
EXPECT_LENGTH(1, kExprI32Ctz);
EXPECT_LENGTH(1, kExprI32Popcnt);
- EXPECT_LENGTH(1, kExprBoolNot);
+ EXPECT_LENGTH(1, kExprI32Eqz);
EXPECT_LENGTH(1, kExprI64Add);
EXPECT_LENGTH(1, kExprI64Sub);
EXPECT_LENGTH(1, kExprI64Mul);
@@ -2211,16 +1950,18 @@
class WasmOpcodeArityTest : public TestWithZone {
public:
WasmOpcodeArityTest() : TestWithZone() {}
+ TestModuleEnv module;
+ TestSignatures sigs;
};
-#define EXPECT_ARITY(expected, ...) \
- { \
- static const byte code[] = {__VA_ARGS__}; \
- EXPECT_EQ(expected, OpcodeArity(&env, code, code + sizeof(code))); \
+#define EXPECT_ARITY(expected, ...) \
+ { \
+ static const byte code[] = {__VA_ARGS__}; \
+ EXPECT_EQ(expected, OpcodeArity(&module, sig, code, code + sizeof(code))); \
}
TEST_F(WasmOpcodeArityTest, Control) {
- FunctionEnv env;
+ FunctionSig* sig = sigs.v_v();
EXPECT_ARITY(0, kExprNop);
EXPECT_ARITY(0, kExprBlock, 0);
@@ -2243,19 +1984,16 @@
EXPECT_ARITY(2, kExprBrIf);
{
- TestSignatures sigs;
- FunctionEnv env;
- WasmDecoderTest::init_env(&env, sigs.v_v());
+ sig = sigs.v_v();
EXPECT_ARITY(0, kExprReturn);
- WasmDecoderTest::init_env(&env, sigs.i_i());
+ sig = sigs.i_i();
EXPECT_ARITY(1, kExprReturn);
}
}
TEST_F(WasmOpcodeArityTest, Misc) {
- FunctionEnv env;
-
+ FunctionSig* sig = sigs.v_v();
EXPECT_ARITY(0, kExprI8Const);
EXPECT_ARITY(0, kExprI32Const);
EXPECT_ARITY(0, kExprF32Const);
@@ -2269,8 +2007,6 @@
TEST_F(WasmOpcodeArityTest, Calls) {
- TestSignatures sigs;
- TestModuleEnv module;
module.AddFunction(sigs.i_ii());
module.AddFunction(sigs.i_i());
@@ -2281,9 +2017,7 @@
module.AddImport(sigs.i_d());
{
- FunctionEnv env;
- WasmDecoderTest::init_env(&env, sigs.i_ii());
- env.module = &module;
+ FunctionSig* sig = sigs.i_ii();
EXPECT_ARITY(2, kExprCallFunction, 0);
EXPECT_ARITY(2, kExprCallImport, 0);
@@ -2293,9 +2027,7 @@
}
{
- FunctionEnv env;
- WasmDecoderTest::init_env(&env, sigs.v_v());
- env.module = &module;
+ FunctionSig* sig = sigs.v_v();
EXPECT_ARITY(1, kExprCallFunction, 1);
EXPECT_ARITY(1, kExprCallImport, 1);
@@ -2307,8 +2039,7 @@
TEST_F(WasmOpcodeArityTest, LoadsAndStores) {
- FunctionEnv env;
-
+ FunctionSig* sig = sigs.v_v();
EXPECT_ARITY(1, kExprI32LoadMem8S);
EXPECT_ARITY(1, kExprI32LoadMem8U);
EXPECT_ARITY(1, kExprI32LoadMem16S);
@@ -2338,16 +2069,14 @@
TEST_F(WasmOpcodeArityTest, MiscMemExpressions) {
- FunctionEnv env;
-
+ FunctionSig* sig = sigs.v_v();
EXPECT_ARITY(0, kExprMemorySize);
EXPECT_ARITY(1, kExprGrowMemory);
}
TEST_F(WasmOpcodeArityTest, SimpleExpressions) {
- FunctionEnv env;
-
+ FunctionSig* sig = sigs.v_v();
EXPECT_ARITY(2, kExprI32Add);
EXPECT_ARITY(2, kExprI32Sub);
EXPECT_ARITY(2, kExprI32Mul);
@@ -2374,7 +2103,7 @@
EXPECT_ARITY(1, kExprI32Clz);
EXPECT_ARITY(1, kExprI32Ctz);
EXPECT_ARITY(1, kExprI32Popcnt);
- EXPECT_ARITY(1, kExprBoolNot);
+ EXPECT_ARITY(1, kExprI32Eqz);
EXPECT_ARITY(2, kExprI64Add);
EXPECT_ARITY(2, kExprI64Sub);
EXPECT_ARITY(2, kExprI64Mul);
@@ -2467,6 +2196,127 @@
EXPECT_ARITY(1, kExprI32ReinterpretF32);
EXPECT_ARITY(1, kExprI64ReinterpretF64);
}
+
+typedef ZoneVector<LocalType> LocalTypeMap;
+
+class LocalDeclDecoderTest : public TestWithZone {
+ public:
+ base::AccountingAllocator allocator;
+
+ size_t ExpectRun(LocalTypeMap map, size_t pos, LocalType expected,
+ size_t count) {
+ for (size_t i = 0; i < count; i++) {
+ EXPECT_EQ(expected, map[pos++]);
+ }
+ return pos;
+ }
+
+ LocalTypeMap Expand(AstLocalDecls& decls) {
+ ZoneVector<LocalType> map(zone());
+ for (auto p : decls.local_types) {
+ map.insert(map.end(), p.second, p.first);
+ }
+ return map;
+ }
+};
+
+TEST_F(LocalDeclDecoderTest, EmptyLocals) {
+ AstLocalDecls decls(zone());
+ bool result = DecodeLocalDecls(decls, nullptr, nullptr);
+ EXPECT_FALSE(result);
+}
+
+TEST_F(LocalDeclDecoderTest, NoLocals) {
+ static const byte data[] = {0};
+ AstLocalDecls decls(zone());
+ bool result = DecodeLocalDecls(decls, data, data + sizeof(data));
+ EXPECT_TRUE(result);
+ EXPECT_EQ(0, decls.total_local_count);
+}
+
+TEST_F(LocalDeclDecoderTest, OneLocal) {
+ for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
+ LocalType type = kLocalTypes[i];
+ const byte data[] = {
+ 1, 1, static_cast<byte>(WasmOpcodes::LocalTypeCodeFor(type))};
+ AstLocalDecls decls(zone());
+ bool result = DecodeLocalDecls(decls, data, data + sizeof(data));
+ EXPECT_TRUE(result);
+ EXPECT_EQ(1, decls.total_local_count);
+
+ LocalTypeMap map = Expand(decls);
+ EXPECT_EQ(1, map.size());
+ EXPECT_EQ(type, map.at(0));
+ }
+}
+
+TEST_F(LocalDeclDecoderTest, FiveLocals) {
+ for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
+ LocalType type = kLocalTypes[i];
+ const byte data[] = {
+ 1, 5, static_cast<byte>(WasmOpcodes::LocalTypeCodeFor(type))};
+ AstLocalDecls decls(zone());
+ bool result = DecodeLocalDecls(decls, data, data + sizeof(data));
+ EXPECT_TRUE(result);
+ EXPECT_EQ(sizeof(data), decls.decls_encoded_size);
+ EXPECT_EQ(5, decls.total_local_count);
+
+ LocalTypeMap map = Expand(decls);
+ EXPECT_EQ(5, map.size());
+ ExpectRun(map, 0, type, 5);
+ }
+}
+
+TEST_F(LocalDeclDecoderTest, MixedLocals) {
+ for (byte a = 0; a < 3; a++) {
+ for (byte b = 0; b < 3; b++) {
+ for (byte c = 0; c < 3; c++) {
+ for (byte d = 0; d < 3; d++) {
+ const byte data[] = {4, a, kLocalI32, b, kLocalI64,
+ c, kLocalF32, d, kLocalF64};
+ AstLocalDecls decls(zone());
+ bool result = DecodeLocalDecls(decls, data, data + sizeof(data));
+ EXPECT_TRUE(result);
+ EXPECT_EQ(sizeof(data), decls.decls_encoded_size);
+ EXPECT_EQ(a + b + c + d, decls.total_local_count);
+
+ LocalTypeMap map = Expand(decls);
+ EXPECT_EQ(a + b + c + d, map.size());
+
+ size_t pos = 0;
+ pos = ExpectRun(map, pos, kAstI32, a);
+ pos = ExpectRun(map, pos, kAstI64, b);
+ pos = ExpectRun(map, pos, kAstF32, c);
+ pos = ExpectRun(map, pos, kAstF64, d);
+ }
+ }
+ }
+ }
+}
+
+TEST_F(LocalDeclDecoderTest, UseEncoder) {
+ const byte* data = nullptr;
+ const byte* end = nullptr;
+ LocalDeclEncoder local_decls;
+
+ local_decls.AddLocals(5, kAstF32);
+ local_decls.AddLocals(1337, kAstI32);
+ local_decls.AddLocals(212, kAstI64);
+ local_decls.Prepend(&data, &end);
+
+ AstLocalDecls decls(zone());
+ bool result = DecodeLocalDecls(decls, data, end);
+ EXPECT_TRUE(result);
+ EXPECT_EQ(5 + 1337 + 212, decls.total_local_count);
+
+ LocalTypeMap map = Expand(decls);
+ size_t pos = 0;
+ pos = ExpectRun(map, pos, kAstF32, 5);
+ pos = ExpectRun(map, pos, kAstI32, 1337);
+ pos = ExpectRun(map, pos, kAstI64, 212);
+ delete[] data;
+}
+
} // namespace wasm
} // namespace internal
} // namespace v8
diff --git a/test/unittests/wasm/decoder-unittest.cc b/test/unittests/wasm/decoder-unittest.cc
new file mode 100644
index 0000000..11d68f1
--- /dev/null
+++ b/test/unittests/wasm/decoder-unittest.cc
@@ -0,0 +1,667 @@
+// Copyright 2016 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "test/unittests/test-utils.h"
+
+#include "src/wasm/decoder.h"
+#include "src/wasm/wasm-macro-gen.h"
+
+namespace v8 {
+namespace internal {
+namespace wasm {
+
+class DecoderTest : public TestWithZone {
+ public:
+ DecoderTest() : decoder(nullptr, nullptr) {}
+
+ Decoder decoder;
+};
+
+#define CHECK_UINT32V_INLINE(expected, expected_length, ...) \
+ do { \
+ const byte data[] = {__VA_ARGS__}; \
+ decoder.Reset(data, data + sizeof(data)); \
+ int length; \
+ EXPECT_EQ(expected, \
+ decoder.checked_read_u32v(decoder.start(), 0, &length)); \
+ EXPECT_EQ(expected_length, length); \
+ } while (false)
+
+#define CHECK_INT32V_INLINE(expected, expected_length, ...) \
+ do { \
+ const byte data[] = {__VA_ARGS__}; \
+ decoder.Reset(data, data + sizeof(data)); \
+ int length; \
+ EXPECT_EQ(expected, \
+ decoder.checked_read_i32v(decoder.start(), 0, &length)); \
+ EXPECT_EQ(expected_length, length); \
+ } while (false)
+
+#define CHECK_UINT64V_INLINE(expected, expected_length, ...) \
+ do { \
+ const byte data[] = {__VA_ARGS__}; \
+ decoder.Reset(data, data + sizeof(data)); \
+ int length; \
+ EXPECT_EQ(expected, \
+ decoder.checked_read_u64v(decoder.start(), 0, &length)); \
+ EXPECT_EQ(expected_length, length); \
+ } while (false)
+
+#define CHECK_INT64V_INLINE(expected, expected_length, ...) \
+ do { \
+ const byte data[] = {__VA_ARGS__}; \
+ decoder.Reset(data, data + sizeof(data)); \
+ int length; \
+ EXPECT_EQ(expected, \
+ decoder.checked_read_i64v(decoder.start(), 0, &length)); \
+ EXPECT_EQ(expected_length, length); \
+ } while (false)
+
+TEST_F(DecoderTest, ReadU32v_OneByte) {
+ CHECK_UINT32V_INLINE(0, 1, 0);
+ CHECK_UINT32V_INLINE(5, 1, 5);
+ CHECK_UINT32V_INLINE(7, 1, 7);
+ CHECK_UINT32V_INLINE(9, 1, 9);
+ CHECK_UINT32V_INLINE(37, 1, 37);
+ CHECK_UINT32V_INLINE(69, 1, 69);
+ CHECK_UINT32V_INLINE(110, 1, 110);
+ CHECK_UINT32V_INLINE(125, 1, 125);
+ CHECK_UINT32V_INLINE(126, 1, 126);
+ CHECK_UINT32V_INLINE(127, 1, 127);
+}
+
+TEST_F(DecoderTest, ReadU32v_TwoByte) {
+ CHECK_UINT32V_INLINE(0, 1, 0, 0);
+ CHECK_UINT32V_INLINE(10, 1, 10, 0);
+ CHECK_UINT32V_INLINE(27, 1, 27, 0);
+ CHECK_UINT32V_INLINE(100, 1, 100, 0);
+
+ CHECK_UINT32V_INLINE(444, 2, U32V_2(444));
+ CHECK_UINT32V_INLINE(544, 2, U32V_2(544));
+ CHECK_UINT32V_INLINE(1311, 2, U32V_2(1311));
+ CHECK_UINT32V_INLINE(2333, 2, U32V_2(2333));
+
+ for (uint32_t i = 0; i < 1 << 14; i = i * 13 + 1) {
+ CHECK_UINT32V_INLINE(i, 2, U32V_2(i));
+ }
+
+ const uint32_t max = (1 << 14) - 1;
+ CHECK_UINT32V_INLINE(max, 2, U32V_2(max));
+}
+
+TEST_F(DecoderTest, ReadU32v_ThreeByte) {
+ CHECK_UINT32V_INLINE(0, 1, 0, 0, 0, 0);
+ CHECK_UINT32V_INLINE(10, 1, 10, 0, 0, 0);
+ CHECK_UINT32V_INLINE(27, 1, 27, 0, 0, 0);
+ CHECK_UINT32V_INLINE(100, 1, 100, 0, 0, 0);
+
+ CHECK_UINT32V_INLINE(11, 3, U32V_3(11));
+ CHECK_UINT32V_INLINE(101, 3, U32V_3(101));
+ CHECK_UINT32V_INLINE(446, 3, U32V_3(446));
+ CHECK_UINT32V_INLINE(546, 3, U32V_3(546));
+ CHECK_UINT32V_INLINE(1319, 3, U32V_3(1319));
+ CHECK_UINT32V_INLINE(2338, 3, U32V_3(2338));
+ CHECK_UINT32V_INLINE(8191, 3, U32V_3(8191));
+ CHECK_UINT32V_INLINE(9999, 3, U32V_3(9999));
+ CHECK_UINT32V_INLINE(14444, 3, U32V_3(14444));
+ CHECK_UINT32V_INLINE(314444, 3, U32V_3(314444));
+ CHECK_UINT32V_INLINE(614444, 3, U32V_3(614444));
+
+ const uint32_t max = (1 << 21) - 1;
+
+ for (uint32_t i = 0; i <= max; i = i * 13 + 3) {
+ CHECK_UINT32V_INLINE(i, 3, U32V_3(i), 0);
+ }
+
+ CHECK_UINT32V_INLINE(max, 3, U32V_3(max));
+}
+
+TEST_F(DecoderTest, ReadU32v_FourByte) {
+ CHECK_UINT32V_INLINE(0, 1, 0, 0, 0, 0, 0);
+ CHECK_UINT32V_INLINE(10, 1, 10, 0, 0, 0, 0);
+ CHECK_UINT32V_INLINE(27, 1, 27, 0, 0, 0, 0);
+ CHECK_UINT32V_INLINE(100, 1, 100, 0, 0, 0, 0);
+
+ CHECK_UINT32V_INLINE(13, 4, U32V_4(13));
+ CHECK_UINT32V_INLINE(107, 4, U32V_4(107));
+ CHECK_UINT32V_INLINE(449, 4, U32V_4(449));
+ CHECK_UINT32V_INLINE(541, 4, U32V_4(541));
+ CHECK_UINT32V_INLINE(1317, 4, U32V_4(1317));
+ CHECK_UINT32V_INLINE(2334, 4, U32V_4(2334));
+ CHECK_UINT32V_INLINE(8191, 4, U32V_4(8191));
+ CHECK_UINT32V_INLINE(9994, 4, U32V_4(9994));
+ CHECK_UINT32V_INLINE(14442, 4, U32V_4(14442));
+ CHECK_UINT32V_INLINE(314442, 4, U32V_4(314442));
+ CHECK_UINT32V_INLINE(614442, 4, U32V_4(614442));
+ CHECK_UINT32V_INLINE(1614442, 4, U32V_4(1614442));
+ CHECK_UINT32V_INLINE(5614442, 4, U32V_4(5614442));
+ CHECK_UINT32V_INLINE(19614442, 4, U32V_4(19614442));
+
+ const uint32_t max = (1 << 28) - 1;
+
+ for (uint32_t i = 0; i <= max; i = i * 13 + 5) {
+ CHECK_UINT32V_INLINE(i, 4, U32V_4(i), 0);
+ }
+
+ CHECK_UINT32V_INLINE(max, 4, U32V_4(max));
+}
+
+TEST_F(DecoderTest, ReadU32v_FiveByte) {
+ CHECK_UINT32V_INLINE(0, 1, 0, 0, 0, 0, 0);
+ CHECK_UINT32V_INLINE(10, 1, 10, 0, 0, 0, 0);
+ CHECK_UINT32V_INLINE(27, 1, 27, 0, 0, 0, 0);
+ CHECK_UINT32V_INLINE(100, 1, 100, 0, 0, 0, 0);
+
+ CHECK_UINT32V_INLINE(13, 5, U32V_5(13));
+ CHECK_UINT32V_INLINE(107, 5, U32V_5(107));
+ CHECK_UINT32V_INLINE(449, 5, U32V_5(449));
+ CHECK_UINT32V_INLINE(541, 5, U32V_5(541));
+ CHECK_UINT32V_INLINE(1317, 5, U32V_5(1317));
+ CHECK_UINT32V_INLINE(2334, 5, U32V_5(2334));
+ CHECK_UINT32V_INLINE(8191, 5, U32V_5(8191));
+ CHECK_UINT32V_INLINE(9994, 5, U32V_5(9994));
+ CHECK_UINT32V_INLINE(24442, 5, U32V_5(24442));
+ CHECK_UINT32V_INLINE(414442, 5, U32V_5(414442));
+ CHECK_UINT32V_INLINE(714442, 5, U32V_5(714442));
+ CHECK_UINT32V_INLINE(1614442, 5, U32V_5(1614442));
+ CHECK_UINT32V_INLINE(6614442, 5, U32V_5(6614442));
+ CHECK_UINT32V_INLINE(89614442, 5, U32V_5(89614442));
+ CHECK_UINT32V_INLINE(2219614442u, 5, U32V_5(2219614442u));
+ CHECK_UINT32V_INLINE(3219614442u, 5, U32V_5(3219614442u));
+ CHECK_UINT32V_INLINE(4019614442u, 5, U32V_5(4019614442u));
+
+ const uint32_t max = 0xFFFFFFFFu;
+
+ for (uint32_t i = 1; i < 32; i++) {
+ uint32_t val = 0x983489aau << i;
+ CHECK_UINT32V_INLINE(val, 5, U32V_5(val), 0);
+ }
+
+ CHECK_UINT32V_INLINE(max, 5, U32V_5(max));
+}
+
+TEST_F(DecoderTest, ReadU32v_various) {
+ for (int i = 0; i < 10; i++) {
+ uint32_t x = 0xCCCCCCCCu * i;
+ for (int width = 0; width < 32; width++) {
+ uint32_t val = x >> width;
+
+ CHECK_UINT32V_INLINE(val & MASK_7, 1, U32V_1(val));
+ CHECK_UINT32V_INLINE(val & MASK_14, 2, U32V_2(val));
+ CHECK_UINT32V_INLINE(val & MASK_21, 3, U32V_3(val));
+ CHECK_UINT32V_INLINE(val & MASK_28, 4, U32V_4(val));
+ CHECK_UINT32V_INLINE(val, 5, U32V_5(val));
+ }
+ }
+}
+
+TEST_F(DecoderTest, ReadI32v_OneByte) {
+ CHECK_INT32V_INLINE(0, 1, 0);
+ CHECK_INT32V_INLINE(4, 1, 4);
+ CHECK_INT32V_INLINE(6, 1, 6);
+ CHECK_INT32V_INLINE(9, 1, 9);
+ CHECK_INT32V_INLINE(33, 1, 33);
+ CHECK_INT32V_INLINE(61, 1, 61);
+ CHECK_INT32V_INLINE(63, 1, 63);
+
+ CHECK_INT32V_INLINE(-1, 1, 127);
+ CHECK_INT32V_INLINE(-2, 1, 126);
+ CHECK_INT32V_INLINE(-11, 1, 117);
+ CHECK_INT32V_INLINE(-62, 1, 66);
+ CHECK_INT32V_INLINE(-63, 1, 65);
+ CHECK_INT32V_INLINE(-64, 1, 64);
+}
+
+TEST_F(DecoderTest, ReadI32v_TwoByte) {
+ CHECK_INT32V_INLINE(0, 2, U32V_2(0));
+ CHECK_INT32V_INLINE(9, 2, U32V_2(9));
+ CHECK_INT32V_INLINE(61, 2, U32V_2(61));
+ CHECK_INT32V_INLINE(63, 2, U32V_2(63));
+
+ CHECK_INT32V_INLINE(-1, 2, U32V_2(-1));
+ CHECK_INT32V_INLINE(-2, 2, U32V_2(-2));
+ CHECK_INT32V_INLINE(-63, 2, U32V_2(-63));
+ CHECK_INT32V_INLINE(-64, 2, U32V_2(-64));
+
+ CHECK_INT32V_INLINE(-200, 2, U32V_2(-200));
+ CHECK_INT32V_INLINE(-1002, 2, U32V_2(-1002));
+ CHECK_INT32V_INLINE(-2004, 2, U32V_2(-2004));
+ CHECK_INT32V_INLINE(-4077, 2, U32V_2(-4077));
+
+ CHECK_INT32V_INLINE(207, 2, U32V_2(207));
+ CHECK_INT32V_INLINE(1009, 2, U32V_2(1009));
+ CHECK_INT32V_INLINE(2003, 2, U32V_2(2003));
+ CHECK_INT32V_INLINE(4072, 2, U32V_2(4072));
+
+ const int32_t min = 0 - (1 << 13);
+ for (int i = min; i < min + 10; i++) {
+ CHECK_INT32V_INLINE(i, 2, U32V_2(i));
+ }
+
+ const int32_t max = (1 << 13) - 1;
+ for (int i = max; i > max - 10; i--) {
+ CHECK_INT32V_INLINE(i, 2, U32V_2(i));
+ }
+}
+
+TEST_F(DecoderTest, ReadI32v_ThreeByte) {
+ CHECK_INT32V_INLINE(0, 3, U32V_3(0));
+ CHECK_INT32V_INLINE(9, 3, U32V_3(9));
+ CHECK_INT32V_INLINE(61, 3, U32V_3(61));
+ CHECK_INT32V_INLINE(63, 3, U32V_3(63));
+
+ CHECK_INT32V_INLINE(-1, 3, U32V_3(-1));
+ CHECK_INT32V_INLINE(-2, 3, U32V_3(-2));
+ CHECK_INT32V_INLINE(-63, 3, U32V_3(-63));
+ CHECK_INT32V_INLINE(-64, 3, U32V_3(-64));
+
+ CHECK_INT32V_INLINE(-207, 3, U32V_3(-207));
+ CHECK_INT32V_INLINE(-1012, 3, U32V_3(-1012));
+ CHECK_INT32V_INLINE(-4067, 3, U32V_3(-4067));
+ CHECK_INT32V_INLINE(-14067, 3, U32V_3(-14067));
+ CHECK_INT32V_INLINE(-234061, 3, U32V_3(-234061));
+
+ CHECK_INT32V_INLINE(237, 3, U32V_3(237));
+ CHECK_INT32V_INLINE(1309, 3, U32V_3(1309));
+ CHECK_INT32V_INLINE(4372, 3, U32V_3(4372));
+ CHECK_INT32V_INLINE(64372, 3, U32V_3(64372));
+ CHECK_INT32V_INLINE(374372, 3, U32V_3(374372));
+
+ const int32_t min = 0 - (1 << 20);
+ for (int i = min; i < min + 10; i++) {
+ CHECK_INT32V_INLINE(i, 3, U32V_3(i));
+ }
+
+ const int32_t max = (1 << 20) - 1;
+ for (int i = max; i > max - 10; i--) {
+ CHECK_INT32V_INLINE(i, 3, U32V_3(i));
+ }
+}
+
+TEST_F(DecoderTest, ReadI32v_FourByte) {
+ CHECK_INT32V_INLINE(0, 4, U32V_4(0));
+ CHECK_INT32V_INLINE(9, 4, U32V_4(9));
+ CHECK_INT32V_INLINE(61, 4, U32V_4(61));
+ CHECK_INT32V_INLINE(63, 4, U32V_4(63));
+
+ CHECK_INT32V_INLINE(-1, 4, U32V_4(-1));
+ CHECK_INT32V_INLINE(-2, 4, U32V_4(-2));
+ CHECK_INT32V_INLINE(-63, 4, U32V_4(-63));
+ CHECK_INT32V_INLINE(-64, 4, U32V_4(-64));
+
+ CHECK_INT32V_INLINE(-267, 4, U32V_4(-267));
+ CHECK_INT32V_INLINE(-1612, 4, U32V_4(-1612));
+ CHECK_INT32V_INLINE(-4667, 4, U32V_4(-4667));
+ CHECK_INT32V_INLINE(-16067, 4, U32V_4(-16067));
+ CHECK_INT32V_INLINE(-264061, 4, U32V_4(-264061));
+ CHECK_INT32V_INLINE(-1264061, 4, U32V_4(-1264061));
+ CHECK_INT32V_INLINE(-6264061, 4, U32V_4(-6264061));
+ CHECK_INT32V_INLINE(-8264061, 4, U32V_4(-8264061));
+
+ CHECK_INT32V_INLINE(277, 4, U32V_4(277));
+ CHECK_INT32V_INLINE(1709, 4, U32V_4(1709));
+ CHECK_INT32V_INLINE(4772, 4, U32V_4(4772));
+ CHECK_INT32V_INLINE(67372, 4, U32V_4(67372));
+ CHECK_INT32V_INLINE(374372, 4, U32V_4(374372));
+ CHECK_INT32V_INLINE(2374372, 4, U32V_4(2374372));
+ CHECK_INT32V_INLINE(7374372, 4, U32V_4(7374372));
+ CHECK_INT32V_INLINE(9374372, 4, U32V_4(9374372));
+
+ const int32_t min = 0 - (1 << 27);
+ for (int i = min; i < min + 10; i++) {
+ CHECK_INT32V_INLINE(i, 4, U32V_4(i));
+ }
+
+ const int32_t max = (1 << 27) - 1;
+ for (int i = max; i > max - 10; i--) {
+ CHECK_INT32V_INLINE(i, 4, U32V_4(i));
+ }
+}
+
+TEST_F(DecoderTest, ReadI32v_FiveByte) {
+ CHECK_INT32V_INLINE(0, 5, U32V_5(0));
+ CHECK_INT32V_INLINE(16, 5, U32V_5(16));
+ CHECK_INT32V_INLINE(94, 5, U32V_5(94));
+ CHECK_INT32V_INLINE(127, 5, U32V_5(127));
+
+ CHECK_INT32V_INLINE(-1, 5, U32V_5(-1));
+ CHECK_INT32V_INLINE(-2, 5, U32V_5(-2));
+ CHECK_INT32V_INLINE(-63, 5, U32V_5(-63));
+ CHECK_INT32V_INLINE(-64, 5, U32V_5(-64));
+
+ CHECK_INT32V_INLINE(-257, 5, U32V_5(-257));
+ CHECK_INT32V_INLINE(-1512, 5, U32V_5(-1512));
+ CHECK_INT32V_INLINE(-4567, 5, U32V_5(-4567));
+ CHECK_INT32V_INLINE(-15067, 5, U32V_5(-15067));
+ CHECK_INT32V_INLINE(-254061, 5, U32V_5(-254061));
+ CHECK_INT32V_INLINE(-1364061, 5, U32V_5(-1364061));
+ CHECK_INT32V_INLINE(-6364061, 5, U32V_5(-6364061));
+ CHECK_INT32V_INLINE(-8364061, 5, U32V_5(-8364061));
+ CHECK_INT32V_INLINE(-28364061, 5, U32V_5(-28364061));
+ CHECK_INT32V_INLINE(-228364061, 5, U32V_5(-228364061));
+
+ CHECK_INT32V_INLINE(227, 5, U32V_5(227));
+ CHECK_INT32V_INLINE(1209, 5, U32V_5(1209));
+ CHECK_INT32V_INLINE(4272, 5, U32V_5(4272));
+ CHECK_INT32V_INLINE(62372, 5, U32V_5(62372));
+ CHECK_INT32V_INLINE(324372, 5, U32V_5(324372));
+ CHECK_INT32V_INLINE(2274372, 5, U32V_5(2274372));
+ CHECK_INT32V_INLINE(7274372, 5, U32V_5(7274372));
+ CHECK_INT32V_INLINE(9274372, 5, U32V_5(9274372));
+ CHECK_INT32V_INLINE(42374372, 5, U32V_5(42374372));
+ CHECK_INT32V_INLINE(429374372, 5, U32V_5(429374372));
+
+ const int32_t min = kMinInt;
+ for (int i = min; i < min + 10; i++) {
+ CHECK_INT32V_INLINE(i, 5, U32V_5(i));
+ }
+
+ const int32_t max = kMaxInt;
+ for (int i = max; i > max - 10; i--) {
+ CHECK_INT32V_INLINE(i, 5, U32V_5(i));
+ }
+}
+
+TEST_F(DecoderTest, ReadU32v_off_end1) {
+ static const byte data[] = {U32V_1(11)};
+ int length = 0;
+ decoder.Reset(data, data);
+ decoder.checked_read_u32v(decoder.start(), 0, &length);
+ EXPECT_EQ(0, length);
+ EXPECT_FALSE(decoder.ok());
+}
+
+TEST_F(DecoderTest, ReadU32v_off_end2) {
+ static const byte data[] = {U32V_2(1111)};
+ for (size_t i = 0; i < sizeof(data); i++) {
+ int length = 0;
+ decoder.Reset(data, data + i);
+ decoder.checked_read_u32v(decoder.start(), 0, &length);
+ EXPECT_EQ(i, length);
+ EXPECT_FALSE(decoder.ok());
+ }
+}
+
+TEST_F(DecoderTest, ReadU32v_off_end3) {
+ static const byte data[] = {U32V_3(111111)};
+ for (size_t i = 0; i < sizeof(data); i++) {
+ int length = 0;
+ decoder.Reset(data, data + i);
+ decoder.checked_read_u32v(decoder.start(), 0, &length);
+ EXPECT_EQ(i, length);
+ EXPECT_FALSE(decoder.ok());
+ }
+}
+
+TEST_F(DecoderTest, ReadU32v_off_end4) {
+ static const byte data[] = {U32V_4(11111111)};
+ for (size_t i = 0; i < sizeof(data); i++) {
+ int length = 0;
+ decoder.Reset(data, data + i);
+ decoder.checked_read_u32v(decoder.start(), 0, &length);
+ EXPECT_EQ(i, length);
+ EXPECT_FALSE(decoder.ok());
+ }
+}
+
+TEST_F(DecoderTest, ReadU32v_off_end5) {
+ static const byte data[] = {U32V_5(111111111)};
+ for (size_t i = 0; i < sizeof(data); i++) {
+ int length = 0;
+ decoder.Reset(data, data + i);
+ decoder.checked_read_u32v(decoder.start(), 0, &length);
+ EXPECT_EQ(i, length);
+ EXPECT_FALSE(decoder.ok());
+ }
+}
+
+TEST_F(DecoderTest, ReadU32v_extra_bits) {
+ byte data[] = {0x80, 0x80, 0x80, 0x80, 0x00};
+ for (int i = 1; i < 16; i++) {
+ data[4] = static_cast<byte>(i << 4);
+ int length = 0;
+ decoder.Reset(data, data + sizeof(data));
+ decoder.checked_read_u32v(decoder.start(), 0, &length);
+ EXPECT_EQ(5, length);
+ EXPECT_FALSE(decoder.ok());
+ }
+}
+
+TEST_F(DecoderTest, ReadI32v_extra_bits_negative) {
+ // OK for negative signed values to have extra ones.
+ int length = 0;
+ byte data[] = {0xff, 0xff, 0xff, 0xff, 0x7f};
+ decoder.Reset(data, data + sizeof(data));
+ decoder.checked_read_i32v(decoder.start(), 0, &length);
+ EXPECT_EQ(5, length);
+ EXPECT_TRUE(decoder.ok());
+}
+
+TEST_F(DecoderTest, ReadI32v_extra_bits_positive) {
+ // Not OK for positive signed values to have extra ones.
+ int length = 0;
+ byte data[] = {0x80, 0x80, 0x80, 0x80, 0x77};
+ decoder.Reset(data, data + sizeof(data));
+ decoder.checked_read_i32v(decoder.start(), 0, &length);
+ EXPECT_EQ(5, length);
+ EXPECT_FALSE(decoder.ok());
+}
+
+TEST_F(DecoderTest, ReadU32v_Bits) {
+ // A more exhaustive test.
+ const int kMaxSize = 5;
+ const uint32_t kVals[] = {
+ 0xaabbccdd, 0x11223344, 0x33445566, 0xffeeddcc, 0xF0F0F0F0, 0x0F0F0F0F,
+ 0xEEEEEEEE, 0xAAAAAAAA, 0x12345678, 0x9abcdef0, 0x80309488, 0x729ed997,
+ 0xc4a0cf81, 0x16c6eb85, 0x4206db8e, 0xf3b089d5, 0xaa2e223e, 0xf99e29c8,
+ 0x4a4357d8, 0x1890b1c1, 0x8d80a085, 0xacb6ae4c, 0x1b827e10, 0xeb5c7bd9,
+ 0xbb1bc146, 0xdf57a33l};
+ byte data[kMaxSize];
+
+ // foreach value in above array
+ for (size_t v = 0; v < arraysize(kVals); v++) {
+ // foreach length 1...32
+ for (int i = 1; i <= 32; i++) {
+ uint32_t val = kVals[v];
+ if (i < 32) val &= ((1 << i) - 1);
+
+ int length = 1 + i / 7;
+ for (int j = 0; j < kMaxSize; j++) {
+ data[j] = static_cast<byte>((val >> (7 * j)) & MASK_7);
+ }
+ for (int j = 0; j < length - 1; j++) {
+ data[j] |= 0x80;
+ }
+
+ // foreach buffer size 0...5
+ for (int limit = 0; limit <= kMaxSize; limit++) {
+ decoder.Reset(data, data + limit);
+ int rlen;
+ uint32_t result = decoder.checked_read_u32v(data, 0, &rlen);
+ if (limit < length) {
+ EXPECT_FALSE(decoder.ok());
+ } else {
+ EXPECT_TRUE(decoder.ok());
+ EXPECT_EQ(val, result);
+ EXPECT_EQ(length, rlen);
+ }
+ }
+ }
+ }
+}
+
+TEST_F(DecoderTest, ReadU64v_OneByte) {
+ CHECK_UINT64V_INLINE(0, 1, 0);
+ CHECK_UINT64V_INLINE(6, 1, 6);
+ CHECK_UINT64V_INLINE(8, 1, 8);
+ CHECK_UINT64V_INLINE(12, 1, 12);
+ CHECK_UINT64V_INLINE(33, 1, 33);
+ CHECK_UINT64V_INLINE(59, 1, 59);
+ CHECK_UINT64V_INLINE(110, 1, 110);
+ CHECK_UINT64V_INLINE(125, 1, 125);
+ CHECK_UINT64V_INLINE(126, 1, 126);
+ CHECK_UINT64V_INLINE(127, 1, 127);
+}
+
+TEST_F(DecoderTest, ReadI64v_OneByte) {
+ CHECK_INT64V_INLINE(0, 1, 0);
+ CHECK_INT64V_INLINE(4, 1, 4);
+ CHECK_INT64V_INLINE(6, 1, 6);
+ CHECK_INT64V_INLINE(9, 1, 9);
+ CHECK_INT64V_INLINE(33, 1, 33);
+ CHECK_INT64V_INLINE(61, 1, 61);
+ CHECK_INT64V_INLINE(63, 1, 63);
+
+ CHECK_INT64V_INLINE(-1, 1, 127);
+ CHECK_INT64V_INLINE(-2, 1, 126);
+ CHECK_INT64V_INLINE(-11, 1, 117);
+ CHECK_INT64V_INLINE(-62, 1, 66);
+ CHECK_INT64V_INLINE(-63, 1, 65);
+ CHECK_INT64V_INLINE(-64, 1, 64);
+}
+
+TEST_F(DecoderTest, ReadU64v_PowerOf2) {
+ const int kMaxSize = 10;
+ byte data[kMaxSize];
+
+ for (int i = 0; i < 64; i++) {
+ const uint64_t val = 1ull << i;
+ int index = i / 7;
+ data[index] = 1 << (i % 7);
+ memset(data, 0x80, index);
+
+ for (int limit = 0; limit <= kMaxSize; limit++) {
+ decoder.Reset(data, data + limit);
+ int length;
+ uint64_t result = decoder.checked_read_u64v(data, 0, &length);
+ if (limit <= index) {
+ EXPECT_FALSE(decoder.ok());
+ } else {
+ EXPECT_TRUE(decoder.ok());
+ EXPECT_EQ(val, result);
+ EXPECT_EQ(index + 1, length);
+ }
+ }
+ }
+}
+
+TEST_F(DecoderTest, ReadU64v_Bits) {
+ const int kMaxSize = 10;
+ const uint64_t kVals[] = {
+ 0xaabbccdd11223344ull, 0x33445566ffeeddccull, 0xF0F0F0F0F0F0F0F0ull,
+ 0x0F0F0F0F0F0F0F0Full, 0xEEEEEEEEEEEEEEEEull, 0xAAAAAAAAAAAAAAAAull,
+ 0x123456789abcdef0ull, 0x80309488729ed997ull, 0xc4a0cf8116c6eb85ull,
+ 0x4206db8ef3b089d5ull, 0xaa2e223ef99e29c8ull, 0x4a4357d81890b1c1ull,
+ 0x8d80a085acb6ae4cull, 0x1b827e10eb5c7bd9ull, 0xbb1bc146df57a338ull};
+ byte data[kMaxSize];
+
+ // foreach value in above array
+ for (size_t v = 0; v < arraysize(kVals); v++) {
+ // foreach length 1...64
+ for (int i = 1; i <= 64; i++) {
+ uint64_t val = kVals[v];
+ if (i < 64) val &= ((1ull << i) - 1);
+
+ int length = 1 + i / 7;
+ for (int j = 0; j < kMaxSize; j++) {
+ data[j] = static_cast<byte>((val >> (7 * j)) & MASK_7);
+ }
+ for (int j = 0; j < length - 1; j++) {
+ data[j] |= 0x80;
+ }
+
+ // foreach buffer size 0...10
+ for (int limit = 0; limit <= kMaxSize; limit++) {
+ decoder.Reset(data, data + limit);
+ int rlen;
+ uint64_t result = decoder.checked_read_u64v(data, 0, &rlen);
+ if (limit < length) {
+ EXPECT_FALSE(decoder.ok());
+ } else {
+ EXPECT_TRUE(decoder.ok());
+ EXPECT_EQ(val, result);
+ EXPECT_EQ(length, rlen);
+ }
+ }
+ }
+ }
+}
+
+TEST_F(DecoderTest, ReadI64v_Bits) {
+ const int kMaxSize = 10;
+ // Exhaustive signedness test.
+ const uint64_t kVals[] = {
+ 0xaabbccdd11223344ull, 0x33445566ffeeddccull, 0xF0F0F0F0F0F0F0F0ull,
+ 0x0F0F0F0F0F0F0F0Full, 0xEEEEEEEEEEEEEEEEull, 0xAAAAAAAAAAAAAAAAull,
+ 0x123456789abcdef0ull, 0x80309488729ed997ull, 0xc4a0cf8116c6eb85ull,
+ 0x4206db8ef3b089d5ull, 0xaa2e223ef99e29c8ull, 0x4a4357d81890b1c1ull,
+ 0x8d80a085acb6ae4cull, 0x1b827e10eb5c7bd9ull, 0xbb1bc146df57a338ull};
+ byte data[kMaxSize];
+
+ // foreach value in above array
+ for (size_t v = 0; v < arraysize(kVals); v++) {
+ // foreach length 1...64
+ for (int i = 1; i <= 64; i++) {
+ const int64_t val = bit_cast<int64_t>(kVals[v] << (64 - i)) >> (64 - i);
+
+ int length = 1 + i / 7;
+ for (int j = 0; j < kMaxSize; j++) {
+ data[j] = static_cast<byte>((val >> (7 * j)) & MASK_7);
+ }
+ for (int j = 0; j < length - 1; j++) {
+ data[j] |= 0x80;
+ }
+
+ // foreach buffer size 0...10
+ for (int limit = 0; limit <= kMaxSize; limit++) {
+ decoder.Reset(data, data + limit);
+ int rlen;
+ int64_t result = decoder.checked_read_i64v(data, 0, &rlen);
+ if (limit < length) {
+ EXPECT_FALSE(decoder.ok());
+ } else {
+ EXPECT_TRUE(decoder.ok());
+ EXPECT_EQ(val, result);
+ EXPECT_EQ(length, rlen);
+ }
+ }
+ }
+ }
+}
+
+TEST_F(DecoderTest, ReadU64v_extra_bits) {
+ byte data[] = {0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00};
+ for (int i = 1; i < 128; i++) {
+ data[9] = static_cast<byte>(i << 1);
+ int length = 0;
+ decoder.Reset(data, data + sizeof(data));
+ decoder.checked_read_u64v(decoder.start(), 0, &length);
+ EXPECT_EQ(10, length);
+ EXPECT_FALSE(decoder.ok());
+ }
+}
+
+TEST_F(DecoderTest, ReadI64v_extra_bits_negative) {
+ // OK for negative signed values to have extra ones.
+ int length = 0;
+ byte data[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f};
+ decoder.Reset(data, data + sizeof(data));
+ decoder.checked_read_i64v(decoder.start(), 0, &length);
+ EXPECT_EQ(10, length);
+ EXPECT_TRUE(decoder.ok());
+}
+
+TEST_F(DecoderTest, ReadI64v_extra_bits_positive) {
+ // Not OK for positive signed values to have extra ones.
+ int length = 0;
+ byte data[] = {0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x77};
+ decoder.Reset(data, data + sizeof(data));
+ decoder.checked_read_i64v(decoder.start(), 0, &length);
+ EXPECT_EQ(10, length);
+ EXPECT_FALSE(decoder.ok());
+}
+
+} // namespace wasm
+} // namespace internal
+} // namespace v8
diff --git a/test/unittests/wasm/encoder-unittest.cc b/test/unittests/wasm/encoder-unittest.cc
index e09e71a..740c054 100644
--- a/test/unittests/wasm/encoder-unittest.cc
+++ b/test/unittests/wasm/encoder-unittest.cc
@@ -52,7 +52,8 @@
TEST_F(EncoderTest, Function_Builder_Variable_Indexing) {
- Zone zone;
+ base::AccountingAllocator allocator;
+ Zone zone(&allocator);
WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
uint16_t f_index = builder->AddFunction();
WasmFunctionBuilder* function = builder->FunctionAt(f_index);
@@ -86,14 +87,12 @@
byte* header = buffer;
byte* body = buffer + f->HeaderSize();
f->Serialize(buffer, &header, &body);
- for (size_t i = 0; i < 7; i++) {
- CHECK_EQ(i, static_cast<size_t>(*(buffer + 2 * i + f->HeaderSize() + 1)));
- }
}
TEST_F(EncoderTest, Function_Builder_Indexing_Variable_Width) {
- Zone zone;
+ base::AccountingAllocator allocator;
+ Zone zone(&allocator);
WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
uint16_t f_index = builder->AddFunction();
WasmFunctionBuilder* function = builder->FunctionAt(f_index);
@@ -109,17 +108,85 @@
byte* body = buffer + f->HeaderSize();
f->Serialize(buffer, &header, &body);
body = buffer + f->HeaderSize();
- for (size_t i = 0; i < 127; i++) {
- CHECK_EQ(kExprGetLocal, static_cast<size_t>(*(body + 2 * i)));
- CHECK_EQ(i + 1, static_cast<size_t>(*(body + 2 * i + 1)));
- }
- CHECK_EQ(kExprGetLocal, static_cast<size_t>(*(body + 2 * 127)));
- CHECK_EQ(0x80, static_cast<size_t>(*(body + 2 * 127 + 1)));
- CHECK_EQ(0x01, static_cast<size_t>(*(body + 2 * 127 + 2)));
- CHECK_EQ(kExprGetLocal, static_cast<size_t>(*(body + 2 * 127 + 3)));
- CHECK_EQ(0x00, static_cast<size_t>(*(body + 2 * 127 + 4)));
}
+TEST_F(EncoderTest, Function_Builder_Block_Variable_Width) {
+ base::AccountingAllocator allocator;
+ Zone zone(&allocator);
+ WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
+ uint16_t f_index = builder->AddFunction();
+ WasmFunctionBuilder* function = builder->FunctionAt(f_index);
+ function->EmitWithVarInt(kExprBlock, 200);
+ for (int i = 0; i < 200; ++i) {
+ function->Emit(kExprNop);
+ }
+
+ WasmFunctionEncoder* f = function->Build(&zone, builder);
+ CHECK_EQ(f->BodySize(), 204);
+}
+
+TEST_F(EncoderTest, Function_Builder_EmitEditableVarIntImmediate) {
+ base::AccountingAllocator allocator;
+ Zone zone(&allocator);
+ WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
+ uint16_t f_index = builder->AddFunction();
+ WasmFunctionBuilder* function = builder->FunctionAt(f_index);
+ function->Emit(kExprLoop);
+ uint32_t offset = function->EmitEditableVarIntImmediate();
+ for (int i = 0; i < 200; ++i) {
+ function->Emit(kExprNop);
+ }
+ function->EditVarIntImmediate(offset, 200);
+
+ WasmFunctionEncoder* f = function->Build(&zone, builder);
+ CHECK_EQ(f->BodySize(), 204);
+}
+
+TEST_F(EncoderTest, Function_Builder_EmitEditableVarIntImmediate_Locals) {
+ base::AccountingAllocator allocator;
+ Zone zone(&allocator);
+ WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
+ uint16_t f_index = builder->AddFunction();
+ WasmFunctionBuilder* function = builder->FunctionAt(f_index);
+ function->Emit(kExprBlock);
+ uint32_t offset = function->EmitEditableVarIntImmediate();
+ for (int i = 0; i < 200; ++i) {
+ AddLocal(function, kAstI32);
+ }
+ function->EditVarIntImmediate(offset, 200);
+
+ WasmFunctionEncoder* f = function->Build(&zone, builder);
+ ZoneVector<uint8_t> buffer_vector(f->HeaderSize() + f->BodySize(), &zone);
+ byte* buffer = &buffer_vector[0];
+ byte* header = buffer;
+ byte* body = buffer + f->HeaderSize();
+ f->Serialize(buffer, &header, &body);
+ body = buffer + f->HeaderSize();
+
+ CHECK_EQ(f->BodySize(), 479);
+ const uint8_t varint200_low = (200 & 0x7f) | 0x80;
+ const uint8_t varint200_high = (200 >> 7) & 0x7f;
+ offset = 0;
+ CHECK_EQ(body[offset++], 1); // Local decl count.
+ CHECK_EQ(body[offset++], varint200_low);
+ CHECK_EQ(body[offset++], varint200_high);
+ CHECK_EQ(body[offset++], kLocalI32);
+ CHECK_EQ(body[offset++], kExprBlock);
+ CHECK_EQ(body[offset++], varint200_low);
+ CHECK_EQ(body[offset++], varint200_high);
+ // GetLocal with one-byte indices.
+ for (int i = 0; i <= 127; ++i) {
+ CHECK_EQ(body[offset++], kExprGetLocal);
+ CHECK_EQ(body[offset++], i);
+ }
+ // GetLocal with two-byte indices.
+ for (int i = 128; i < 200; ++i) {
+ CHECK_EQ(body[offset++], kExprGetLocal);
+ CHECK_EQ(body[offset++], (i & 0x7f) | 0x80);
+ CHECK_EQ(body[offset++], (i >> 7) & 0x7f);
+ }
+ CHECK_EQ(offset, 479);
+}
TEST_F(EncoderTest, LEB_Functions) {
byte leb_value[5] = {0, 0, 0, 0, 0};
diff --git a/test/unittests/wasm/loop-assignment-analysis-unittest.cc b/test/unittests/wasm/loop-assignment-analysis-unittest.cc
index 9586219..e77c1cf 100644
--- a/test/unittests/wasm/loop-assignment-analysis-unittest.cc
+++ b/test/unittests/wasm/loop-assignment-analysis-unittest.cc
@@ -23,25 +23,12 @@
class WasmLoopAssignmentAnalyzerTest : public TestWithZone {
public:
- WasmLoopAssignmentAnalyzerTest() : TestWithZone(), sigs() {
- init_env(&env, sigs.v_v());
- }
-
+ WasmLoopAssignmentAnalyzerTest() : num_locals(0) {}
TestSignatures sigs;
- FunctionEnv env;
-
- static void init_env(FunctionEnv* env, FunctionSig* sig) {
- env->module = nullptr;
- env->sig = sig;
- env->local_i32_count = 0;
- env->local_i64_count = 0;
- env->local_f32_count = 0;
- env->local_f64_count = 0;
- env->SumLocals();
- }
+ uint32_t num_locals;
BitVector* Analyze(const byte* start, const byte* end) {
- return AnalyzeLoopAssignmentForTesting(zone(), &env, start, end);
+ return AnalyzeLoopAssignmentForTesting(zone(), num_locals, start, end);
}
};
@@ -60,13 +47,13 @@
for (int j = 0; j < assigned->length(); j++) {
CHECK_EQ(false, assigned->Contains(j));
}
- env.AddLocals(kAstI32, 1);
+ num_locals++;
}
}
TEST_F(WasmLoopAssignmentAnalyzerTest, One) {
- env.AddLocals(kAstI32, 5);
+ num_locals = 5;
for (int i = 0; i < 5; i++) {
byte code[] = {WASM_LOOP(1, WASM_SET_ZERO(i))};
BitVector* assigned = Analyze(code, code + arraysize(code));
@@ -78,7 +65,7 @@
TEST_F(WasmLoopAssignmentAnalyzerTest, OneBeyond) {
- env.AddLocals(kAstI32, 5);
+ num_locals = 5;
for (int i = 0; i < 5; i++) {
byte code[] = {WASM_LOOP(1, WASM_SET_ZERO(i)), WASM_SET_ZERO(1)};
BitVector* assigned = Analyze(code, code + arraysize(code));
@@ -90,7 +77,7 @@
TEST_F(WasmLoopAssignmentAnalyzerTest, Two) {
- env.AddLocals(kAstI32, 5);
+ num_locals = 5;
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
byte code[] = {WASM_LOOP(2, WASM_SET_ZERO(i), WASM_SET_ZERO(j))};
@@ -105,7 +92,7 @@
TEST_F(WasmLoopAssignmentAnalyzerTest, NestedIf) {
- env.AddLocals(kAstI32, 5);
+ num_locals = 5;
for (int i = 0; i < 5; i++) {
byte code[] = {WASM_LOOP(
1, WASM_IF_ELSE(WASM_SET_ZERO(0), WASM_SET_ZERO(i), WASM_SET_ZERO(1)))};
@@ -126,7 +113,7 @@
TEST_F(WasmLoopAssignmentAnalyzerTest, BigLocal) {
- env.AddLocals(kAstI32, 65000);
+ num_locals = 65000;
for (int i = 13; i < 65000; i = static_cast<int>(i * 1.5)) {
byte code[] = {kExprLoop,
1,
@@ -148,7 +135,7 @@
TEST_F(WasmLoopAssignmentAnalyzerTest, Break) {
- env.AddLocals(kAstI32, 3);
+ num_locals = 3;
byte code[] = {
WASM_LOOP(1, WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_SET_ZERO(1)))),
WASM_SET_ZERO(0)};
@@ -162,7 +149,7 @@
TEST_F(WasmLoopAssignmentAnalyzerTest, Loop1) {
- env.AddLocals(kAstI32, 5);
+ num_locals = 5;
byte code[] = {
WASM_LOOP(1, WASM_IF(WASM_GET_LOCAL(0),
WASM_BRV(0, WASM_SET_LOCAL(
@@ -179,9 +166,8 @@
TEST_F(WasmLoopAssignmentAnalyzerTest, Loop2) {
- env.AddLocals(kAstI32, 3);
+ num_locals = 6;
const byte kIter = 0;
- env.AddLocals(kAstF32, 3);
const byte kSum = 3;
byte code[] = {WASM_BLOCK(
diff --git a/test/unittests/wasm/module-decoder-unittest.cc b/test/unittests/wasm/module-decoder-unittest.cc
index 467ffcc..44e7865 100644
--- a/test/unittests/wasm/module-decoder-unittest.cc
+++ b/test/unittests/wasm/module-decoder-unittest.cc
@@ -5,20 +5,26 @@
#include "test/unittests/test-utils.h"
#include "src/wasm/module-decoder.h"
+#include "src/wasm/wasm-macro-gen.h"
#include "src/wasm/wasm-opcodes.h"
namespace v8 {
namespace internal {
namespace wasm {
-class WasmModuleVerifyTest : public TestWithZone {
- public:
- ModuleResult DecodeModule(const byte* module_start, const byte* module_end) {
- return DecodeWasmModule(nullptr, zone(), module_start, module_end, false,
- false);
- }
-};
+#define EMPTY_FUNCTION(sig_index) 0, SIG_INDEX(sig_index), U16_LE(0)
+#define EMPTY_FUNCTION_SIZE ((size_t)5)
+#define EMPTY_BODY 0
+#define EMPTY_BODY_SIZE ((size_t)1)
+#define NOP_BODY 2, 0, kExprNop
+#define NOP_BODY_SIZE ((size_t)3)
+#define VOID_VOID_SIG 0, kLocalVoid
+#define VOID_VOID_SIG_SIZE ((size_t)2)
+#define INT_INT_SIG 1, kLocalI32, kLocalI32
+#define INT_INT_SIG_SIZE ((size_t)3)
+#define SECTION(NAME, EXTRA_SIZE) \
+ U32V_1(WASM_SECTION_##NAME##_SIZE + (EXTRA_SIZE)), WASM_SECTION_##NAME
#define EXPECT_VERIFIES(data) \
do { \
@@ -27,14 +33,30 @@
if (result.val) delete result.val; \
} while (false)
-
-#define EXPECT_FAILURE(data) \
- do { \
- ModuleResult result = DecodeModule(data, data + arraysize(data)); \
- EXPECT_FALSE(result.ok()); \
- if (result.val) delete result.val; \
+#define EXPECT_FAILURE_LEN(data, length) \
+ do { \
+ ModuleResult result = DecodeModule(data, data + length); \
+ EXPECT_FALSE(result.ok()); \
+ if (result.val) delete result.val; \
} while (false)
+#define EXPECT_FAILURE(data) EXPECT_FAILURE_LEN(data, sizeof(data))
+
+#define EXPECT_OFF_END_FAILURE(data, min, max) \
+ do { \
+ for (size_t length = min; length < max; length++) { \
+ EXPECT_FAILURE_LEN(data, length); \
+ } \
+ } while (false)
+
+static size_t SizeOfVarInt(size_t value) {
+ size_t size = 0;
+ do {
+ size++;
+ value = value >> 7;
+ } while (value > 0);
+ return size;
+}
struct LocalTypePair {
uint8_t code;
@@ -44,39 +66,59 @@
{kLocalF32, kAstF32},
{kLocalF64, kAstF64}};
-
-// TODO(titzer): use these macros everywhere below.
-#define U32_LE(v) \
- static_cast<byte>(v), static_cast<byte>((v) >> 8), \
- static_cast<byte>((v) >> 16), static_cast<byte>((v) >> 24)
-
-
-#define U16_LE(v) static_cast<byte>(v), static_cast<byte>((v) >> 8)
-
-
-TEST_F(WasmModuleVerifyTest, DecodeEmpty) {
- static const byte data[1]{kDeclEnd};
- {
- ModuleResult result = DecodeModule(data, data);
- EXPECT_TRUE(result.ok());
- if (result.val) delete result.val;
+class WasmModuleVerifyTest : public TestWithZone {
+ public:
+ ModuleResult DecodeModule(const byte* module_start, const byte* module_end) {
+ // Add the WASM magic and version number automatically.
+ size_t size = static_cast<size_t>(module_end - module_start);
+ byte header[] = {WASM_MODULE_HEADER};
+ size_t total = sizeof(header) + size;
+ auto temp = new byte[total];
+ memcpy(temp, header, sizeof(header));
+ memcpy(temp + sizeof(header), module_start, size);
+ ModuleResult result = DecodeWasmModule(nullptr, zone(), temp, temp + total,
+ false, kWasmOrigin);
+ delete[] temp;
+ return result;
}
- {
- ModuleResult result = DecodeModule(data, data + 1);
- EXPECT_TRUE(result.ok());
+ ModuleResult DecodeModuleNoHeader(const byte* module_start,
+ const byte* module_end) {
+ return DecodeWasmModule(nullptr, zone(), module_start, module_end, false,
+ kWasmOrigin);
+ }
+};
+
+TEST_F(WasmModuleVerifyTest, WrongMagic) {
+ for (uint32_t x = 1; x; x <<= 1) {
+ const byte data[] = {U32_LE(kWasmMagic ^ x), U32_LE(kWasmVersion),
+ SECTION(END, 0)};
+ ModuleResult result = DecodeModuleNoHeader(data, data + sizeof(data));
+ EXPECT_FALSE(result.ok());
if (result.val) delete result.val;
}
}
+TEST_F(WasmModuleVerifyTest, WrongVersion) {
+ for (uint32_t x = 1; x; x <<= 1) {
+ const byte data[] = {U32_LE(kWasmMagic), U32_LE(kWasmVersion ^ x),
+ SECTION(END, 0)};
+ ModuleResult result = DecodeModuleNoHeader(data, data + sizeof(data));
+ EXPECT_FALSE(result.ok());
+ if (result.val) delete result.val;
+ }
+}
+
+TEST_F(WasmModuleVerifyTest, DecodeEmpty) {
+ static const byte data[] = {SECTION(END, 0)};
+ EXPECT_VERIFIES(data);
+}
TEST_F(WasmModuleVerifyTest, OneGlobal) {
static const byte data[] = {
- kDeclGlobals,
+ SECTION(GLOBALS, 7), // --
1,
- 0,
- 0,
- 0,
- 0, // name offset
+ NAME_LENGTH(1),
+ 'g', // name
kMemI32, // memory type
0, // exported
};
@@ -85,13 +127,13 @@
// Should decode to exactly one global.
ModuleResult result = DecodeModule(data, data + arraysize(data));
EXPECT_TRUE(result.ok());
- EXPECT_EQ(1, result.val->globals->size());
- EXPECT_EQ(0, result.val->functions->size());
- EXPECT_EQ(0, result.val->data_segments->size());
+ EXPECT_EQ(1, result.val->globals.size());
+ EXPECT_EQ(0, result.val->functions.size());
+ EXPECT_EQ(0, result.val->data_segments.size());
- WasmGlobal* global = &result.val->globals->back();
+ WasmGlobal* global = &result.val->globals.back();
- EXPECT_EQ(0, global->name_offset);
+ EXPECT_EQ(1, global->name_length);
EXPECT_EQ(MachineType::Int32(), global->type);
EXPECT_EQ(0, global->offset);
EXPECT_FALSE(global->exported);
@@ -99,18 +141,14 @@
if (result.val) delete result.val;
}
- for (size_t size = 1; size < arraysize(data); size++) {
- // Should fall off end of module bytes.
- ModuleResult result = DecodeModule(data, data + size);
- EXPECT_FALSE(result.ok());
- if (result.val) delete result.val;
- }
+ EXPECT_OFF_END_FAILURE(data, 1, sizeof(data));
}
TEST_F(WasmModuleVerifyTest, ZeroGlobals) {
static const byte data[] = {
- kDeclGlobals, 0, // declare 0 globals
+ SECTION(GLOBALS, 1), // --
+ 0, // declare 0 globals
};
ModuleResult result = DecodeModule(data, data + arraysize(data));
EXPECT_TRUE(result.ok());
@@ -135,16 +173,22 @@
TEST_F(WasmModuleVerifyTest, NGlobals) {
static const byte data[] = {
- 0, 0, 0, 0, // name offset
- kMemI32, // memory type
- 0, // exported
+ NO_NAME, // name length
+ kMemI32, // memory type
+ 0, // exported
};
- for (uint32_t i = 0; i < 1000000; i = i * 7 + 1) {
+
+ for (uint32_t i = 0; i < 1000000; i = i * 13 + 1) {
std::vector<byte> buffer;
- buffer.push_back(kDeclGlobals);
- AppendUint32v(buffer, i);
+ size_t size =
+ WASM_SECTION_GLOBALS_SIZE + SizeOfVarInt(i) + i * sizeof(data);
+ const byte globals[] = {U32V_5(size), WASM_SECTION_GLOBALS};
+ for (size_t g = 0; g != sizeof(globals); ++g) {
+ buffer.push_back(globals[g]);
+ }
+ AppendUint32v(buffer, i); // Number of globals.
for (uint32_t j = 0; j < i; j++) {
- buffer.insert(buffer.end(), data, data + arraysize(data));
+ buffer.insert(buffer.end(), data, data + sizeof(data));
}
ModuleResult result = DecodeModule(&buffer[0], &buffer[0] + buffer.size());
@@ -153,33 +197,25 @@
}
}
-
TEST_F(WasmModuleVerifyTest, GlobalWithInvalidNameOffset) {
static const byte data[] = {
- kDeclGlobals,
- 1, // declare one global
- 0,
- 3,
- 0,
- 0, // name offset
- kMemI32, // memory type
+ SECTION(GLOBALS, 7),
+ 1, // declare one global
+ NO_NAME, // name offset
+ 33, // memory type
0, // exported
};
EXPECT_FAILURE(data);
}
-
TEST_F(WasmModuleVerifyTest, GlobalWithInvalidMemoryType) {
static const byte data[] = {
- kDeclGlobals,
- 1, // declare one global
- 0,
- 0,
- 0,
- 0, // name offset
- 33, // memory type
- 0, // exported
+ SECTION(GLOBALS, 7),
+ 1, // declare one global
+ NO_NAME, // name offset
+ 33, // memory type
+ 0, // exported
};
EXPECT_FAILURE(data);
@@ -188,18 +224,12 @@
TEST_F(WasmModuleVerifyTest, TwoGlobals) {
static const byte data[] = {
- kDeclGlobals,
+ SECTION(GLOBALS, 13),
2,
- 0,
- 0,
- 0,
- 0, // #0: name offset
+ NO_NAME, // #0: name length
kMemF32, // memory type
0, // exported
- 0,
- 0,
- 0,
- 0, // #1: name offset
+ NO_NAME, // #1: name length
kMemF64, // memory type
1, // exported
};
@@ -208,19 +238,19 @@
// Should decode to exactly two globals.
ModuleResult result = DecodeModule(data, data + arraysize(data));
EXPECT_TRUE(result.ok());
- EXPECT_EQ(2, result.val->globals->size());
- EXPECT_EQ(0, result.val->functions->size());
- EXPECT_EQ(0, result.val->data_segments->size());
+ EXPECT_EQ(2, result.val->globals.size());
+ EXPECT_EQ(0, result.val->functions.size());
+ EXPECT_EQ(0, result.val->data_segments.size());
- WasmGlobal* g0 = &result.val->globals->at(0);
- WasmGlobal* g1 = &result.val->globals->at(1);
+ WasmGlobal* g0 = &result.val->globals[0];
+ WasmGlobal* g1 = &result.val->globals[1];
- EXPECT_EQ(0, g0->name_offset);
+ EXPECT_EQ(0, g0->name_length);
EXPECT_EQ(MachineType::Float32(), g0->type);
EXPECT_EQ(0, g0->offset);
EXPECT_FALSE(g0->exported);
- EXPECT_EQ(0, g1->name_offset);
+ EXPECT_EQ(0, g1->name_length);
EXPECT_EQ(MachineType::Float64(), g1->type);
EXPECT_EQ(0, g1->offset);
EXPECT_TRUE(g1->exported);
@@ -228,26 +258,28 @@
if (result.val) delete result.val;
}
- for (size_t size = 1; size < arraysize(data); size++) {
- // Should fall off end of module bytes.
- ModuleResult result = DecodeModule(data, data + size);
- EXPECT_FALSE(result.ok());
- if (result.val) delete result.val;
- }
+ EXPECT_OFF_END_FAILURE(data, 1, sizeof(data));
}
TEST_F(WasmModuleVerifyTest, OneSignature) {
- static const byte data[] = {
- kDeclSignatures, 1, 0, kLocalVoid // void -> void
- };
- EXPECT_VERIFIES(data);
+ {
+ static const byte data[] = {SECTION(SIGNATURES, 1 + VOID_VOID_SIG_SIZE), 1,
+ VOID_VOID_SIG};
+ EXPECT_VERIFIES(data);
+ }
+
+ {
+ static const byte data[] = {SECTION(SIGNATURES, 1 + INT_INT_SIG_SIZE), 1,
+ INT_INT_SIG};
+ EXPECT_VERIFIES(data);
+ }
}
TEST_F(WasmModuleVerifyTest, MultipleSignatures) {
static const byte data[] = {
- kDeclSignatures,
+ SECTION(SIGNATURES, 10),
3,
0,
kLocalVoid, // void -> void
@@ -262,41 +294,36 @@
ModuleResult result = DecodeModule(data, data + arraysize(data));
EXPECT_TRUE(result.ok());
- EXPECT_EQ(3, result.val->signatures->size());
- if (result.val->signatures->size() == 3) {
- EXPECT_EQ(0, result.val->signatures->at(0)->return_count());
- EXPECT_EQ(1, result.val->signatures->at(1)->return_count());
- EXPECT_EQ(1, result.val->signatures->at(2)->return_count());
+ EXPECT_EQ(3, result.val->signatures.size());
+ if (result.val->signatures.size() == 3) {
+ EXPECT_EQ(0, result.val->signatures[0]->return_count());
+ EXPECT_EQ(1, result.val->signatures[1]->return_count());
+ EXPECT_EQ(1, result.val->signatures[2]->return_count());
- EXPECT_EQ(0, result.val->signatures->at(0)->parameter_count());
- EXPECT_EQ(1, result.val->signatures->at(1)->parameter_count());
- EXPECT_EQ(2, result.val->signatures->at(2)->parameter_count());
+ EXPECT_EQ(0, result.val->signatures[0]->parameter_count());
+ EXPECT_EQ(1, result.val->signatures[1]->parameter_count());
+ EXPECT_EQ(2, result.val->signatures[2]->parameter_count());
}
if (result.val) delete result.val;
- for (size_t size = 1; size < arraysize(data); size++) {
- ModuleResult result = DecodeModule(data, data + size);
- // Should fall off the end of module bytes.
- EXPECT_FALSE(result.ok());
- if (result.val) delete result.val;
- }
+ EXPECT_OFF_END_FAILURE(data, 1, sizeof(data));
}
TEST_F(WasmModuleVerifyTest, FunctionWithoutSig) {
static const byte data[] = {
- kDeclFunctions, 1,
+ SECTION(FUNCTIONS, 25), 1,
// func#0 ------------------------------------------------------
- 0, 0, // signature index
- 0, 0, 0, 0, // name offset
- 0, 0, 0, 0, // code start offset
- 0, 0, 0, 0, // code end offset
- 1, 2, // local int32 count
- 3, 4, // local int64 count
- 5, 6, // local float32 count
- 7, 8, // local float64 count
- 0, // exported
- 1 // external
+ SIG_INDEX(0), // signature index
+ NO_NAME, // name length
+ U32_LE(0), // code start offset
+ U32_LE(0), // code end offset
+ U16_LE(899), // local int32 count
+ U16_LE(799), // local int64 count
+ U16_LE(699), // local float32 count
+ U16_LE(599), // local float64 count
+ 0, // exported
+ 1 // external
};
ModuleResult result = DecodeModule(data, data + arraysize(data));
@@ -306,23 +333,23 @@
TEST_F(WasmModuleVerifyTest, OneEmptyVoidVoidFunction) {
- const int kCodeStartOffset = 23;
+ const int kCodeStartOffset = 51;
const int kCodeEndOffset = kCodeStartOffset + 1;
static const byte data[] = {
- kDeclSignatures, 1,
+ SECTION(SIGNATURES, 1 + VOID_VOID_SIG_SIZE), 1,
// sig#0 -------------------------------------------------------
- 0, 0, // void -> void
+ VOID_VOID_SIG,
// func#0 ------------------------------------------------------
- kDeclFunctions, 1,
- kDeclFunctionLocals | kDeclFunctionExport | kDeclFunctionName, 0,
- 0, // signature index
- 9, 0, 0, 0, // name offset
- 11, 2, // local int32 count
- 13, 4, // local int64 count
- 15, 6, // local float32 count
- 17, 8, // local float64 count
- 1, 0, // size
+ SECTION(FUNCTIONS, 19), 1,
+ kDeclFunctionLocals | kDeclFunctionExport | kDeclFunctionName,
+ SIG_INDEX(0), // signature index
+ NAME_LENGTH(2), 'h', 'i', // name
+ U16_LE(1466), // local int32 count
+ U16_LE(1355), // local int64 count
+ U16_LE(1244), // local float32 count
+ U16_LE(1133), // local float64 count
+ 1, 0, // size
kExprNop,
};
@@ -330,22 +357,23 @@
// Should decode to exactly one function.
ModuleResult result = DecodeModule(data, data + arraysize(data));
EXPECT_TRUE(result.ok());
- EXPECT_EQ(0, result.val->globals->size());
- EXPECT_EQ(1, result.val->signatures->size());
- EXPECT_EQ(1, result.val->functions->size());
- EXPECT_EQ(0, result.val->data_segments->size());
- EXPECT_EQ(0, result.val->function_table->size());
+ EXPECT_EQ(0, result.val->globals.size());
+ EXPECT_EQ(1, result.val->signatures.size());
+ EXPECT_EQ(1, result.val->functions.size());
+ EXPECT_EQ(0, result.val->data_segments.size());
+ EXPECT_EQ(0, result.val->function_table.size());
- WasmFunction* function = &result.val->functions->back();
+ WasmFunction* function = &result.val->functions.back();
- EXPECT_EQ(9, function->name_offset);
+ EXPECT_EQ(39, function->name_offset);
+ EXPECT_EQ(2, function->name_length);
EXPECT_EQ(kCodeStartOffset, function->code_start_offset);
EXPECT_EQ(kCodeEndOffset, function->code_end_offset);
- EXPECT_EQ(523, function->local_i32_count);
- EXPECT_EQ(1037, function->local_i64_count);
- EXPECT_EQ(1551, function->local_f32_count);
- EXPECT_EQ(2065, function->local_f64_count);
+ EXPECT_EQ(1466, function->local_i32_count);
+ EXPECT_EQ(1355, function->local_i64_count);
+ EXPECT_EQ(1244, function->local_f32_count);
+ EXPECT_EQ(1133, function->local_f64_count);
EXPECT_TRUE(function->exported);
EXPECT_FALSE(function->external);
@@ -353,32 +381,26 @@
if (result.val) delete result.val;
}
- for (size_t size = 5; size < arraysize(data); size++) {
- // Should fall off end of module bytes.
- ModuleResult result = DecodeModule(data, data + size);
- EXPECT_FALSE(result.ok());
- if (result.val) delete result.val;
- }
+ EXPECT_OFF_END_FAILURE(data, 16, sizeof(data));
}
TEST_F(WasmModuleVerifyTest, OneFunctionImported) {
static const byte data[] = {
- kDeclSignatures, 1,
+ SECTION(SIGNATURES, VOID_VOID_SIG_SIZE), 1,
// sig#0 -------------------------------------------------------
- 0, 0, // void -> void
- kDeclFunctions, 1,
+ VOID_VOID_SIG, SECTION(FUNCTIONS, 6), 1,
// func#0 ------------------------------------------------------
kDeclFunctionImport, // no name, no locals, imported
- 0, 0, // signature index
+ SIG_INDEX(0),
};
ModuleResult result = DecodeModule(data, data + arraysize(data));
EXPECT_TRUE(result.ok());
- EXPECT_EQ(1, result.val->functions->size());
- WasmFunction* function = &result.val->functions->back();
+ EXPECT_EQ(1, result.val->functions.size());
+ WasmFunction* function = &result.val->functions.back();
- EXPECT_EQ(0, function->name_offset);
+ EXPECT_EQ(0, function->name_length);
EXPECT_EQ(0, function->code_start_offset);
EXPECT_EQ(0, function->code_end_offset);
@@ -393,16 +415,15 @@
if (result.val) delete result.val;
}
-
TEST_F(WasmModuleVerifyTest, OneFunctionWithNopBody) {
- static const byte kCodeStartOffset = 11;
+ static const byte kCodeStartOffset = 40;
static const byte kCodeEndOffset = kCodeStartOffset + 1;
static const byte data[] = {
- kDeclSignatures, 1,
+ SECTION(SIGNATURES, 3), 1,
// sig#0 -------------------------------------------------------
0, 0, // void -> void
- kDeclFunctions, 1,
+ SECTION(FUNCTIONS, 7), 1,
// func#0 ------------------------------------------------------
0, // no name, no locals
0, 0, // signature index
@@ -412,10 +433,10 @@
ModuleResult result = DecodeModule(data, data + arraysize(data));
EXPECT_TRUE(result.ok());
- EXPECT_EQ(1, result.val->functions->size());
- WasmFunction* function = &result.val->functions->back();
+ EXPECT_EQ(1, result.val->functions.size());
+ WasmFunction* function = &result.val->functions.back();
- EXPECT_EQ(0, function->name_offset);
+ EXPECT_EQ(0, function->name_length);
EXPECT_EQ(kCodeStartOffset, function->code_start_offset);
EXPECT_EQ(kCodeEndOffset, function->code_end_offset);
@@ -432,14 +453,14 @@
TEST_F(WasmModuleVerifyTest, OneFunctionWithNopBody_WithLocals) {
- static const byte kCodeStartOffset = 19;
+ static const byte kCodeStartOffset = 48;
static const byte kCodeEndOffset = kCodeStartOffset + 1;
static const byte data[] = {
- kDeclSignatures, 1,
+ SECTION(SIGNATURES, 3), 1,
// sig#0 -------------------------------------------------------
0, 0, // void -> void
- kDeclFunctions, 1,
+ SECTION(FUNCTIONS, 15), 1,
// func#0 ------------------------------------------------------
kDeclFunctionLocals, 0, 0, // signature index
1, 2, // local int32 count
@@ -452,10 +473,10 @@
ModuleResult result = DecodeModule(data, data + arraysize(data));
EXPECT_TRUE(result.ok());
- EXPECT_EQ(1, result.val->functions->size());
- WasmFunction* function = &result.val->functions->back();
+ EXPECT_EQ(1, result.val->functions.size());
+ WasmFunction* function = &result.val->functions.back();
- EXPECT_EQ(0, function->name_offset);
+ EXPECT_EQ(0, function->name_length);
EXPECT_EQ(kCodeStartOffset, function->code_start_offset);
EXPECT_EQ(kCodeEndOffset, function->code_end_offset);
@@ -472,67 +493,68 @@
TEST_F(WasmModuleVerifyTest, OneGlobalOneFunctionWithNopBodyOneDataSegment) {
- static const byte kDeclMemorySize = 4;
- static const byte kCodeStartOffset =
- 2 + kDeclMemorySize + kDeclGlobalSize + 4 + 2 + 17;
+ static const byte kCodeStartOffset = 75;
static const byte kCodeEndOffset = kCodeStartOffset + 3;
+ static const byte kDataSegmentSourceOffset = kCodeEndOffset + 20;
static const byte data[] = {
- kDeclMemory, 28, 28, 1,
+ SECTION(MEMORY, 3), 28, 28, 1,
// global#0 --------------------------------------------------
- kDeclGlobals, 1, 0, 0, 0, 0, // name offset
- kMemU8, // memory type
- 0, // exported
+ SECTION(GLOBALS, 7), 1,
+ 0, // name length
+ kMemU8, // memory type
+ 0, // exported
// sig#0 -----------------------------------------------------
- kDeclSignatures, 1, 0, 0, // void -> void
+ SECTION(SIGNATURES, 3), 1, 0, 0, // void -> void
// func#0 ----------------------------------------------------
- kDeclFunctions, 1, kDeclFunctionLocals | kDeclFunctionName, 0,
- 0, // signature index
- 9, 0, 0, 0, // name offset
- 1, 2, // local int32 count
- 3, 4, // local int64 count
- 5, 6, // local float32 count
- 7, 8, // local float64 count
- 3, 0, // body size
- kExprNop, // func#0 body
- kExprNop, // func#0 body
- kExprNop, // func#0 body
+ SECTION(FUNCTIONS, 20), 1, kDeclFunctionLocals | kDeclFunctionName, 0,
+ 0, // signature index
+ 2, 'h', 'i', // name
+ 1, 2, // local int32 count
+ 3, 4, // local int64 count
+ 5, 6, // local float32 count
+ 7, 8, // local float64 count
+ 3, 0, // body size
+ kExprNop, // func#0 body
+ kExprNop, // func#0 body
+ kExprNop, // func#0 body
// segment#0 -------------------------------------------------
- kDeclDataSegments, 1, 0xae, 0xb3, 0x08, 0, // dest addr
- 15, 0, 0, 0, // source offset
- 5, 0, 0, 0, // source size
- 1, // init
+ SECTION(DATA_SEGMENTS, 14), 1,
+ U32V_3(0x8b3ae), // dest addr
+ U32V_1(5), // source size
+ 0, 1, 2, 3, 4, // data bytes
// rest ------------------------------------------------------
- kDeclEnd,
+ SECTION(END, 0),
};
{
ModuleResult result = DecodeModule(data, data + arraysize(data));
EXPECT_TRUE(result.ok());
- EXPECT_EQ(1, result.val->globals->size());
- EXPECT_EQ(1, result.val->functions->size());
- EXPECT_EQ(1, result.val->data_segments->size());
+ EXPECT_EQ(1, result.val->globals.size());
+ EXPECT_EQ(1, result.val->functions.size());
+ EXPECT_EQ(1, result.val->data_segments.size());
- WasmGlobal* global = &result.val->globals->back();
+ WasmGlobal* global = &result.val->globals.back();
- EXPECT_EQ(0, global->name_offset);
+ EXPECT_EQ(0, global->name_length);
EXPECT_EQ(MachineType::Uint8(), global->type);
EXPECT_EQ(0, global->offset);
EXPECT_FALSE(global->exported);
- WasmFunction* function = &result.val->functions->back();
+ WasmFunction* function = &result.val->functions.back();
- EXPECT_EQ(9, function->name_offset);
+ EXPECT_EQ(63, function->name_offset);
+ EXPECT_EQ(2, function->name_length);
EXPECT_EQ(kCodeStartOffset, function->code_start_offset);
EXPECT_EQ(kCodeEndOffset, function->code_end_offset);
EXPECT_FALSE(function->exported);
EXPECT_FALSE(function->external);
- WasmDataSegment* segment = &result.val->data_segments->back();
+ WasmDataSegment* segment = &result.val->data_segments.back();
EXPECT_EQ(0x8b3ae, segment->dest_addr);
- EXPECT_EQ(15, segment->source_offset);
+ EXPECT_EQ(kDataSegmentSourceOffset, segment->source_offset);
EXPECT_EQ(5, segment->source_size);
EXPECT_TRUE(segment->init);
@@ -542,147 +564,119 @@
TEST_F(WasmModuleVerifyTest, OneDataSegment) {
+ const byte kDataSegmentSourceOffset = 39;
const byte data[] = {
- kDeclMemory, 28, 28, 1, kDeclDataSegments, 1, 0xaa, 0xbb, 0x09,
- 0, // dest addr
- 11, 0, 0,
- 0, // source offset
- 3, 0, 0,
- 0, // source size
- 1, // init
+ SECTION(MEMORY, 3),
+ 28,
+ 28,
+ 1,
+ SECTION(DATA_SEGMENTS, 8),
+ 1,
+ U32V_3(0x9bbaa), // dest addr
+ U32V_1(3), // source size
+ 'a',
+ 'b',
+ 'c' // data bytes
};
{
EXPECT_VERIFIES(data);
ModuleResult result = DecodeModule(data, data + arraysize(data));
EXPECT_TRUE(result.ok());
- EXPECT_EQ(0, result.val->globals->size());
- EXPECT_EQ(0, result.val->functions->size());
- EXPECT_EQ(1, result.val->data_segments->size());
+ EXPECT_EQ(0, result.val->globals.size());
+ EXPECT_EQ(0, result.val->functions.size());
+ EXPECT_EQ(1, result.val->data_segments.size());
- WasmDataSegment* segment = &result.val->data_segments->back();
+ WasmDataSegment* segment = &result.val->data_segments.back();
EXPECT_EQ(0x9bbaa, segment->dest_addr);
- EXPECT_EQ(11, segment->source_offset);
+ EXPECT_EQ(kDataSegmentSourceOffset, segment->source_offset);
EXPECT_EQ(3, segment->source_size);
EXPECT_TRUE(segment->init);
if (result.val) delete result.val;
}
- for (size_t size = 5; size < arraysize(data); size++) {
- // Should fall off end of module bytes.
- ModuleResult result = DecodeModule(data, data + size);
- EXPECT_FALSE(result.ok());
- if (result.val) delete result.val;
- }
+ EXPECT_OFF_END_FAILURE(data, 13, sizeof(data));
}
TEST_F(WasmModuleVerifyTest, TwoDataSegments) {
+ const byte kDataSegment0SourceOffset = 39;
+ const byte kDataSegment1SourceOffset = 39 + 8;
+
const byte data[] = {
- kDeclMemory, 28, 28, 1, kDeclDataSegments, 2, 0xee, 0xff, 0x07,
- 0, // dest addr
- 9, 0, 0,
- 0, // #0: source offset
- 4, 0, 0,
- 0, // source size
- 0, // init
- 0xcc, 0xdd, 0x06,
- 0, // #1: dest addr
- 6, 0, 0,
- 0, // source offset
- 10, 0, 0,
- 0, // source size
- 1, // init
+ SECTION(MEMORY, 3),
+ 28,
+ 28,
+ 1,
+ SECTION(DATA_SEGMENTS, 31),
+ 2, // segment count
+ U32V_3(0x7ffee), // #0: dest addr
+ U32V_1(4), // source size
+ 1,
+ 2,
+ 3,
+ 4, // data bytes
+ U32V_3(0x6ddcc), // #1: dest addr
+ U32V_1(10), // source size
+ 1,
+ 2,
+ 3,
+ 4,
+ 5,
+ 6,
+ 7,
+ 8,
+ 9,
+ 10 // data bytes
};
{
ModuleResult result = DecodeModule(data, data + arraysize(data));
EXPECT_TRUE(result.ok());
- EXPECT_EQ(0, result.val->globals->size());
- EXPECT_EQ(0, result.val->functions->size());
- EXPECT_EQ(2, result.val->data_segments->size());
+ EXPECT_EQ(0, result.val->globals.size());
+ EXPECT_EQ(0, result.val->functions.size());
+ EXPECT_EQ(2, result.val->data_segments.size());
- WasmDataSegment* s0 = &result.val->data_segments->at(0);
- WasmDataSegment* s1 = &result.val->data_segments->at(1);
+ WasmDataSegment* s0 = &result.val->data_segments[0];
+ WasmDataSegment* s1 = &result.val->data_segments[1];
EXPECT_EQ(0x7ffee, s0->dest_addr);
- EXPECT_EQ(9, s0->source_offset);
+ EXPECT_EQ(kDataSegment0SourceOffset, s0->source_offset);
EXPECT_EQ(4, s0->source_size);
- EXPECT_FALSE(s0->init);
+ EXPECT_TRUE(s0->init);
EXPECT_EQ(0x6ddcc, s1->dest_addr);
- EXPECT_EQ(6, s1->source_offset);
+ EXPECT_EQ(kDataSegment1SourceOffset, s1->source_offset);
EXPECT_EQ(10, s1->source_size);
EXPECT_TRUE(s1->init);
if (result.val) delete result.val;
}
- for (size_t size = 5; size < arraysize(data); size++) {
- // Should fall off end of module bytes.
- ModuleResult result = DecodeModule(data, data + size);
- EXPECT_FALSE(result.ok());
- if (result.val) delete result.val;
- }
+ EXPECT_OFF_END_FAILURE(data, 13, sizeof(data));
}
-
-TEST_F(WasmModuleVerifyTest, DataSegmentWithInvalidSource) {
- const int dest_addr = 0x100;
- const byte mem_size_log2 = 15;
- const int kDataSize = 19;
-
- for (int source_offset = 0; source_offset < 5 + kDataSize; source_offset++) {
- for (int source_size = -1; source_size < 5 + kDataSize; source_size += 3) {
- byte data[] = {
- kDeclMemory,
- mem_size_log2,
- mem_size_log2,
- 1,
- kDeclDataSegments,
- 1,
- U32_LE(dest_addr),
- U32_LE(source_offset),
- U32_LE(source_size),
- 1, // init
- };
-
- STATIC_ASSERT(kDataSize == arraysize(data));
-
- if (source_offset < kDataSize && source_size >= 0 &&
- (source_offset + source_size) <= kDataSize) {
- EXPECT_VERIFIES(data);
- } else {
- EXPECT_FAILURE(data);
- }
- }
- }
-}
-
-
TEST_F(WasmModuleVerifyTest, DataSegmentWithInvalidDest) {
const int source_size = 3;
- const int source_offset = 11;
- for (byte mem_size_log2 = 12; mem_size_log2 < 20; mem_size_log2++) {
- int mem_size = 1 << mem_size_log2;
+ for (byte mem_pages = 1; mem_pages < 16; mem_pages++) {
+ int mem_size = mem_pages * 0x10000; // 64k pages.
for (int dest_addr = mem_size - source_size;
dest_addr < mem_size + source_size; dest_addr++) {
- byte data[] = {
- kDeclMemory,
- mem_size_log2,
- mem_size_log2,
- 1,
- kDeclDataSegments,
- 1,
- U32_LE(dest_addr),
- U32_LE(source_offset),
- U32_LE(source_size),
- 1, // init
- };
+ byte data[] = {SECTION(MEMORY, 3),
+ mem_pages,
+ mem_pages,
+ 1,
+ SECTION(DATA_SEGMENTS, 14),
+ 1,
+ U32V_3(dest_addr),
+ U32V_1(source_size),
+ 'a',
+ 'b',
+ 'c'};
if (dest_addr <= (mem_size - source_size)) {
EXPECT_VERIFIES(data);
@@ -695,27 +689,24 @@
// To make below tests for indirect calls much shorter.
-#define FUNCTION(sig_index, external) \
- kDeclFunctionImport, static_cast<byte>(sig_index), \
- static_cast<byte>(sig_index >> 8)
-
+#define FUNCTION(sig_index, external) kDeclFunctionImport, SIG_INDEX(sig_index)
TEST_F(WasmModuleVerifyTest, OneIndirectFunction) {
static const byte data[] = {
// sig#0 -------------------------------------------------------
- kDeclSignatures, 1, 0, 0, // void -> void
+ SECTION(SIGNATURES, 3), 1, 0, 0, // void -> void
// func#0 ------------------------------------------------------
- kDeclFunctions, 1, FUNCTION(0, 0),
+ SECTION(FUNCTIONS, 4), 1, FUNCTION(0, 0),
// indirect table ----------------------------------------------
- kDeclFunctionTable, 1, 0, 0};
+ SECTION(FUNCTION_TABLE, 2), 1, U32V_1(0)};
ModuleResult result = DecodeModule(data, data + arraysize(data));
EXPECT_TRUE(result.ok());
if (result.ok()) {
- EXPECT_EQ(1, result.val->signatures->size());
- EXPECT_EQ(1, result.val->functions->size());
- EXPECT_EQ(1, result.val->function_table->size());
- EXPECT_EQ(0, result.val->function_table->at(0));
+ EXPECT_EQ(1, result.val->signatures.size());
+ EXPECT_EQ(1, result.val->functions.size());
+ EXPECT_EQ(1, result.val->function_table.size());
+ EXPECT_EQ(0, result.val->function_table[0]);
}
if (result.val) delete result.val;
}
@@ -724,23 +715,33 @@
TEST_F(WasmModuleVerifyTest, MultipleIndirectFunctions) {
static const byte data[] = {
// sig#0 -------------------------------------------------------
- kDeclSignatures, 2, 0, 0, // void -> void
- 0, kLocalI32, // void -> i32
+ SECTION(SIGNATURES, 5), 2, 0, 0, // void -> void
+ 0, kLocalI32, // void -> i32
// func#0 ------------------------------------------------------
- kDeclFunctions, 4, FUNCTION(0, 1), FUNCTION(1, 1), FUNCTION(0, 1),
- FUNCTION(1, 1),
+ SECTION(FUNCTIONS, 13), 4, FUNCTION(0, 1), // --
+ FUNCTION(1, 1), // --
+ FUNCTION(0, 1), // --
+ FUNCTION(1, 1), // --
// indirect table ----------------------------------------------
- kDeclFunctionTable, 8, 0, 0, 1, 0, 2, 0, 3, 0, 0, 0, 1, 0, 2, 0, 3, 0,
+ SECTION(FUNCTION_TABLE, 9), 8,
+ U32V_1(0), // --
+ U32V_1(1), // --
+ U32V_1(2), // --
+ U32V_1(3), // --
+ U32V_1(0), // --
+ U32V_1(1), // --
+ U32V_1(2), // --
+ U32V_1(3), // --
};
ModuleResult result = DecodeModule(data, data + arraysize(data));
EXPECT_TRUE(result.ok());
if (result.ok()) {
- EXPECT_EQ(2, result.val->signatures->size());
- EXPECT_EQ(4, result.val->functions->size());
- EXPECT_EQ(8, result.val->function_table->size());
+ EXPECT_EQ(2, result.val->signatures.size());
+ EXPECT_EQ(4, result.val->functions.size());
+ EXPECT_EQ(8, result.val->function_table.size());
for (int i = 0; i < 8; i++) {
- EXPECT_EQ(i & 3, result.val->function_table->at(i));
+ EXPECT_EQ(i & 3, result.val->function_table[i]);
}
}
if (result.val) delete result.val;
@@ -750,9 +751,9 @@
TEST_F(WasmModuleVerifyTest, IndirectFunctionNoFunctions) {
static const byte data[] = {
// sig#0 -------------------------------------------------------
- kDeclSignatures, 1, 0, 0, // void -> void
+ SECTION(SIGNATURES, 3), 1, 0, 0, // void -> void
// indirect table ----------------------------------------------
- kDeclFunctionTable, 1, 0, 0,
+ SECTION(FUNCTION_TABLE, 3), 1, 0, 0,
};
EXPECT_FAILURE(data);
@@ -762,11 +763,11 @@
TEST_F(WasmModuleVerifyTest, IndirectFunctionInvalidIndex) {
static const byte data[] = {
// sig#0 -------------------------------------------------------
- kDeclSignatures, 1, 0, 0, // void -> void
+ SECTION(SIGNATURES, 3), 1, 0, 0, // void -> void
// functions ---------------------------------------------------
- kDeclFunctions, 1, FUNCTION(0, 1),
+ SECTION(FUNCTIONS, 4), 1, FUNCTION(0, 1),
// indirect table ----------------------------------------------
- kDeclFunctionTable, 1, 1, 0,
+ SECTION(FUNCTION_TABLE, 3), 1, 1, 0,
};
EXPECT_FAILURE(data);
@@ -778,7 +779,8 @@
TEST_F(WasmSignatureDecodeTest, Ok_v_v) {
static const byte data[] = {0, 0};
- Zone zone;
+ base::AccountingAllocator allocator;
+ Zone zone(&allocator);
FunctionSig* sig =
DecodeWasmSignatureForTesting(&zone, data, data + arraysize(data));
@@ -906,10 +908,11 @@
TEST_F(WasmFunctionVerifyTest, Ok_v_v_empty) {
static const byte data[] = {
0, kLocalVoid, // signature
- 3, 0, // local int32 count
- 4, 0, // local int64 count
- 5, 0, // local float32 count
- 6, 0, // local float64 count
+ 4, // locals
+ 3, kLocalI32, // --
+ 4, kLocalI64, // --
+ 5, kLocalF32, // --
+ 6, kLocalF64, // --
kExprNop // body
};
@@ -922,12 +925,9 @@
EXPECT_EQ(0, function->sig->parameter_count());
EXPECT_EQ(0, function->sig->return_count());
EXPECT_EQ(0, function->name_offset);
- EXPECT_EQ(arraysize(data) - 1, function->code_start_offset);
+ EXPECT_EQ(2, function->code_start_offset);
EXPECT_EQ(arraysize(data), function->code_end_offset);
- EXPECT_EQ(3, function->local_i32_count);
- EXPECT_EQ(4, function->local_i64_count);
- EXPECT_EQ(5, function->local_f32_count);
- EXPECT_EQ(6, function->local_f64_count);
+ // TODO(titzer): verify encoding of local declarations
EXPECT_FALSE(function->external);
EXPECT_FALSE(function->exported);
}
@@ -935,156 +935,445 @@
if (result.val) delete result.val;
}
+TEST_F(WasmModuleVerifyTest, SectionWithoutNameLength) {
+ const byte data[] = {1};
+ EXPECT_FAILURE(data);
+}
-TEST_F(WasmModuleVerifyTest, WLLSectionNoLen) {
+TEST_F(WasmModuleVerifyTest, TheLoneliestOfValidModulesTheTrulyEmptyOne) {
const byte data[] = {
- kDeclWLL, // section without length.
+ 1, // Section size.
+ 0, // Empty section name.
+ // No section name, no content, nothing but sadness.
+ };
+ EXPECT_VERIFIES(data);
+}
+
+TEST_F(WasmModuleVerifyTest, OnlyUnknownSectionEmpty) {
+ const byte data[] = {
+ 5, // Section size.
+ 4, 'l', 'u', 'l', 'z', // unknown section.
+ };
+ EXPECT_VERIFIES(data);
+}
+
+TEST_F(WasmModuleVerifyTest, OnlyUnknownSectionNonEmpty) {
+ const byte data[] = {
+ 10, // Section size.
+ 4, 'l', 'u', 'l', 'z', // unknown section.
+ // Section content:
+ 0xff, 0xff, 0xff, 0xff, 0xff,
+ };
+ EXPECT_VERIFIES(data);
+}
+
+TEST_F(WasmModuleVerifyTest, SignatureFollowedByEmptyUnknownSection) {
+ const byte data[] = {
+ SECTION(SIGNATURES, 1 + VOID_VOID_SIG_SIZE), 1, VOID_VOID_SIG,
+ // -----------------------------------------------------------
+ 5, // Section size.
+ 4, 'l', 'u', 'l', 'z', // unknown section.
+ };
+ EXPECT_VERIFIES(data);
+}
+
+TEST_F(WasmModuleVerifyTest, SignatureFollowedByUnknownSection) {
+ const byte data[] = {
+ SECTION(SIGNATURES, 1 + VOID_VOID_SIG_SIZE), 1, VOID_VOID_SIG,
+ // -----------------------------------------------------------
+ 10, // Section size.
+ 4, 'l', 'u', 'l', 'z', // unknown section.
+ 0xff, 0xff, 0xff, 0xff, 0xff,
+ };
+ EXPECT_VERIFIES(data);
+}
+
+TEST_F(WasmModuleVerifyTest, SignatureFollowedByUnknownSectionWithLongLEB) {
+ const byte data[] = {
+ SECTION(SIGNATURES, 1 + VOID_VOID_SIG_SIZE), 1, VOID_VOID_SIG,
+ // -----------------------------------------------------------
+ 0x85, 0x80, 0x80, 0x80, 0x00, // Section size: 1 but in a 5-byte LEB.
+ 4, 'l', 'u', 'l', 'z', // unknown section.
+ };
+ EXPECT_VERIFIES(data);
+}
+
+TEST_F(WasmModuleVerifyTest, UnknownSectionOverflow) {
+ static const byte data[] = {
+ 13, // Section size.
+ 1, // Section name length.
+ '\0', // Section name.
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, // 10 byte section
};
EXPECT_FAILURE(data);
}
-
-TEST_F(WasmModuleVerifyTest, WLLSectionEmpty) {
+TEST_F(WasmModuleVerifyTest, UnknownSectionUnderflow) {
static const byte data[] = {
- kDeclWLL, 0, // empty section
- };
- ModuleResult result = DecodeModule(data, data + arraysize(data));
- EXPECT_TRUE(result.ok());
- if (result.val) delete result.val;
-}
-
-
-TEST_F(WasmModuleVerifyTest, WLLSectionOne) {
- static const byte data[] = {
- kDeclWLL,
- 1, // LEB128 1
- 0, // one byte section
- };
- ModuleResult result = DecodeModule(data, data + arraysize(data));
- EXPECT_TRUE(result.ok());
- if (result.val) delete result.val;
-}
-
-
-TEST_F(WasmModuleVerifyTest, WLLSectionTen) {
- static const byte data[] = {
- kDeclWLL,
- 10, // LEB128 10
- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, // 10 byte section
- };
- ModuleResult result = DecodeModule(data, data + arraysize(data));
- EXPECT_TRUE(result.ok());
- if (result.val) delete result.val;
-}
-
-
-TEST_F(WasmModuleVerifyTest, WLLSectionOverflow) {
- static const byte data[] = {
- kDeclWLL,
- 11, // LEB128 11
- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, // 10 byte section
+ 0xff, 0xff, 0xff, 0xff, 0x0f, // Section size LEB128 0xffffffff
+ 1, '\0', // Section name and name length.
+ 1, 2, 3, 4, // 4 byte section
};
EXPECT_FAILURE(data);
}
-
-TEST_F(WasmModuleVerifyTest, WLLSectionUnderflow) {
- static const byte data[] = {
- kDeclWLL, 0xff, 0xff, 0xff, 0xff, 0x0f, // LEB128 0xffffffff
- 1, 2, 3, 4, // 4 byte section
- };
- EXPECT_FAILURE(data);
-}
-
-
-TEST_F(WasmModuleVerifyTest, WLLSectionLoop) {
+TEST_F(WasmModuleVerifyTest, UnknownSectionLoop) {
// Would infinite loop decoding if wrapping and allowed.
static const byte data[] = {
- kDeclWLL, 0xfa, 0xff, 0xff, 0xff, 0x0f, // LEB128 0xfffffffa
- 1, 2, 3, 4, // 4 byte section
+ 0xfa, 0xff, 0xff, 0xff, 0x0f, // Section size LEB128 0xfffffffa
+ 1, '\0', // Section name and name length.
+ 1, 2, 3, 4, // 4 byte section
};
EXPECT_FAILURE(data);
}
+TEST_F(WasmModuleVerifyTest, UnknownSectionSkipped) {
+ static const byte data[] = {
+ 3, // Section size.
+ 1,
+ '\0', // Section name: LEB128 1, string '\0'
+ 0, // one byte section
+ SECTION(GLOBALS, 7),
+ 1,
+ 0, // name length
+ kMemI32, // memory type
+ 0, // exported
+ };
+ ModuleResult result = DecodeModule(data, data + arraysize(data));
+ EXPECT_TRUE(result.ok());
+
+ EXPECT_EQ(1, result.val->globals.size());
+ EXPECT_EQ(0, result.val->functions.size());
+ EXPECT_EQ(0, result.val->data_segments.size());
+
+ WasmGlobal* global = &result.val->globals.back();
+
+ EXPECT_EQ(0, global->name_length);
+ EXPECT_EQ(MachineType::Int32(), global->type);
+ EXPECT_EQ(0, global->offset);
+ EXPECT_FALSE(global->exported);
+
+ if (result.val) delete result.val;
+}
+
TEST_F(WasmModuleVerifyTest, ImportTable_empty) {
- static const byte data[] = {kDeclSignatures, 0, kDeclImportTable, 0};
+ static const byte data[] = {SECTION(SIGNATURES, 1), 0,
+ SECTION(IMPORT_TABLE, 1), 0};
EXPECT_VERIFIES(data);
}
TEST_F(WasmModuleVerifyTest, ImportTable_nosigs) {
- static const byte data[] = {kDeclImportTable, 0};
+ static const byte data[] = {SECTION(IMPORT_TABLE, 1), 0};
EXPECT_FAILURE(data);
}
TEST_F(WasmModuleVerifyTest, ImportTable_invalid_sig) {
static const byte data[] = {
- kDeclSignatures,
- 0,
- kDeclImportTable,
- 1,
- 0,
- 0, // sig index
- 1,
- 0,
- 0,
- 0, // module name
- 1,
- 0,
- 0,
- 0 // function name
+ SECTION(SIGNATURES, 1), 0, SECTION(IMPORT_TABLE, 6), 1,
+ IMPORT_SIG_INDEX(0), // sig index
+ NAME_LENGTH(1), 'm', // module name
+ NAME_LENGTH(1), 'f', // function name
};
EXPECT_FAILURE(data);
}
TEST_F(WasmModuleVerifyTest, ImportTable_one_sig) {
static const byte data[] = {
- kDeclSignatures,
+ SECTION(SIGNATURES, 1 + VOID_VOID_SIG_SIZE),
1,
- 0,
- static_cast<byte>(kAstStmt),
- kDeclImportTable,
- 1,
- 0,
- 0, // sig index
- 1,
- 0,
- 0,
- 0, // module name
- 1,
- 0,
- 0,
- 0 // function name
+ VOID_VOID_SIG,
+ SECTION(IMPORT_TABLE, 6),
+ 1, // --
+ IMPORT_SIG_INDEX(0), // sig index
+ NAME_LENGTH(1),
+ 'm', // module name
+ NAME_LENGTH(1),
+ 'f', // function name
};
EXPECT_VERIFIES(data);
}
+TEST_F(WasmModuleVerifyTest, ImportTable_invalid_module) {
+ static const byte data[] = {
+ SECTION(SIGNATURES, 1 + VOID_VOID_SIG_SIZE),
+ 1,
+ VOID_VOID_SIG,
+ SECTION(IMPORT_TABLE, 6),
+ 1, // --
+ IMPORT_SIG_INDEX(0), // sig index
+ NO_NAME, // module name
+ NAME_LENGTH(1),
+ 'f' // function name
+ };
+ EXPECT_FAILURE(data);
+}
+
TEST_F(WasmModuleVerifyTest, ImportTable_off_end) {
static const byte data[] = {
- kDeclSignatures,
+ SECTION(SIGNATURES, 1 + VOID_VOID_SIG_SIZE),
1,
- 0,
- static_cast<byte>(kAstStmt),
- kDeclImportTable,
+ VOID_VOID_SIG,
+ SECTION(IMPORT_TABLE, 6),
1,
- 0,
- 0, // sig index
- 1,
- 0,
- 0,
- 0, // module name
- 1,
- 0,
- 0,
- 0 // function name
+ IMPORT_SIG_INDEX(0), // sig index
+ NAME_LENGTH(1),
+ 'm', // module name
+ NAME_LENGTH(1),
+ 'f', // function name
};
- for (size_t length = 5; length < sizeof(data); length++) {
+ EXPECT_OFF_END_FAILURE(data, 16, sizeof(data));
+}
+
+TEST_F(WasmModuleVerifyTest, ExportTable_empty1) {
+ static const byte data[] = {SECTION(SIGNATURES, 1 + VOID_VOID_SIG_SIZE),
+ 1,
+ VOID_VOID_SIG,
+ SECTION(FUNCTIONS, 1 + EMPTY_FUNCTION_SIZE),
+ 1,
+ EMPTY_FUNCTION(0),
+ SECTION(EXPORT_TABLE, 1),
+ 0};
+ EXPECT_VERIFIES(data);
+}
+
+TEST_F(WasmModuleVerifyTest, ExportTable_empty2) {
+ static const byte data[] = {SECTION(SIGNATURES, 1), 0,
+ SECTION(FUNCTIONS, 1), 0,
+ SECTION(EXPORT_TABLE, 1), 0};
+ // TODO(titzer): current behavior treats empty functions section as missing.
+ EXPECT_FAILURE(data);
+}
+
+TEST_F(WasmModuleVerifyTest, ExportTable_NoFunctions1) {
+ static const byte data[] = {SECTION(SIGNATURES, 1), 0,
+ SECTION(EXPORT_TABLE, 1), 0};
+ EXPECT_FAILURE(data);
+}
+
+TEST_F(WasmModuleVerifyTest, ExportTable_NoFunctions2) {
+ static const byte data[] = {SECTION(EXPORT_TABLE, 1), 0};
+ EXPECT_FAILURE(data);
+}
+
+TEST_F(WasmModuleVerifyTest, ExportTableOne) {
+ static const byte data[] = {
+ SECTION(SIGNATURES, 1 + VOID_VOID_SIG_SIZE),
+ 1, // sigs
+ VOID_VOID_SIG, // --
+ SECTION(FUNCTIONS, 1 + EMPTY_FUNCTION_SIZE),
+ 1, // functions
+ EMPTY_FUNCTION(0), // --
+ SECTION(EXPORT_TABLE, 7),
+ 1, // exports
+ FUNC_INDEX(0), // --
+ NO_NAME // --
+ };
+ EXPECT_VERIFIES(data);
+}
+
+TEST_F(WasmModuleVerifyTest, ExportTableTwo) {
+ static const byte data[] = {
+ SECTION(SIGNATURES, 1 + VOID_VOID_SIG_SIZE),
+ 1, // sigs
+ VOID_VOID_SIG, // --
+ SECTION(FUNCTIONS, 1 + EMPTY_FUNCTION_SIZE),
+ 1, // functions
+ EMPTY_FUNCTION(0), // --
+ SECTION(EXPORT_TABLE, 12),
+ 2, // exports
+ FUNC_INDEX(0), // --
+ NAME_LENGTH(4),
+ 'n',
+ 'a',
+ 'm',
+ 'e', // --
+ FUNC_INDEX(0), // --
+ NAME_LENGTH(3),
+ 'n',
+ 'o',
+ 'm' // --
+ };
+ EXPECT_VERIFIES(data);
+}
+
+TEST_F(WasmModuleVerifyTest, ExportTableThree) {
+ static const byte data[] = {
+ SECTION(SIGNATURES, 1 + VOID_VOID_SIG_SIZE),
+ 1, // sigs
+ VOID_VOID_SIG, // --
+ SECTION(FUNCTIONS, 1 + 3 * EMPTY_FUNCTION_SIZE),
+ 3, // functions
+ EMPTY_FUNCTION(0), // --
+ EMPTY_FUNCTION(0), // --
+ EMPTY_FUNCTION(0), // --
+ SECTION(EXPORT_TABLE, 10),
+ 3, // exports
+ FUNC_INDEX(0), // --
+ NAME_LENGTH(1),
+ 'a', // --
+ FUNC_INDEX(1), // --
+ NAME_LENGTH(1),
+ 'b', // --
+ FUNC_INDEX(2), // --
+ NAME_LENGTH(1),
+ 'c' // --
+ };
+ EXPECT_VERIFIES(data);
+}
+
+TEST_F(WasmModuleVerifyTest, ExportTableThreeOne) {
+ for (int i = 0; i < 6; i++) {
+ const byte data[] = {
+ SECTION(SIGNATURES, 1 + VOID_VOID_SIG_SIZE),
+ 1, // sigs
+ VOID_VOID_SIG, // --
+ SECTION(FUNCTIONS, 1 + 3 * EMPTY_FUNCTION_SIZE),
+ 3, // functions
+ EMPTY_FUNCTION(0), // --
+ EMPTY_FUNCTION(0), // --
+ EMPTY_FUNCTION(0), // --
+ SECTION(EXPORT_TABLE, 5),
+ 1, // exports
+ FUNC_INDEX(i), // --
+ NAME_LENGTH(2),
+ 'e',
+ 'x', // --
+ };
+
+ if (i < 3) {
+ EXPECT_VERIFIES(data);
+ } else {
+ EXPECT_FAILURE(data);
+ }
+ }
+}
+
+TEST_F(WasmModuleVerifyTest, ExportTableOne_off_end) {
+ static const byte data[] = {
+ SECTION(SIGNATURES, 1 + VOID_VOID_SIG_SIZE),
+ 1, // sigs
+ VOID_VOID_SIG, // --
+ SECTION(FUNCTIONS, 1 + EMPTY_FUNCTION_SIZE),
+ 1, // functions
+ EMPTY_FUNCTION(0), // --
+ SECTION(EXPORT_TABLE, 1 + 6),
+ 1, // exports
+ FUNC_INDEX(0), // --
+ NO_NAME // --
+ };
+
+ for (int length = 33; length < sizeof(data); length++) {
ModuleResult result = DecodeModule(data, data + length);
EXPECT_FALSE(result.ok());
if (result.val) delete result.val;
}
}
+#define SIGNATURES_SECTION(count, ...) \
+ SECTION(SIGNATURES, 1 + 3 * (count)), U32V_1(count), __VA_ARGS__
+#define FUNCTION_SIGNATURES_SECTION(count, ...) \
+ SECTION(FUNCTION_SIGNATURES, 1 + (count)), U32V_1(count), __VA_ARGS__
+
+#define FOO_STRING 3, 'f', 'o', 'o'
+#define NO_LOCAL_NAMES 0
+
+#define EMPTY_SIGNATURES_SECTION SECTION(SIGNATURES, 1), 0
+#define EMPTY_FUNCTION_SIGNATURES_SECTION SECTION(FUNCTION_SIGNATURES, 1), 0
+#define EMPTY_FUNCTION_BODIES_SECTION SECTION(FUNCTION_BODIES, 1), 0
+#define EMPTY_NAMES_SECTION SECTION(NAMES, 1), 0
+
+TEST_F(WasmModuleVerifyTest, FunctionSignatures_empty) {
+ static const byte data[] = {SECTION(SIGNATURES, 1), 0,
+ SECTION(FUNCTION_SIGNATURES, 1), 0};
+ EXPECT_VERIFIES(data);
+}
+
+TEST_F(WasmModuleVerifyTest, FunctionSignatures_one) {
+ static const byte data[] = {SIGNATURES_SECTION(1, VOID_VOID_SIG),
+ FUNCTION_SIGNATURES_SECTION(1, 0)};
+ EXPECT_VERIFIES(data);
+}
+
+TEST_F(WasmModuleVerifyTest, FunctionBodies_empty) {
+ static const byte data[] = {EMPTY_SIGNATURES_SECTION,
+ EMPTY_FUNCTION_SIGNATURES_SECTION,
+ EMPTY_FUNCTION_BODIES_SECTION};
+ EXPECT_VERIFIES(data);
+}
+
+TEST_F(WasmModuleVerifyTest, FunctionBodies_one_empty) {
+ static const byte data[] = {
+ SIGNATURES_SECTION(1, VOID_VOID_SIG), FUNCTION_SIGNATURES_SECTION(1, 0),
+ SECTION(FUNCTION_BODIES, 1 + EMPTY_BODY_SIZE), 1, EMPTY_BODY};
+ EXPECT_VERIFIES(data);
+}
+
+TEST_F(WasmModuleVerifyTest, FunctionBodies_one_nop) {
+ static const byte data[] = {
+ SIGNATURES_SECTION(1, VOID_VOID_SIG), FUNCTION_SIGNATURES_SECTION(1, 0),
+ SECTION(FUNCTION_BODIES, 1 + NOP_BODY_SIZE), 1, NOP_BODY};
+ EXPECT_VERIFIES(data);
+}
+
+TEST_F(WasmModuleVerifyTest, FunctionBodies_count_mismatch1) {
+ static const byte data[] = {SIGNATURES_SECTION(1, VOID_VOID_SIG),
+ FUNCTION_SIGNATURES_SECTION(2, 0, 0),
+ SECTION(FUNCTION_BODIES, 1 + EMPTY_BODY_SIZE), 1,
+ EMPTY_BODY};
+ EXPECT_FAILURE(data);
+}
+
+TEST_F(WasmModuleVerifyTest, FunctionBodies_count_mismatch2) {
+ static const byte data[] = {SIGNATURES_SECTION(1, VOID_VOID_SIG),
+ FUNCTION_SIGNATURES_SECTION(1, 0),
+ SECTION(FUNCTION_BODIES, 1 + 2 * NOP_BODY_SIZE),
+ 2,
+ NOP_BODY,
+ NOP_BODY};
+ EXPECT_FAILURE(data);
+}
+
+TEST_F(WasmModuleVerifyTest, Names_empty) {
+ static const byte data[] = {
+ EMPTY_SIGNATURES_SECTION, EMPTY_FUNCTION_SIGNATURES_SECTION,
+ EMPTY_FUNCTION_BODIES_SECTION, EMPTY_NAMES_SECTION};
+ EXPECT_VERIFIES(data);
+}
+
+TEST_F(WasmModuleVerifyTest, Names_one_empty) {
+ static const byte data[] = {
+ SIGNATURES_SECTION(1, VOID_VOID_SIG), // --
+ FUNCTION_SIGNATURES_SECTION(1, 0), // --
+ SECTION(FUNCTION_BODIES, 1 + EMPTY_BODY_SIZE),
+ 1,
+ EMPTY_BODY, // --
+ SECTION(NAMES, 1 + 5),
+ 1,
+ FOO_STRING,
+ NO_LOCAL_NAMES // --
+ };
+ EXPECT_VERIFIES(data);
+}
+
+TEST_F(WasmModuleVerifyTest, Names_two_empty) {
+ static const byte data[] = {
+ SIGNATURES_SECTION(1, VOID_VOID_SIG), // --
+ FUNCTION_SIGNATURES_SECTION(2, 0, 0), // --
+ SECTION(FUNCTION_BODIES, 1 + 2 * EMPTY_BODY_SIZE), // --
+ 2,
+ EMPTY_BODY,
+ EMPTY_BODY, // --
+ SECTION(NAMES, 1 + 10),
+ 2, // --
+ FOO_STRING,
+ NO_LOCAL_NAMES, // --
+ FOO_STRING,
+ NO_LOCAL_NAMES, // --
+ };
+ EXPECT_VERIFIES(data);
+}
+
} // namespace wasm
} // namespace internal
} // namespace v8
diff --git a/test/unittests/wasm/wasm-macro-gen-unittest.cc b/test/unittests/wasm/wasm-macro-gen-unittest.cc
index f3f604b..ec188c0 100644
--- a/test/unittests/wasm/wasm-macro-gen-unittest.cc
+++ b/test/unittests/wasm/wasm-macro-gen-unittest.cc
@@ -26,14 +26,18 @@
EXPECT_SIZE(2, WASM_I8(122));
EXPECT_SIZE(2, WASM_I8(254));
- EXPECT_SIZE(5, WASM_I32(1));
- EXPECT_SIZE(5, WASM_I32(10000));
- EXPECT_SIZE(5, WASM_I32(-9828934));
+ EXPECT_SIZE(2, WASM_I32V_1(1));
+ EXPECT_SIZE(3, WASM_I32V_2(200));
+ EXPECT_SIZE(4, WASM_I32V_3(10000));
+ EXPECT_SIZE(5, WASM_I32V_4(-9828934));
+ EXPECT_SIZE(6, WASM_I32V_5(-1119828934));
- EXPECT_SIZE(9, WASM_I64(1));
- EXPECT_SIZE(9, WASM_I64(10000));
- EXPECT_SIZE(9, WASM_I64(-9828934));
- EXPECT_SIZE(9, WASM_I64(0x123456789abcdef0ULL));
+ EXPECT_SIZE(2, WASM_I64V_1(1));
+ EXPECT_SIZE(3, WASM_I64V_2(300));
+ EXPECT_SIZE(4, WASM_I64V_3(10000));
+ EXPECT_SIZE(5, WASM_I64V_4(-9828934));
+ EXPECT_SIZE(6, WASM_I64V_5(-1119828934));
+ EXPECT_SIZE(10, WASM_I64V_9(0x123456789abcdef0ULL));
EXPECT_SIZE(5, WASM_F32(1.0f));
EXPECT_SIZE(5, WASM_F32(10000.0f));
@@ -52,7 +56,7 @@
EXPECT_SIZE(4, WASM_STORE_GLOBAL(0, WASM_ZERO));
- EXPECT_SIZE(6, WASM_STORE_MEM(MachineType::Int32(), WASM_ZERO, WASM_ZERO));
+ EXPECT_SIZE(7, WASM_STORE_MEM(MachineType::Int32(), WASM_ZERO, WASM_ZERO));
EXPECT_SIZE(4, WASM_IF(WASM_ZERO, WASM_NOP));
@@ -92,17 +96,8 @@
EXPECT_SIZE(3, WASM_CONTINUE(0));
}
-
-TEST_F(WasmMacroGenTest, TableSwitch) {
- EXPECT_SIZE(2, WASM_CASE(9));
- EXPECT_SIZE(2, WASM_CASE_BR(11));
-
- EXPECT_SIZE(7, WASM_TABLESWITCH_OP(0, 1, WASM_CASE(7)));
- EXPECT_SIZE(9, WASM_TABLESWITCH_OP(0, 2, WASM_CASE(7), WASM_CASE(8)));
-
- EXPECT_SIZE(4, WASM_TABLESWITCH_BODY(WASM_I8(88), WASM_I8(77)));
- EXPECT_SIZE(
- 6, WASM_TABLESWITCH_BODY(WASM_I8(33), WASM_I8(44), WASM_GET_LOCAL(0)));
+TEST_F(WasmMacroGenTest, BrTable) {
+ EXPECT_SIZE(8, WASM_BR_TABLE(WASM_ZERO, 1, BR_TARGET(1)));
}
@@ -113,9 +108,9 @@
EXPECT_SIZE(2, WASM_LOAD_GLOBAL(0));
EXPECT_SIZE(2, WASM_LOAD_GLOBAL(1));
EXPECT_SIZE(2, WASM_LOAD_GLOBAL(12));
- EXPECT_SIZE(4, WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO));
- EXPECT_SIZE(4, WASM_LOAD_MEM(MachineType::Float64(), WASM_ZERO));
- EXPECT_SIZE(4, WASM_LOAD_MEM(MachineType::Float32(), WASM_ZERO));
+ EXPECT_SIZE(5, WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO));
+ EXPECT_SIZE(5, WASM_LOAD_MEM(MachineType::Float64(), WASM_ZERO));
+ EXPECT_SIZE(5, WASM_LOAD_MEM(MachineType::Float32(), WASM_ZERO));
EXPECT_SIZE(3, WASM_NOT(WASM_ZERO));
@@ -173,6 +168,8 @@
EXPECT_SIZE(5, WASM_I32_SHL(WASM_ZERO, WASM_ZERO));
EXPECT_SIZE(5, WASM_I32_SHR(WASM_ZERO, WASM_ZERO));
EXPECT_SIZE(5, WASM_I32_SAR(WASM_ZERO, WASM_ZERO));
+ EXPECT_SIZE(5, WASM_I32_ROR(WASM_ZERO, WASM_ZERO));
+ EXPECT_SIZE(5, WASM_I32_ROL(WASM_ZERO, WASM_ZERO));
EXPECT_SIZE(5, WASM_I32_EQ(WASM_ZERO, WASM_ZERO));
EXPECT_SIZE(5, WASM_I32_LTS(WASM_ZERO, WASM_ZERO));
@@ -188,6 +185,8 @@
EXPECT_SIZE(3, WASM_I32_CLZ(WASM_ZERO));
EXPECT_SIZE(3, WASM_I32_CTZ(WASM_ZERO));
EXPECT_SIZE(3, WASM_I32_POPCNT(WASM_ZERO));
+
+ EXPECT_SIZE(3, WASM_I32_EQZ(WASM_ZERO));
}
@@ -205,6 +204,8 @@
EXPECT_SIZE(5, WASM_I64_SHL(WASM_ZERO, WASM_ZERO));
EXPECT_SIZE(5, WASM_I64_SHR(WASM_ZERO, WASM_ZERO));
EXPECT_SIZE(5, WASM_I64_SAR(WASM_ZERO, WASM_ZERO));
+ EXPECT_SIZE(5, WASM_I64_ROR(WASM_ZERO, WASM_ZERO));
+ EXPECT_SIZE(5, WASM_I64_ROL(WASM_ZERO, WASM_ZERO));
EXPECT_SIZE(5, WASM_I64_EQ(WASM_ZERO, WASM_ZERO));
EXPECT_SIZE(5, WASM_I64_LTS(WASM_ZERO, WASM_ZERO));
@@ -220,6 +221,8 @@
EXPECT_SIZE(3, WASM_I64_CLZ(WASM_ZERO));
EXPECT_SIZE(3, WASM_I64_CTZ(WASM_ZERO));
EXPECT_SIZE(3, WASM_I64_POPCNT(WASM_ZERO));
+
+ EXPECT_SIZE(3, WASM_I64_EQZ(WASM_ZERO));
}
@@ -307,10 +310,10 @@
TEST_F(WasmMacroGenTest, LoadsAndStores) {
for (size_t i = 0; i < arraysize(kMemTypes); i++) {
- EXPECT_SIZE(4, WASM_LOAD_MEM(kMemTypes[i], WASM_ZERO));
+ EXPECT_SIZE(5, WASM_LOAD_MEM(kMemTypes[i], WASM_ZERO));
}
for (size_t i = 0; i < arraysize(kMemTypes); i++) {
- EXPECT_SIZE(6, WASM_STORE_MEM(kMemTypes[i], WASM_ZERO, WASM_GET_LOCAL(0)));
+ EXPECT_SIZE(7, WASM_STORE_MEM(kMemTypes[i], WASM_ZERO, WASM_GET_LOCAL(0)));
}
}