Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(405)

Unified Diff: test/unittests/interpreter/bytecode-writer-unittest.cc

Issue 1947403002: [interpreter] Introduce bytecode generation pipeline. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Attempt to fix compilation with gcc/msvc and introduce nop to simplify source positions in peephole… Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: test/unittests/interpreter/bytecode-writer-unittest.cc
diff --git a/test/unittests/interpreter/bytecode-writer-unittest.cc b/test/unittests/interpreter/bytecode-writer-unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8b8a19765853d96132bc60294bac12b5b0549d93
--- /dev/null
+++ b/test/unittests/interpreter/bytecode-writer-unittest.cc
@@ -0,0 +1,116 @@
+// 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/bytecode-register-allocator.h"
+#include "src/interpreter/bytecode-writer.h"
+#include "src/isolate.h"
+#include "test/unittests/test-utils.h"
+
+namespace v8 {
+namespace internal {
+namespace interpreter {
+
+using BytecodeNodeTest = TestWithIsolateAndZone;
+
+TEST(BytecodeSourceInfo, Operations) {
+ BytecodeSourceInfo x(0, true);
+ CHECK_EQ(x.source_position(), 0);
+ CHECK_EQ(x.is_statement(), true);
+ CHECK_EQ(x.is_valid(), true);
+ x.set_invalid();
+ CHECK_EQ(x.is_statement(), false);
+ CHECK_EQ(x.is_valid(), false);
+
+ x.Update({1, true});
+ BytecodeSourceInfo y(1, true);
+ CHECK(x == y);
+ CHECK(!(x != y));
+
+ x.set_invalid();
+ CHECK(!(x == y));
+ CHECK(x != y);
+
+ y.Update({2, false});
+ CHECK_EQ(y.source_position(), 1);
+ CHECK_EQ(y.is_statement(), true);
+
+ y.Update({2, true});
+ CHECK_EQ(y.source_position(), 2);
+ CHECK_EQ(y.is_statement(), true);
+
+ y.set_invalid();
+ y.Update({3, false});
+ CHECK_EQ(y.source_position(), 3);
+ CHECK_EQ(y.is_statement(), false);
+
+ y.Update({3, true});
+ CHECK_EQ(y.source_position(), 3);
+ CHECK_EQ(y.is_statement(), true);
+}
+
+TEST_F(BytecodeNodeTest, Allocation) {
+ BytecodeNodeAllocator node_allocator(zone());
+ BytecodeNode* node = node_allocator.Allocate();
+ CHECK_EQ(node->bytecode(), Bytecode::kIllegal);
+ CHECK(!node->source_info().is_valid());
+ node->set_bytecode(Bytecode::kStackCheck);
+ CHECK_EQ(node->bytecode(), Bytecode::kStackCheck);
+ CHECK_EQ(node->operand_count(), 0);
+ CHECK_EQ(node->operand_scale(), OperandScale::kSingle);
+ CHECK_EQ(node->Size(), 1);
+
+ node->source_info().Update({0, false});
+ CHECK(node->source_info().is_valid());
+ node->Release();
+
+ // Check node is recylced and recycled is invalid.
+ BytecodeNode* other_node = node_allocator.Allocate();
+ CHECK_EQ(other_node, node);
+ CHECK_EQ(other_node->bytecode(), Bytecode::kIllegal);
+ CHECK(!other_node->source_info().is_valid());
+ other_node->Release();
+}
+
+TEST_F(BytecodeNodeTest, BytecodeNodeProperties) {
+ BytecodeNodeAllocator node_allocator(zone());
+ BytecodeNode* node = node_allocator.Allocate();
+ Register first(0), second(1);
+ node->set_bytecode(Bytecode::kForInDone, first.ToOperand(),
+ second.ToOperand(), OperandScale::kSingle);
+ CHECK_EQ(node->Size(), 3);
+ node->set_bytecode(Bytecode::kForInDone, first.ToOperand(),
+ second.ToOperand(), OperandScale::kDouble);
+ CHECK_EQ(node->Size(), 6);
+ node->set_bytecode(Bytecode::kForInDone, first.ToOperand(),
+ second.ToOperand(), OperandScale::kQuadruple);
+ CHECK_EQ(node->Size(), 10);
+ node->set_bytecode(Bytecode::kForInDone, first.ToOperand(),
+ second.ToOperand(), OperandScale::kQuadruple);
+ CHECK_EQ(node->Size(), 10);
+ node->set_bytecode(Bytecode::kCall, first.ToOperand(), second.ToOperand(), 2,
+ 3, OperandScale::kDouble);
+ CHECK_EQ(node->Size(), 10);
+ CHECK_EQ(node->operands()[0], first.ToOperand());
+ CHECK_EQ(node->operands()[1], second.ToOperand());
+ CHECK_EQ(node->operands()[2], 2);
+ CHECK_EQ(node->operands()[3], 3);
+ CHECK(!node->source_info().is_valid());
+ node->source_info().Update({77, true});
+ CHECK(node->source_info().is_valid());
+ CHECK_EQ(node->source_info().source_position(), 77);
+ CHECK_EQ(node->source_info().is_statement(), true);
+ node->Release();
+}
+
+// TODO(oth): FinalStageBytecodeWriterTest.
+//
+// - Measured frame size is correct.
+// - BytecodeArraySize.
+// - SourcePositionTable iterates as expected.
+
+} // namespace interpreter
+} // namespace internal
+} // namespace v8

Powered by Google App Engine
This is Rietveld 408576698