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 // TODO(jochen): Remove this after the setting is turned on globally. | 5 // TODO(jochen): Remove this after the setting is turned on globally. |
6 #define V8_IMMINENT_DEPRECATION_WARNINGS | 6 #define V8_IMMINENT_DEPRECATION_WARNINGS |
7 | 7 |
8 #include "src/bootstrapper.h" | 8 #include "src/bootstrapper.h" |
9 #include "src/code-stubs.h" | 9 #include "src/code-stubs.h" |
10 #include "src/compiler/common-operator.h" | 10 #include "src/compiler/common-operator.h" |
11 #include "src/compiler/graph.h" | 11 #include "src/compiler/graph.h" |
12 #include "src/compiler/js-graph.h" | 12 #include "src/compiler/js-graph.h" |
13 #include "src/compiler/js-operator.h" | 13 #include "src/compiler/js-operator.h" |
14 #include "src/compiler/linkage.h" | 14 #include "src/compiler/linkage.h" |
15 #include "src/compiler/machine-operator.h" | 15 #include "src/compiler/machine-operator.h" |
16 #include "src/compiler/pipeline.h" | 16 #include "src/compiler/pipeline.h" |
17 #include "src/parsing/parser.h" | 17 #include "src/parsing/parser.h" |
18 #include "test/cctest/compiler/function-tester.h" | 18 #include "test/cctest/compiler/function-tester.h" |
19 | 19 |
20 namespace v8 { | 20 namespace v8 { |
21 namespace internal { | 21 namespace internal { |
22 namespace compiler { | 22 namespace compiler { |
23 | 23 |
24 | 24 |
25 TEST(RunOptimizedMathFloorStub) { | 25 TEST(RunStringLengthStub) { |
26 HandleAndZoneScope scope; | |
27 Isolate* isolate = scope.main_isolate(); | |
28 | |
29 // Create code and an accompanying descriptor. | |
30 MathFloorStub stub(isolate, TurboFanIC::CALL_FROM_OPTIMIZED_CODE); | |
31 Handle<Code> code = stub.GenerateCode(); | |
32 Zone* zone = scope.main_zone(); | |
33 CompilationInfo info(&stub, isolate, zone); | |
34 CallDescriptor* descriptor = Linkage::ComputeIncoming(zone, &info); | |
35 Handle<FixedArray> tv = isolate->factory()->NewFixedArray(10); | |
36 | |
37 // Create a function to call the code using the descriptor. | |
38 Graph graph(zone); | |
39 CommonOperatorBuilder common(zone); | |
40 JSOperatorBuilder javascript(zone); | |
41 MachineOperatorBuilder machine(zone); | |
42 JSGraph js(isolate, &graph, &common, &javascript, nullptr, &machine); | |
43 | |
44 // FunctionTester (ab)uses a 2-argument function | |
45 Node* start = graph.NewNode(common.Start(4)); | |
46 // Parameter 0 is the number to round | |
47 Node* numberParam = graph.NewNode(common.Parameter(1), start); | |
48 Node* theCode = graph.NewNode(common.HeapConstant(code)); | |
49 Node* vector = graph.NewNode(common.HeapConstant(tv)); | |
50 Node* dummyContext = graph.NewNode(common.NumberConstant(0.0)); | |
51 Node* call = | |
52 graph.NewNode(common.Call(descriptor), theCode, js.UndefinedConstant(), | |
53 js.OneConstant(), vector, js.UndefinedConstant(), | |
54 numberParam, dummyContext, start, start); | |
55 Node* ret = graph.NewNode(common.Return(), call, call, start); | |
56 Node* end = graph.NewNode(common.End(1), ret); | |
57 graph.SetStart(start); | |
58 graph.SetEnd(end); | |
59 FunctionTester ft(&graph); | |
60 | |
61 Handle<Object> value = ft.Val(1.5); | |
62 Handle<Object> result = ft.Call(value, value).ToHandleChecked(); | |
63 CHECK_EQ(1, Smi::cast(*result)->value()); | |
64 } | |
65 | |
66 | |
67 TEST(RunStringLengthTFStub) { | |
68 HandleAndZoneScope scope; | 26 HandleAndZoneScope scope; |
69 Isolate* isolate = scope.main_isolate(); | 27 Isolate* isolate = scope.main_isolate(); |
70 Zone* zone = scope.main_zone(); | 28 Zone* zone = scope.main_zone(); |
71 | 29 |
72 // Create code and an accompanying descriptor. | 30 // Create code and an accompanying descriptor. |
73 StringLengthTFStub stub(isolate); | 31 StringLengthStub stub(isolate); |
74 Handle<Code> code = stub.GenerateCode(); | 32 Handle<Code> code = stub.GenerateCode(); |
75 CompilationInfo info(&stub, isolate, zone); | 33 CompilationInfo info(&stub, isolate, zone); |
76 CallDescriptor* descriptor = Linkage::ComputeIncoming(zone, &info); | 34 CallDescriptor* descriptor = Linkage::ComputeIncoming(zone, &info); |
77 | 35 |
78 // Create a function to call the code using the descriptor. | 36 // Create a function to call the code using the descriptor. |
79 Graph graph(zone); | 37 Graph graph(zone); |
80 CommonOperatorBuilder common(zone); | 38 CommonOperatorBuilder common(zone); |
81 // FunctionTester (ab)uses a 4-argument function | 39 // FunctionTester (ab)uses a 4-argument function |
82 Node* start = graph.NewNode(common.Start(6)); | 40 Node* start = graph.NewNode(common.Start(6)); |
83 // Parameter 0 is the receiver | 41 // Parameter 0 is the receiver |
84 Node* receiverParam = graph.NewNode(common.Parameter(1), start); | 42 Node* receiverParam = graph.NewNode(common.Parameter(1), start); |
85 Node* nameParam = graph.NewNode(common.Parameter(2), start); | 43 Node* nameParam = graph.NewNode(common.Parameter(2), start); |
86 Node* slotParam = graph.NewNode(common.Parameter(3), start); | 44 Node* slotParam = graph.NewNode(common.Parameter(3), start); |
87 Node* vectorParam = graph.NewNode(common.Parameter(4), start); | 45 Node* vectorParam = graph.NewNode(common.Parameter(4), start); |
88 Node* theCode = graph.NewNode(common.HeapConstant(code)); | 46 Node* theCode = graph.NewNode(common.HeapConstant(code)); |
89 Node* dummyContext = graph.NewNode(common.NumberConstant(0.0)); | 47 Node* dummyContext = graph.NewNode(common.NumberConstant(0.0)); |
90 Node* call = | 48 Node* call = |
91 graph.NewNode(common.Call(descriptor), theCode, receiverParam, nameParam, | 49 graph.NewNode(common.Call(descriptor), theCode, receiverParam, nameParam, |
92 slotParam, vectorParam, dummyContext, start, start); | 50 slotParam, vectorParam, dummyContext, start, start); |
93 Node* ret = graph.NewNode(common.Return(), call, call, start); | 51 Node* ret = graph.NewNode(common.Return(), call, call, start); |
94 Node* end = graph.NewNode(common.End(1), ret); | 52 Node* end = graph.NewNode(common.End(1), ret); |
95 graph.SetStart(start); | 53 graph.SetStart(start); |
96 graph.SetEnd(end); | 54 graph.SetEnd(end); |
97 FunctionTester ft(&graph); | 55 FunctionTester ft(&graph, 4); |
98 | 56 |
99 // Actuall call through to the stub, verifying its result. | 57 // Actuall call through to the stub, verifying its result. |
100 const char* testString = "Und das Lamm schrie HURZ!"; | 58 const char* testString = "Und das Lamm schrie HURZ!"; |
101 Handle<JSReceiver> receiverArg = | 59 Handle<JSReceiver> receiverArg = |
102 Object::ToObject(isolate, ft.Val(testString)).ToHandleChecked(); | 60 Object::ToObject(isolate, ft.Val(testString)).ToHandleChecked(); |
103 Handle<String> nameArg = ft.Val("length"); | 61 Handle<String> nameArg = ft.Val("length"); |
104 Handle<Object> slot = ft.Val(0.0); | 62 Handle<Object> slot = ft.Val(0.0); |
105 Handle<Object> vector = ft.Val(0.0); | 63 Handle<Object> vector = ft.Val(0.0); |
106 Handle<Object> result = | 64 Handle<Object> result = |
107 ft.Call(receiverArg, nameArg, slot, vector).ToHandleChecked(); | 65 ft.Call(receiverArg, nameArg, slot, vector).ToHandleChecked(); |
108 CHECK_EQ(static_cast<int>(strlen(testString)), Smi::cast(*result)->value()); | 66 CHECK_EQ(static_cast<int>(strlen(testString)), Smi::cast(*result)->value()); |
109 } | 67 } |
110 | 68 |
111 | 69 |
112 TEST(RunStringAddTFStub) { | |
113 HandleAndZoneScope scope; | |
114 Isolate* isolate = scope.main_isolate(); | |
115 Zone* zone = scope.main_zone(); | |
116 | |
117 // Create code and an accompanying descriptor. | |
118 StringAddTFStub stub(isolate, STRING_ADD_CHECK_BOTH, NOT_TENURED); | |
119 Handle<Code> code = stub.GenerateCode(); | |
120 CompilationInfo info(&stub, isolate, zone); | |
121 CallDescriptor* descriptor = Linkage::ComputeIncoming(zone, &info); | |
122 | |
123 // Create a function to call the code using the descriptor. | |
124 Graph graph(zone); | |
125 CommonOperatorBuilder common(zone); | |
126 // FunctionTester (ab)uses a 2-argument function | |
127 Node* start = graph.NewNode(common.Start(4)); | |
128 // Parameter 0 is the receiver | |
129 Node* leftParam = graph.NewNode(common.Parameter(1), start); | |
130 Node* rightParam = graph.NewNode(common.Parameter(2), start); | |
131 Node* theCode = graph.NewNode(common.HeapConstant(code)); | |
132 Node* dummyContext = graph.NewNode(common.NumberConstant(0.0)); | |
133 Node* call = graph.NewNode(common.Call(descriptor), theCode, leftParam, | |
134 rightParam, dummyContext, start, start); | |
135 Node* ret = graph.NewNode(common.Return(), call, call, start); | |
136 Node* end = graph.NewNode(common.End(1), ret); | |
137 graph.SetStart(start); | |
138 graph.SetEnd(end); | |
139 FunctionTester ft(&graph); | |
140 | |
141 // Actuall call through to the stub, verifying its result. | |
142 Handle<String> leftArg = ft.Val("links"); | |
143 Handle<String> rightArg = ft.Val("rechts"); | |
144 Handle<Object> result = ft.Call(leftArg, rightArg).ToHandleChecked(); | |
145 CHECK(String::Equals(ft.Val("linksrechts"), Handle<String>::cast(result))); | |
146 } | |
147 | |
148 } // namespace compiler | 70 } // namespace compiler |
149 } // namespace internal | 71 } // namespace internal |
150 } // namespace v8 | 72 } // namespace v8 |
OLD | NEW |