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

Side by Side 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: Fix return type of BytecodeSourceInfo::is_statement() 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "src/v8.h"
6
7 #include "src/interpreter/bytecode-register-allocator.h"
8 #include "src/interpreter/bytecode-writer.h"
9 #include "src/isolate.h"
10 #include "test/unittests/test-utils.h"
11
12 namespace v8 {
13 namespace internal {
14 namespace interpreter {
15
16 using BytecodeNodeTest = TestWithIsolateAndZone;
17
18 TEST(BytecodeSourceInfo, Operations) {
19 BytecodeSourceInfo x(0, true);
20 CHECK_EQ(x.source_position(), 0);
21 CHECK_EQ(x.is_statement(), true);
22 CHECK_EQ(x.is_valid(), true);
23 x.set_invalid();
24 CHECK_EQ(x.is_statement(), false);
25 CHECK_EQ(x.is_valid(), false);
26
27 x.Update({1, true});
28 BytecodeSourceInfo y(1, true);
29 CHECK(x == y);
30 CHECK(!(x != y));
31
32 x.set_invalid();
33 CHECK(!(x == y));
34 CHECK(x != y);
35
36 y.Update({2, false});
37 CHECK_EQ(y.source_position(), 1);
38 CHECK_EQ(y.is_statement(), true);
39
40 y.Update({2, true});
41 CHECK_EQ(y.source_position(), 2);
42 CHECK_EQ(y.is_statement(), true);
43
44 y.set_invalid();
45 y.Update({3, false});
46 CHECK_EQ(y.source_position(), 3);
47 CHECK_EQ(y.is_statement(), false);
48
49 y.Update({3, true});
50 CHECK_EQ(y.source_position(), 3);
51 CHECK_EQ(y.is_statement(), true);
52 }
53
54 TEST_F(BytecodeNodeTest, Allocation) {
55 BytecodeNodeAllocator node_allocator(zone());
56 BytecodeNode* node = node_allocator.Allocate();
57 CHECK_EQ(node->bytecode(), Bytecode::kIllegal);
58 CHECK(!node->source_info().is_valid());
59 node->set_bytecode(Bytecode::kStackCheck);
60 CHECK_EQ(node->bytecode(), Bytecode::kStackCheck);
61 CHECK_EQ(node->operand_count(), 0);
62 CHECK_EQ(node->operand_scale(), OperandScale::kSingle);
63 CHECK_EQ(node->Size(), 1);
64
65 node->source_info().Update({0, false});
66 CHECK(node->source_info().is_valid());
67 node->Release();
68
69 // Check node is recylced and recycled is invalid.
70 BytecodeNode* other_node = node_allocator.Allocate();
71 CHECK_EQ(other_node, node);
72 CHECK_EQ(other_node->bytecode(), Bytecode::kIllegal);
73 CHECK(!other_node->source_info().is_valid());
74 other_node->Release();
75 }
76
77 TEST_F(BytecodeNodeTest, BytecodeNodeProperties) {
78 BytecodeNodeAllocator node_allocator(zone());
79 BytecodeNode* node = node_allocator.Allocate();
80 Register first(0), second(1);
81 node->set_bytecode(Bytecode::kForInDone, first.ToOperand(),
82 second.ToOperand(), OperandScale::kSingle);
83 CHECK_EQ(node->Size(), 3);
84 node->set_bytecode(Bytecode::kForInDone, first.ToOperand(),
85 second.ToOperand(), OperandScale::kDouble);
86 CHECK_EQ(node->Size(), 6);
87 node->set_bytecode(Bytecode::kForInDone, first.ToOperand(),
88 second.ToOperand(), OperandScale::kQuadruple);
89 CHECK_EQ(node->Size(), 10);
90 node->set_bytecode(Bytecode::kForInDone, first.ToOperand(),
91 second.ToOperand(), OperandScale::kQuadruple);
92 CHECK_EQ(node->Size(), 10);
93 node->set_bytecode(Bytecode::kCall, first.ToOperand(), second.ToOperand(), 2,
94 3, OperandScale::kDouble);
95 CHECK_EQ(node->Size(), 10);
96 CHECK_EQ(node->operands()[0], first.ToOperand());
97 CHECK_EQ(node->operands()[1], second.ToOperand());
98 CHECK_EQ(node->operands()[2], 2);
99 CHECK_EQ(node->operands()[3], 3);
100 CHECK(!node->source_info().is_valid());
101 node->source_info().Update({77, true});
102 CHECK(node->source_info().is_valid());
103 CHECK_EQ(node->source_info().source_position(), 77);
104 CHECK_EQ(node->source_info().is_statement(), true);
105 node->Release();
106 }
107
108 // TODO(oth): FinalStageBytecodeWriterTest.
109 //
110 // - Measured frame size is correct.
111 // - BytecodeArraySize.
112 // - SourcePositionTable iterates as expected.
113
114 } // namespace interpreter
115 } // namespace internal
116 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698