Index: test/unittests/interpreter/bytecode-array-writer-unittest.cc |
diff --git a/test/unittests/interpreter/bytecode-array-writer-unittest.cc b/test/unittests/interpreter/bytecode-array-writer-unittest.cc |
index 0bb0f9757a74fc7afc37c9d0856e516106191355..e3eb7a9a099c8a80ce4c013eae03aaae1a6fd909 100644 |
--- a/test/unittests/interpreter/bytecode-array-writer-unittest.cc |
+++ b/test/unittests/interpreter/bytecode-array-writer-unittest.cc |
@@ -28,78 +28,93 @@ |
SourcePositionTableBuilder::RECORD_SOURCE_POSITIONS) {} |
~BytecodeArrayWriterUnittest() override {} |
- void Write(Bytecode bytecode, BytecodeSourceInfo info = BytecodeSourceInfo()); |
+ void Write(BytecodeNode* node, const BytecodeSourceInfo& info); |
+ void Write(Bytecode bytecode, |
+ const BytecodeSourceInfo& info = BytecodeSourceInfo()); |
void Write(Bytecode bytecode, uint32_t operand0, |
- BytecodeSourceInfo info = BytecodeSourceInfo()); |
+ const BytecodeSourceInfo& info = BytecodeSourceInfo()); |
void Write(Bytecode bytecode, uint32_t operand0, uint32_t operand1, |
- BytecodeSourceInfo info = BytecodeSourceInfo()); |
+ |
+ const BytecodeSourceInfo& info = BytecodeSourceInfo()); |
void Write(Bytecode bytecode, uint32_t operand0, uint32_t operand1, |
- uint32_t operand2, BytecodeSourceInfo info = BytecodeSourceInfo()); |
+ uint32_t operand2, |
+ const BytecodeSourceInfo& info = BytecodeSourceInfo()); |
void Write(Bytecode bytecode, uint32_t operand0, uint32_t operand1, |
uint32_t operand2, uint32_t operand3, |
- BytecodeSourceInfo info = BytecodeSourceInfo()); |
+ const BytecodeSourceInfo& info = BytecodeSourceInfo()); |
void WriteJump(Bytecode bytecode, BytecodeLabel* label, |
- BytecodeSourceInfo info = BytecodeSourceInfo()); |
- void WriteJumpLoop(Bytecode bytecode, BytecodeLabel* label, int depth, |
- BytecodeSourceInfo info = BytecodeSourceInfo()); |
+ const BytecodeSourceInfo& info = BytecodeSourceInfo()); |
+ void WriteJumpLoop(Bytecode bytecode, BytecodeLabel* label, int depth); |
BytecodeArrayWriter* writer() { return &bytecode_array_writer_; } |
ZoneVector<unsigned char>* bytecodes() { return writer()->bytecodes(); } |
SourcePositionTableBuilder* source_position_table_builder() { |
return writer()->source_position_table_builder(); |
} |
+ int max_register_count() { return writer()->max_register_count(); } |
private: |
ConstantArrayBuilder constant_array_builder_; |
BytecodeArrayWriter bytecode_array_writer_; |
}; |
+void BytecodeArrayWriterUnittest::Write(BytecodeNode* node, |
+ const BytecodeSourceInfo& info) { |
+ if (info.is_valid()) { |
+ node->source_info().Clone(info); |
+ } |
+ writer()->Write(node); |
+} |
+ |
void BytecodeArrayWriterUnittest::Write(Bytecode bytecode, |
- BytecodeSourceInfo info) { |
- BytecodeNode node(bytecode, &info); |
- writer()->Write(&node); |
-} |
- |
-void BytecodeArrayWriterUnittest::Write(Bytecode bytecode, uint32_t operand0, |
- BytecodeSourceInfo info) { |
- BytecodeNode node(bytecode, operand0, &info); |
- writer()->Write(&node); |
+ const BytecodeSourceInfo& info) { |
+ BytecodeNode node(bytecode); |
+ Write(&node, info); |
+} |
+ |
+void BytecodeArrayWriterUnittest::Write(Bytecode bytecode, uint32_t operand0, |
+ const BytecodeSourceInfo& info) { |
+ BytecodeNode node(bytecode, operand0); |
+ Write(&node, info); |
} |
void BytecodeArrayWriterUnittest::Write(Bytecode bytecode, uint32_t operand0, |
uint32_t operand1, |
- BytecodeSourceInfo info) { |
- BytecodeNode node(bytecode, operand0, operand1, &info); |
- writer()->Write(&node); |
+ const BytecodeSourceInfo& info) { |
+ BytecodeNode node(bytecode, operand0, operand1); |
+ Write(&node, info); |
} |
void BytecodeArrayWriterUnittest::Write(Bytecode bytecode, uint32_t operand0, |
uint32_t operand1, uint32_t operand2, |
- BytecodeSourceInfo info) { |
- BytecodeNode node(bytecode, operand0, operand1, operand2, &info); |
- writer()->Write(&node); |
+ const BytecodeSourceInfo& info) { |
+ BytecodeNode node(bytecode, operand0, operand1, operand2); |
+ Write(&node, info); |
} |
void BytecodeArrayWriterUnittest::Write(Bytecode bytecode, uint32_t operand0, |
uint32_t operand1, uint32_t operand2, |
uint32_t operand3, |
- BytecodeSourceInfo info) { |
- BytecodeNode node(bytecode, operand0, operand1, operand2, operand3, &info); |
- writer()->Write(&node); |
+ const BytecodeSourceInfo& info) { |
+ BytecodeNode node(bytecode, operand0, operand1, operand2, operand3); |
+ Write(&node, info); |
} |
void BytecodeArrayWriterUnittest::WriteJump(Bytecode bytecode, |
BytecodeLabel* label, |
- BytecodeSourceInfo info) { |
- BytecodeNode node(bytecode, 0, &info); |
+ const BytecodeSourceInfo& info) { |
+ BytecodeNode node(bytecode, 0); |
+ if (info.is_valid()) { |
+ node.source_info().Clone(info); |
+ } |
writer()->WriteJump(&node, label); |
} |
void BytecodeArrayWriterUnittest::WriteJumpLoop(Bytecode bytecode, |
- BytecodeLabel* label, int depth, |
- BytecodeSourceInfo info) { |
- BytecodeNode node(bytecode, 0, depth, &info); |
+ BytecodeLabel* label, |
+ int depth) { |
+ BytecodeNode node(bytecode, 0, depth); |
writer()->WriteJump(&node, label); |
} |
@@ -108,15 +123,19 @@ |
Write(Bytecode::kStackCheck, {10, false}); |
CHECK_EQ(bytecodes()->size(), 1); |
+ CHECK_EQ(max_register_count(), 0); |
Write(Bytecode::kLdaSmi, 127, {55, true}); |
CHECK_EQ(bytecodes()->size(), 3); |
+ CHECK_EQ(max_register_count(), 0); |
Write(Bytecode::kLdar, Register(200).ToOperand()); |
CHECK_EQ(bytecodes()->size(), 7); |
+ CHECK_EQ(max_register_count(), 201); |
Write(Bytecode::kReturn, {70, true}); |
CHECK_EQ(bytecodes()->size(), 8); |
+ CHECK_EQ(max_register_count(), 201); |
static const uint8_t bytes[] = {B(StackCheck), B(LdaSmi), U8(127), B(Wide), |
B(Ldar), R16(200), B(Return)}; |
@@ -148,7 +167,7 @@ |
// clang-format off |
/* 0 30 E> */ B(StackCheck), |
/* 1 42 S> */ B(LdaConstant), U8(0), |
- /* 3 42 E> */ B(Add), R8(1), U8(1), |
+ /* 3 42 E> */ B(Star), R8(1), |
/* 5 68 S> */ B(JumpIfUndefined), U8(39), |
/* 7 */ B(JumpIfNull), U8(37), |
/* 9 */ B(ToObject), R8(3), |
@@ -173,23 +192,30 @@ |
}; |
static const PositionTableEntry expected_positions[] = { |
- {0, 30, false}, {1, 42, true}, {3, 42, false}, {6, 68, true}, |
- {18, 63, true}, {32, 54, false}, {37, 85, true}, {46, 85, true}}; |
+ {0, 30, false}, {1, 42, true}, {3, 42, false}, {5, 68, true}, |
+ {17, 63, true}, {31, 54, false}, {36, 85, true}, {45, 85, true}}; |
BytecodeLabel back_jump, jump_for_in, jump_end_1, jump_end_2, jump_end_3; |
#define R(i) static_cast<uint32_t>(Register(i).ToOperand()) |
Write(Bytecode::kStackCheck, {30, false}); |
Write(Bytecode::kLdaConstant, U8(0), {42, true}); |
- Write(Bytecode::kAdd, R(1), U8(1), {42, false}); |
+ CHECK_EQ(max_register_count(), 0); |
+ Write(Bytecode::kStar, R(1), {42, false}); |
+ CHECK_EQ(max_register_count(), 2); |
WriteJump(Bytecode::kJumpIfUndefined, &jump_end_1, {68, true}); |
WriteJump(Bytecode::kJumpIfNull, &jump_end_2); |
Write(Bytecode::kToObject, R(3)); |
+ CHECK_EQ(max_register_count(), 4); |
Write(Bytecode::kForInPrepare, R(3), R(4)); |
+ CHECK_EQ(max_register_count(), 7); |
Write(Bytecode::kLdaZero); |
+ CHECK_EQ(max_register_count(), 7); |
Write(Bytecode::kStar, R(7)); |
+ CHECK_EQ(max_register_count(), 8); |
writer()->BindLabel(&back_jump); |
Write(Bytecode::kForInContinue, R(7), R(6), {63, true}); |
+ CHECK_EQ(max_register_count(), 8); |
WriteJump(Bytecode::kJumpIfFalse, &jump_end_3); |
Write(Bytecode::kForInNext, R(3), R(7), R(4), U8(1)); |
WriteJump(Bytecode::kJumpIfUndefined, &jump_for_in); |
@@ -207,6 +233,7 @@ |
writer()->BindLabel(&jump_end_3); |
Write(Bytecode::kLdaUndefined); |
Write(Bytecode::kReturn, {85, true}); |
+ CHECK_EQ(max_register_count(), 8); |
#undef R |
CHECK_EQ(bytecodes()->size(), arraysize(expected_bytes)); |