Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: test/cctest/compiler/function-tester.h

Issue 1475953002: [stubs] A new approach to TF stubs (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix Win64 build Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/cctest/cctest.gyp ('k') | test/cctest/compiler/test-code-stub-assembler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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 #ifndef V8_CCTEST_COMPILER_FUNCTION_TESTER_H_ 5 #ifndef V8_CCTEST_COMPILER_FUNCTION_TESTER_H_
6 #define V8_CCTEST_COMPILER_FUNCTION_TESTER_H_ 6 #define V8_CCTEST_COMPILER_FUNCTION_TESTER_H_
7 7
8 #include "src/ast/ast-numbering.h" 8 #include "src/ast/ast-numbering.h"
9 #include "src/ast/scopes.h" 9 #include "src/ast/scopes.h"
10 #include "src/compiler.h" 10 #include "src/compiler.h"
(...skipping 17 matching lines...) Expand all
28 : isolate(main_isolate()), 28 : isolate(main_isolate()),
29 function((FLAG_allow_natives_syntax = true, NewFunction(source))), 29 function((FLAG_allow_natives_syntax = true, NewFunction(source))),
30 flags_(flags) { 30 flags_(flags) {
31 Compile(function); 31 Compile(function);
32 const uint32_t supported_flags = 32 const uint32_t supported_flags =
33 CompilationInfo::kFunctionContextSpecializing | 33 CompilationInfo::kFunctionContextSpecializing |
34 CompilationInfo::kInliningEnabled | CompilationInfo::kTypingEnabled; 34 CompilationInfo::kInliningEnabled | CompilationInfo::kTypingEnabled;
35 CHECK_EQ(0u, flags_ & ~supported_flags); 35 CHECK_EQ(0u, flags_ & ~supported_flags);
36 } 36 }
37 37
38 // TODO(turbofan): generalize FunctionTester to work with N arguments. Now, it 38 FunctionTester(Graph* graph, int param_count)
39 // can handle up to four.
40 explicit FunctionTester(Graph* graph)
41 : isolate(main_isolate()), 39 : isolate(main_isolate()),
42 function(NewFunction("(function(a,b,c,d){})")), 40 function(NewFunction(BuildFunction(param_count).c_str())),
43 flags_(0) { 41 flags_(0) {
44 CompileGraph(graph); 42 CompileGraph(graph);
45 } 43 }
46 44
45 FunctionTester(const CallInterfaceDescriptor& descriptor, Handle<Code> code)
46 : isolate(main_isolate()),
47 function(
48 (FLAG_allow_natives_syntax = true,
49 NewFunction(BuildFunctionFromDescriptor(descriptor).c_str()))),
50 flags_(0) {
51 Compile(function);
52 function->ReplaceCode(*code);
53 }
54
47 Isolate* isolate; 55 Isolate* isolate;
48 Handle<JSFunction> function; 56 Handle<JSFunction> function;
49 57
58 MaybeHandle<Object> Call() {
59 return Execution::Call(isolate, function, undefined(), 0, nullptr);
60 }
61
50 MaybeHandle<Object> Call(Handle<Object> a, Handle<Object> b) { 62 MaybeHandle<Object> Call(Handle<Object> a, Handle<Object> b) {
51 Handle<Object> args[] = {a, b}; 63 Handle<Object> args[] = {a, b};
52 return Execution::Call(isolate, function, undefined(), 2, args); 64 return Execution::Call(isolate, function, undefined(), 2, args);
53 } 65 }
54 66
55 MaybeHandle<Object> Call(Handle<Object> a, Handle<Object> b, Handle<Object> c, 67 MaybeHandle<Object> Call(Handle<Object> a, Handle<Object> b, Handle<Object> c,
56 Handle<Object> d) { 68 Handle<Object> d) {
57 Handle<Object> args[] = {a, b, c, d}; 69 Handle<Object> args[] = {a, b, c, d};
58 return Execution::Call(isolate, function, undefined(), 4, args); 70 return Execution::Call(isolate, function, undefined(), 4, args);
59 } 71 }
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 185
174 Pipeline pipeline(&info); 186 Pipeline pipeline(&info);
175 Handle<Code> code = pipeline.GenerateCode(); 187 Handle<Code> code = pipeline.GenerateCode();
176 CHECK(!code.is_null()); 188 CHECK(!code.is_null());
177 info.dependencies()->Commit(code); 189 info.dependencies()->Commit(code);
178 info.context()->native_context()->AddOptimizedCode(*code); 190 info.context()->native_context()->AddOptimizedCode(*code);
179 function->ReplaceCode(*code); 191 function->ReplaceCode(*code);
180 return function; 192 return function;
181 } 193 }
182 194
183 static Handle<JSFunction> ForMachineGraph(Graph* graph) { 195 static Handle<JSFunction> ForMachineGraph(Graph* graph, int param_count) {
184 JSFunction* p = NULL; 196 JSFunction* p = NULL;
185 { // because of the implicit handle scope of FunctionTester. 197 { // because of the implicit handle scope of FunctionTester.
186 FunctionTester f(graph); 198 FunctionTester f(graph, param_count);
187 p = *f.function; 199 p = *f.function;
188 } 200 }
189 return Handle<JSFunction>(p); // allocated in outer handle scope. 201 return Handle<JSFunction>(p); // allocated in outer handle scope.
190 } 202 }
191 203
192 private: 204 private:
193 uint32_t flags_; 205 uint32_t flags_;
194 206
207 std::string BuildFunction(int param_count) {
208 std::string function_string = "(function(";
209 if (param_count > 0) {
210 char next = 'a';
211 function_string += next;
212 while (param_count-- > 0) {
213 function_string += ',';
214 function_string += ++next;
215 }
216 }
217 function_string += "){})";
218 return function_string;
219 }
220
221 std::string BuildFunctionFromDescriptor(
222 const CallInterfaceDescriptor& descriptor) {
223 return BuildFunction(descriptor.GetParameterCount());
224 }
225
195 // Compile the given machine graph instead of the source of the function 226 // Compile the given machine graph instead of the source of the function
196 // and replace the JSFunction's code with the result. 227 // and replace the JSFunction's code with the result.
197 Handle<JSFunction> CompileGraph(Graph* graph) { 228 Handle<JSFunction> CompileGraph(Graph* graph) {
198 Zone zone; 229 Zone zone;
199 ParseInfo parse_info(&zone, function); 230 ParseInfo parse_info(&zone, function);
200 CompilationInfo info(&parse_info); 231 CompilationInfo info(&parse_info);
201 232
202 CHECK(Parser::ParseStatic(info.parse_info())); 233 CHECK(Parser::ParseStatic(info.parse_info()));
203 info.SetOptimizing(BailoutId::None(), 234 info.SetOptimizing(BailoutId::None(),
204 Handle<Code>(function->shared()->code())); 235 Handle<Code>(function->shared()->code()));
205 CHECK(Compiler::Analyze(info.parse_info())); 236 CHECK(Compiler::Analyze(info.parse_info()));
206 CHECK(Compiler::EnsureDeoptimizationSupport(&info)); 237 CHECK(Compiler::EnsureDeoptimizationSupport(&info));
207 238
208 Handle<Code> code = Pipeline::GenerateCodeForTesting(&info, graph); 239 Handle<Code> code = Pipeline::GenerateCodeForTesting(&info, graph);
209 CHECK(!code.is_null()); 240 CHECK(!code.is_null());
210 function->ReplaceCode(*code); 241 function->ReplaceCode(*code);
211 return function; 242 return function;
212 } 243 }
213 }; 244 };
214 } // namespace compiler 245 } // namespace compiler
215 } // namespace internal 246 } // namespace internal
216 } // namespace v8 247 } // namespace v8
217 248
218 #endif // V8_CCTEST_COMPILER_FUNCTION_TESTER_H_ 249 #endif // V8_CCTEST_COMPILER_FUNCTION_TESTER_H_
OLDNEW
« no previous file with comments | « test/cctest/cctest.gyp ('k') | test/cctest/compiler/test-code-stub-assembler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698