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

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: Merge with ToT 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
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 // TODO(turbofan): generalize FunctionTester to work with N arguments. Now, it
Michael Starzinger 2015/12/01 18:06:53 I think your change pretty much addresses this TOD
danno 2015/12/02 07:00:19 Done.
39 // can handle up to four. 39 // can handle up to four.
40 explicit FunctionTester(Graph* graph) 40 explicit FunctionTester(Graph* graph, int param_count)
Michael Starzinger 2015/12/01 18:06:53 nit: No longer needs to be marked "explicit".
danno 2015/12/02 07:00:19 Done.
41 : isolate(main_isolate()), 41 : isolate(main_isolate()),
42 function(NewFunction("(function(a,b,c,d){})")), 42 function(NewFunction(BuildFunction(param_count).c_str())),
43 flags_(0) { 43 flags_(0) {
44 CompileGraph(graph); 44 CompileGraph(graph);
45 } 45 }
46 46
47 explicit FunctionTester(const CallInterfaceDescriptor& descriptor,
Michael Starzinger 2015/12/01 18:06:53 nit: Doesn't need to be marked "explicit".
danno 2015/12/02 07:00:19 Done.
48 Handle<Code> code)
49 : isolate(main_isolate()),
50 function(
51 (FLAG_allow_natives_syntax = true,
52 NewFunction(BuildFunctionFromDescriptor(descriptor).c_str()))) {
53 Compile(function);
54 function->ReplaceCode(*code);
55 }
56
47 Isolate* isolate; 57 Isolate* isolate;
48 Handle<JSFunction> function; 58 Handle<JSFunction> function;
49 59
60 MaybeHandle<Object> Call() {
61 return Execution::Call(isolate, function, undefined(), 0, nullptr);
62 }
63
50 MaybeHandle<Object> Call(Handle<Object> a, Handle<Object> b) { 64 MaybeHandle<Object> Call(Handle<Object> a, Handle<Object> b) {
51 Handle<Object> args[] = {a, b}; 65 Handle<Object> args[] = {a, b};
52 return Execution::Call(isolate, function, undefined(), 2, args); 66 return Execution::Call(isolate, function, undefined(), 2, args);
53 } 67 }
54 68
55 MaybeHandle<Object> Call(Handle<Object> a, Handle<Object> b, Handle<Object> c, 69 MaybeHandle<Object> Call(Handle<Object> a, Handle<Object> b, Handle<Object> c,
56 Handle<Object> d) { 70 Handle<Object> d) {
57 Handle<Object> args[] = {a, b, c, d}; 71 Handle<Object> args[] = {a, b, c, d};
58 return Execution::Call(isolate, function, undefined(), 4, args); 72 return Execution::Call(isolate, function, undefined(), 4, args);
59 } 73 }
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 187
174 Pipeline pipeline(&info); 188 Pipeline pipeline(&info);
175 Handle<Code> code = pipeline.GenerateCode(); 189 Handle<Code> code = pipeline.GenerateCode();
176 CHECK(!code.is_null()); 190 CHECK(!code.is_null());
177 info.dependencies()->Commit(code); 191 info.dependencies()->Commit(code);
178 info.context()->native_context()->AddOptimizedCode(*code); 192 info.context()->native_context()->AddOptimizedCode(*code);
179 function->ReplaceCode(*code); 193 function->ReplaceCode(*code);
180 return function; 194 return function;
181 } 195 }
182 196
183 static Handle<JSFunction> ForMachineGraph(Graph* graph) { 197 static Handle<JSFunction> ForMachineGraph(Graph* graph, int param_count) {
184 JSFunction* p = NULL; 198 JSFunction* p = NULL;
185 { // because of the implicit handle scope of FunctionTester. 199 { // because of the implicit handle scope of FunctionTester.
186 FunctionTester f(graph); 200 FunctionTester f(graph, param_count);
187 p = *f.function; 201 p = *f.function;
188 } 202 }
189 return Handle<JSFunction>(p); // allocated in outer handle scope. 203 return Handle<JSFunction>(p); // allocated in outer handle scope.
190 } 204 }
191 205
192 private: 206 private:
193 uint32_t flags_; 207 uint32_t flags_;
194 208
209 std::string BuildFunction(int param_count) {
210 std::string function_string = "(function(";
211 if (param_count > 0) {
212 char next = 'a';
213 function_string += next;
214 while (param_count-- > 0) {
215 function_string += ',';
216 function_string += ++next;
217 }
218 }
219 function_string += "){})";
220 return function_string;
221 }
222
223 std::string BuildFunctionFromDescriptor(
224 const CallInterfaceDescriptor& descriptor) {
225 return BuildFunction(descriptor.GetParameterCount());
226 }
227
195 // Compile the given machine graph instead of the source of the function 228 // Compile the given machine graph instead of the source of the function
196 // and replace the JSFunction's code with the result. 229 // and replace the JSFunction's code with the result.
197 Handle<JSFunction> CompileGraph(Graph* graph) { 230 Handle<JSFunction> CompileGraph(Graph* graph) {
198 Zone zone; 231 Zone zone;
199 ParseInfo parse_info(&zone, function); 232 ParseInfo parse_info(&zone, function);
200 CompilationInfo info(&parse_info); 233 CompilationInfo info(&parse_info);
201 234
202 CHECK(Parser::ParseStatic(info.parse_info())); 235 CHECK(Parser::ParseStatic(info.parse_info()));
203 info.SetOptimizing(BailoutId::None(), 236 info.SetOptimizing(BailoutId::None(),
204 Handle<Code>(function->shared()->code())); 237 Handle<Code>(function->shared()->code()));
205 CHECK(Compiler::Analyze(info.parse_info())); 238 CHECK(Compiler::Analyze(info.parse_info()));
206 CHECK(Compiler::EnsureDeoptimizationSupport(&info)); 239 CHECK(Compiler::EnsureDeoptimizationSupport(&info));
207 240
208 Handle<Code> code = Pipeline::GenerateCodeForTesting(&info, graph); 241 Handle<Code> code = Pipeline::GenerateCodeForTesting(&info, graph);
209 CHECK(!code.is_null()); 242 CHECK(!code.is_null());
210 function->ReplaceCode(*code); 243 function->ReplaceCode(*code);
211 return function; 244 return function;
212 } 245 }
213 }; 246 };
214 } // namespace compiler 247 } // namespace compiler
215 } // namespace internal 248 } // namespace internal
216 } // namespace v8 249 } // namespace v8
217 250
218 #endif // V8_CCTEST_COMPILER_FUNCTION_TESTER_H_ 251 #endif // V8_CCTEST_COMPILER_FUNCTION_TESTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698