OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <iostream> | 5 #include <iostream> |
6 | 6 |
7 #include "src/compiler/bytecode-graph-builder.h" | 7 #include "src/compiler/bytecode-graph-builder.h" |
8 #include "src/compiler/common-operator.h" | 8 #include "src/compiler/common-operator.h" |
9 #include "src/compiler/graph-visualizer.h" | 9 #include "src/compiler/graph-visualizer.h" |
10 #include "src/compiler/instruction.h" | 10 #include "src/compiler/instruction.h" |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 Node* control = graph->start(); | 200 Node* control = graph->start(); |
201 EXPECT_THAT(ret, IsReturn(IsNumberConstant(kValue), effect, control)); | 201 EXPECT_THAT(ret, IsReturn(IsNumberConstant(kValue), effect, control)); |
202 } | 202 } |
203 | 203 |
204 | 204 |
205 TEST_F(BytecodeGraphBuilderTest, SimpleExpressionWithParameters) { | 205 TEST_F(BytecodeGraphBuilderTest, SimpleExpressionWithParameters) { |
206 array_builder()->set_locals_count(1); | 206 array_builder()->set_locals_count(1); |
207 array_builder()->set_parameter_count(3); | 207 array_builder()->set_parameter_count(3); |
208 array_builder() | 208 array_builder() |
209 ->LoadAccumulatorWithRegister(array_builder()->Parameter(1)) | 209 ->LoadAccumulatorWithRegister(array_builder()->Parameter(1)) |
210 .BinaryOperation(Token::Value::ADD, array_builder()->Parameter(2)) | 210 .BinaryOperation(Token::Value::ADD, array_builder()->Parameter(2), |
| 211 Strength::WEAK) |
211 .StoreAccumulatorInRegister(interpreter::Register(0)) | 212 .StoreAccumulatorInRegister(interpreter::Register(0)) |
212 .Return(); | 213 .Return(); |
213 | 214 |
214 Graph* graph = GetCompletedGraph(); | 215 Graph* graph = GetCompletedGraph(); |
215 Node* end = graph->end(); | 216 Node* end = graph->end(); |
216 EXPECT_EQ(1, end->InputCount()); | 217 EXPECT_EQ(1, end->InputCount()); |
217 Node* ret = end->InputAt(0); | 218 Node* ret = end->InputAt(0); |
218 // NB binary operation is <reg> <op> <acc>. The register represents | 219 // NB binary operation is <reg> <op> <acc>. The register represents |
219 // the left-hand side, which is why parameters appear in opposite | 220 // the left-hand side, which is why parameters appear in opposite |
220 // order to construction via the builder. | 221 // order to construction via the builder. |
221 EXPECT_THAT(ret, IsReturn(IsJSAdd(IsParameter(2), IsParameter(1)), _, _)); | 222 EXPECT_THAT(ret, IsReturn(IsJSAdd(IsParameter(2), IsParameter(1)), _, _)); |
222 } | 223 } |
223 | 224 |
224 | 225 |
225 TEST_F(BytecodeGraphBuilderTest, SimpleExpressionWithRegister) { | 226 TEST_F(BytecodeGraphBuilderTest, SimpleExpressionWithRegister) { |
226 static const int kLeft = -655371; | 227 static const int kLeft = -655371; |
227 static const int kRight = +2000000; | 228 static const int kRight = +2000000; |
228 array_builder()->set_locals_count(1); | 229 array_builder()->set_locals_count(1); |
229 array_builder()->set_parameter_count(1); | 230 array_builder()->set_parameter_count(1); |
230 array_builder() | 231 array_builder() |
231 ->LoadLiteral(Smi::FromInt(kLeft)) | 232 ->LoadLiteral(Smi::FromInt(kLeft)) |
232 .StoreAccumulatorInRegister(interpreter::Register(0)) | 233 .StoreAccumulatorInRegister(interpreter::Register(0)) |
233 .LoadLiteral(Smi::FromInt(kRight)) | 234 .LoadLiteral(Smi::FromInt(kRight)) |
234 .BinaryOperation(Token::Value::ADD, interpreter::Register(0)) | 235 .BinaryOperation(Token::Value::ADD, interpreter::Register(0), |
| 236 Strength::WEAK) |
235 .Return(); | 237 .Return(); |
236 | 238 |
237 Graph* graph = GetCompletedGraph(); | 239 Graph* graph = GetCompletedGraph(); |
238 Node* end = graph->end(); | 240 Node* end = graph->end(); |
239 EXPECT_EQ(1, end->InputCount()); | 241 EXPECT_EQ(1, end->InputCount()); |
240 Node* ret = end->InputAt(0); | 242 Node* ret = end->InputAt(0); |
241 EXPECT_THAT( | 243 EXPECT_THAT( |
242 ret, IsReturn(IsJSAdd(IsNumberConstant(kLeft), IsNumberConstant(kRight)), | 244 ret, IsReturn(IsJSAdd(IsNumberConstant(kLeft), IsNumberConstant(kRight)), |
243 _, _)); | 245 _, _)); |
244 } | 246 } |
245 | 247 |
246 } // namespace compiler | 248 } // namespace compiler |
247 } // namespace internal | 249 } // namespace internal |
248 } // namespace v8 | 250 } // namespace v8 |
OLD | NEW |