OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 <sstream> |
| 6 |
5 #include "src/v8.h" | 7 #include "src/v8.h" |
6 | 8 |
7 #include "src/compiler/operator.h" | 9 #include "src/compiler/operator.h" |
8 #include "test/cctest/cctest.h" | 10 #include "test/cctest/cctest.h" |
9 | 11 |
10 using namespace v8::internal; | 12 using namespace v8::internal; |
11 using namespace v8::internal::compiler; | 13 using namespace v8::internal::compiler; |
12 | 14 |
13 #define NaN (v8::base::OS::nan_value()) | 15 #define NaN (v8::base::OS::nan_value()) |
14 #define Infinity (std::numeric_limits<double>::infinity()) | |
15 | 16 |
16 TEST(TestOperatorMnemonic) { | 17 TEST(TestOperatorMnemonic) { |
17 SimpleOperator op1(10, Operator::kNoProperties, 0, 0, "ThisOne"); | 18 SimpleOperator op1(10, Operator::kNoProperties, 0, 0, "ThisOne"); |
18 CHECK_EQ(0, strcmp(op1.mnemonic(), "ThisOne")); | 19 CHECK_EQ(0, strcmp(op1.mnemonic(), "ThisOne")); |
19 | 20 |
20 SimpleOperator op2(11, Operator::kNoProperties, 0, 0, "ThatOne"); | 21 SimpleOperator op2(11, Operator::kNoProperties, 0, 0, "ThatOne"); |
21 CHECK_EQ(0, strcmp(op2.mnemonic(), "ThatOne")); | 22 CHECK_EQ(0, strcmp(op2.mnemonic(), "ThatOne")); |
22 | 23 |
23 Operator1<int> op3(12, Operator::kNoProperties, 0, 1, "Mnemonic1", 12333); | 24 Operator1<int> op3(12, Operator::kNoProperties, 0, 1, "Mnemonic1", 12333); |
24 CHECK_EQ(0, strcmp(op3.mnemonic(), "Mnemonic1")); | 25 CHECK_EQ(0, strcmp(op3.mnemonic(), "Mnemonic1")); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 CHECK(!op1b.Equals(&op2b)); | 61 CHECK(!op1b.Equals(&op2b)); |
61 | 62 |
62 CHECK(!op2a.Equals(&op1a)); | 63 CHECK(!op2a.Equals(&op1a)); |
63 CHECK(!op2a.Equals(&op1b)); | 64 CHECK(!op2a.Equals(&op1b)); |
64 CHECK(!op2b.Equals(&op1a)); | 65 CHECK(!op2b.Equals(&op1a)); |
65 CHECK(!op2b.Equals(&op1b)); | 66 CHECK(!op2b.Equals(&op1b)); |
66 } | 67 } |
67 | 68 |
68 | 69 |
69 static SmartArrayPointer<const char> OperatorToString(Operator* op) { | 70 static SmartArrayPointer<const char> OperatorToString(Operator* op) { |
70 OStringStream os; | 71 std::ostringstream os; |
71 os << *op; | 72 os << *op; |
72 return SmartArrayPointer<const char>(StrDup(os.c_str())); | 73 return SmartArrayPointer<const char>(StrDup(os.str().c_str())); |
73 } | 74 } |
74 | 75 |
75 | 76 |
76 TEST(TestSimpleOperatorPrint) { | 77 TEST(TestSimpleOperatorPrint) { |
77 SimpleOperator op1a(19, Operator::kNoProperties, 0, 0, "Another1"); | 78 SimpleOperator op1a(19, Operator::kNoProperties, 0, 0, "Another1"); |
78 SimpleOperator op1b(19, Operator::kFoldable, 2, 2, "Another2"); | 79 SimpleOperator op1b(19, Operator::kFoldable, 2, 2, "Another2"); |
79 | 80 |
80 CHECK_EQ("Another1", OperatorToString(&op1a).get()); | 81 CHECK_EQ("Another1", OperatorToString(&op1a).get()); |
81 CHECK_EQ("Another2", OperatorToString(&op1b).get()); | 82 CHECK_EQ("Another2", OperatorToString(&op1b).get()); |
82 | 83 |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 TEST(TestOperator1doublePrint) { | 230 TEST(TestOperator1doublePrint) { |
230 Operator1<double> op1(12, Operator::kNoProperties, 0, 1, "Op1Test", 0); | 231 Operator1<double> op1(12, Operator::kNoProperties, 0, 1, "Op1Test", 0); |
231 CHECK_EQ("Op1Test[0]", OperatorToString(&op1).get()); | 232 CHECK_EQ("Op1Test[0]", OperatorToString(&op1).get()); |
232 | 233 |
233 Operator1<double> op2(12, Operator::kNoProperties, 0, 1, "Op1Test", 7.3); | 234 Operator1<double> op2(12, Operator::kNoProperties, 0, 1, "Op1Test", 7.3); |
234 CHECK_EQ("Op1Test[7.3]", OperatorToString(&op2).get()); | 235 CHECK_EQ("Op1Test[7.3]", OperatorToString(&op2).get()); |
235 | 236 |
236 Operator1<double> op3(12, Operator::kNoProperties, 0, 1, "FooBar", 2e+123); | 237 Operator1<double> op3(12, Operator::kNoProperties, 0, 1, "FooBar", 2e+123); |
237 CHECK_EQ("FooBar[2e+123]", OperatorToString(&op3).get()); | 238 CHECK_EQ("FooBar[2e+123]", OperatorToString(&op3).get()); |
238 | 239 |
239 Operator1<double> op4(12, Operator::kNoProperties, 0, 1, "BarFoo", Infinity); | |
240 CHECK_EQ("BarFoo[inf]", OperatorToString(&op4).get()); | |
241 | |
242 Operator1<double> op5(12, Operator::kNoProperties, 0, 1, "BarFoo", NaN); | 240 Operator1<double> op5(12, Operator::kNoProperties, 0, 1, "BarFoo", NaN); |
243 CHECK_EQ("BarFoo[nan]", OperatorToString(&op5).get()); | 241 CHECK_EQ("BarFoo[nan]", OperatorToString(&op5).get()); |
244 } | 242 } |
OLD | NEW |