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 "src/compiler/code-assembler.h" | 5 #include "src/compiler/code-assembler.h" |
6 #include "src/isolate.h" | 6 #include "src/isolate.h" |
7 #include "test/cctest/compiler/code-assembler-tester.h" | 7 #include "test/cctest/compiler/code-assembler-tester.h" |
8 #include "test/cctest/compiler/function-tester.h" | 8 #include "test/cctest/compiler/function-tester.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 CHECK_EQ(0, Handle<Smi>::cast(result.ToHandleChecked())->value()); | 96 CHECK_EQ(0, Handle<Smi>::cast(result.ToHandleChecked())->value()); |
97 } | 97 } |
98 | 98 |
99 TEST(SimpleCallRuntime2Arg) { | 99 TEST(SimpleCallRuntime2Arg) { |
100 Isolate* isolate(CcTest::InitIsolateOnce()); | 100 Isolate* isolate(CcTest::InitIsolateOnce()); |
101 VoidDescriptor descriptor(isolate); | 101 VoidDescriptor descriptor(isolate); |
102 CodeAssemblerTester m(isolate, descriptor); | 102 CodeAssemblerTester m(isolate, descriptor); |
103 Node* context = m.HeapConstant(Handle<Context>(isolate->native_context())); | 103 Node* context = m.HeapConstant(Handle<Context>(isolate->native_context())); |
104 Node* a = SmiTag(m, m.Int32Constant(2)); | 104 Node* a = SmiTag(m, m.Int32Constant(2)); |
105 Node* b = SmiTag(m, m.Int32Constant(4)); | 105 Node* b = SmiTag(m, m.Int32Constant(4)); |
106 m.Return(m.CallRuntime(Runtime::kMathPow, context, a, b)); | 106 m.Return(m.CallRuntime(Runtime::kAdd, context, a, b)); |
107 Handle<Code> code = m.GenerateCode(); | 107 Handle<Code> code = m.GenerateCode(); |
108 FunctionTester ft(descriptor, code); | 108 FunctionTester ft(descriptor, code); |
109 MaybeHandle<Object> result = ft.Call(); | 109 MaybeHandle<Object> result = ft.Call(); |
110 CHECK_EQ(16, Handle<Smi>::cast(result.ToHandleChecked())->value()); | 110 CHECK_EQ(6, Handle<Smi>::cast(result.ToHandleChecked())->value()); |
111 } | 111 } |
112 | 112 |
113 TEST(SimpleTailCallRuntime2Arg) { | 113 TEST(SimpleTailCallRuntime2Arg) { |
114 Isolate* isolate(CcTest::InitIsolateOnce()); | 114 Isolate* isolate(CcTest::InitIsolateOnce()); |
115 VoidDescriptor descriptor(isolate); | 115 VoidDescriptor descriptor(isolate); |
116 CodeAssemblerTester m(isolate, descriptor); | 116 CodeAssemblerTester m(isolate, descriptor); |
117 Node* context = m.HeapConstant(Handle<Context>(isolate->native_context())); | 117 Node* context = m.HeapConstant(Handle<Context>(isolate->native_context())); |
118 Node* a = SmiTag(m, m.Int32Constant(2)); | 118 Node* a = SmiTag(m, m.Int32Constant(2)); |
119 Node* b = SmiTag(m, m.Int32Constant(4)); | 119 Node* b = SmiTag(m, m.Int32Constant(4)); |
120 m.TailCallRuntime(Runtime::kMathPow, context, a, b); | 120 m.TailCallRuntime(Runtime::kAdd, context, a, b); |
121 Handle<Code> code = m.GenerateCode(); | 121 Handle<Code> code = m.GenerateCode(); |
122 FunctionTester ft(descriptor, code); | 122 FunctionTester ft(descriptor, code); |
123 MaybeHandle<Object> result = ft.Call(); | 123 MaybeHandle<Object> result = ft.Call(); |
124 CHECK_EQ(16, Handle<Smi>::cast(result.ToHandleChecked())->value()); | 124 CHECK_EQ(6, Handle<Smi>::cast(result.ToHandleChecked())->value()); |
125 } | 125 } |
126 | 126 |
127 namespace { | 127 namespace { |
128 | 128 |
129 Handle<JSFunction> CreateSumAllArgumentsFunction(FunctionTester& ft) { | 129 Handle<JSFunction> CreateSumAllArgumentsFunction(FunctionTester& ft) { |
130 const char* source = | 130 const char* source = |
131 "(function() {\n" | 131 "(function() {\n" |
132 " var sum = 0 + this;\n" | 132 " var sum = 0 + this;\n" |
133 " for (var i = 0; i < arguments.length; i++) {\n" | 133 " for (var i = 0; i < arguments.length; i++) {\n" |
134 " sum += arguments[i];\n" | 134 " sum += arguments[i];\n" |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 var_object.Bind(m.IntPtrConstant(66)); | 429 var_object.Bind(m.IntPtrConstant(66)); |
430 m.Goto(&block1); | 430 m.Goto(&block1); |
431 } | 431 } |
432 m.Bind(&block1); | 432 m.Bind(&block1); |
433 CHECK(!m.GenerateCode().is_null()); | 433 CHECK(!m.GenerateCode().is_null()); |
434 } | 434 } |
435 | 435 |
436 } // namespace compiler | 436 } // namespace compiler |
437 } // namespace internal | 437 } // namespace internal |
438 } // namespace v8 | 438 } // namespace v8 |
OLD | NEW |