OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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.h" | 5 #include "src/compiler.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "src/ast/ast-numbering.h" | 9 #include "src/ast/ast-numbering.h" |
10 #include "src/ast/prettyprinter.h" | 10 #include "src/ast/prettyprinter.h" |
(...skipping 1633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1644 } else if (!lazy) { | 1644 } else if (!lazy) { |
1645 // Assert that we are not overwriting (possibly patched) debug code. | 1645 // Assert that we are not overwriting (possibly patched) debug code. |
1646 DCHECK(!existing->HasDebugCode()); | 1646 DCHECK(!existing->HasDebugCode()); |
1647 existing->ReplaceCode(*info.code()); | 1647 existing->ReplaceCode(*info.code()); |
1648 existing->set_scope_info(*scope_info); | 1648 existing->set_scope_info(*scope_info); |
1649 existing->set_feedback_vector(*info.feedback_vector()); | 1649 existing->set_feedback_vector(*info.feedback_vector()); |
1650 } | 1650 } |
1651 return existing; | 1651 return existing; |
1652 } | 1652 } |
1653 | 1653 |
| 1654 Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForNative( |
| 1655 v8::Extension* extension, Handle<String> name) { |
| 1656 Isolate* isolate = name->GetIsolate(); |
| 1657 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); |
| 1658 |
| 1659 // Compute the function template for the native function. |
| 1660 v8::Local<v8::FunctionTemplate> fun_template = |
| 1661 extension->GetNativeFunctionTemplate(v8_isolate, |
| 1662 v8::Utils::ToLocal(name)); |
| 1663 DCHECK(!fun_template.IsEmpty()); |
| 1664 |
| 1665 // Instantiate the function and create a shared function info from it. |
| 1666 Handle<JSFunction> fun = Handle<JSFunction>::cast(Utils::OpenHandle( |
| 1667 *fun_template->GetFunction(v8_isolate->GetCurrentContext()) |
| 1668 .ToLocalChecked())); |
| 1669 const int literals = fun->NumberOfLiterals(); |
| 1670 Handle<Code> code = Handle<Code>(fun->shared()->code()); |
| 1671 Handle<Code> construct_stub = Handle<Code>(fun->shared()->construct_stub()); |
| 1672 Handle<SharedFunctionInfo> shared = isolate->factory()->NewSharedFunctionInfo( |
| 1673 name, literals, FunctionKind::kNormalFunction, code, |
| 1674 Handle<ScopeInfo>(fun->shared()->scope_info()), |
| 1675 Handle<TypeFeedbackVector>(fun->shared()->feedback_vector())); |
| 1676 shared->set_construct_stub(*construct_stub); |
| 1677 |
| 1678 // Copy the function data to the shared function info. |
| 1679 shared->set_function_data(fun->shared()->function_data()); |
| 1680 int parameters = fun->shared()->internal_formal_parameter_count(); |
| 1681 shared->set_internal_formal_parameter_count(parameters); |
| 1682 |
| 1683 return shared; |
| 1684 } |
1654 | 1685 |
1655 MaybeHandle<Code> Compiler::GetOptimizedCode(Handle<JSFunction> function, | 1686 MaybeHandle<Code> Compiler::GetOptimizedCode(Handle<JSFunction> function, |
1656 ConcurrencyMode mode, | 1687 ConcurrencyMode mode, |
1657 BailoutId osr_ast_id, | 1688 BailoutId osr_ast_id, |
1658 JavaScriptFrame* osr_frame) { | 1689 JavaScriptFrame* osr_frame) { |
1659 Isolate* isolate = function->GetIsolate(); | 1690 Isolate* isolate = function->GetIsolate(); |
1660 Handle<SharedFunctionInfo> shared(function->shared(), isolate); | 1691 Handle<SharedFunctionInfo> shared(function->shared(), isolate); |
1661 if (shared->HasDebugInfo()) return MaybeHandle<Code>(); | 1692 if (shared->HasDebugInfo()) return MaybeHandle<Code>(); |
1662 | 1693 |
1663 Handle<Code> cached_code; | 1694 Handle<Code> cached_code; |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1806 } | 1837 } |
1807 | 1838 |
1808 #if DEBUG | 1839 #if DEBUG |
1809 void CompilationInfo::PrintAstForTesting() { | 1840 void CompilationInfo::PrintAstForTesting() { |
1810 PrintF("--- Source from AST ---\n%s\n", | 1841 PrintF("--- Source from AST ---\n%s\n", |
1811 PrettyPrinter(isolate()).PrintProgram(literal())); | 1842 PrettyPrinter(isolate()).PrintProgram(literal())); |
1812 } | 1843 } |
1813 #endif | 1844 #endif |
1814 } // namespace internal | 1845 } // namespace internal |
1815 } // namespace v8 | 1846 } // namespace v8 |
OLD | NEW |