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

Side by Side Diff: runtime/vm/kernel_to_il.cc

Issue 2485993002: VM: Support bootstrapping core libraries from Kernel binaries instead of source. (Closed)
Patch Set: Done Created 4 years, 1 month 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 (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include <map> 5 #include <map>
6 #include <set> 6 #include <set>
7 #include <string> 7 #include <string>
8 8
9 #include "vm/kernel_to_il.h" 9 #include "vm/kernel_to_il.h"
10 10
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 node->finalizer()->AcceptStatementVisitor(this); 592 node->finalizer()->AcceptStatementVisitor(this);
593 --depth_.catch_; 593 --depth_.catch_;
594 } 594 }
595 595
596 596
597 void ScopeBuilder::VisitFunctionNode(FunctionNode* node) { 597 void ScopeBuilder::VisitFunctionNode(FunctionNode* node) {
598 List<TypeParameter>& type_parameters = node->type_parameters(); 598 List<TypeParameter>& type_parameters = node->type_parameters();
599 for (intptr_t i = 0; i < type_parameters.length(); ++i) { 599 for (intptr_t i = 0; i < type_parameters.length(); ++i) {
600 VisitTypeParameter(type_parameters[i]); 600 VisitTypeParameter(type_parameters[i]);
601 } 601 }
602
603 if (node->async_marker() == FunctionNode::kSyncYielding) {
604 LocalScope* scope = parsed_function_->node_sequence()->scope();
605 for (intptr_t i = 0;
606 i < parsed_function_->function().NumOptionalPositionalParameters();
607 i++) {
608 scope->VariableAt(i)->set_is_forced_stack();
609 }
610 }
611
602 // Do not visit the positional and named parameters, because they've 612 // Do not visit the positional and named parameters, because they've
603 // already been added to the scope. 613 // already been added to the scope.
604 if (node->body() != NULL) { 614 if (node->body() != NULL) {
605 node->body()->AcceptStatementVisitor(this); 615 node->body()->AcceptStatementVisitor(this);
606 } 616 }
607 617
608 // Ensure that :await_jump_var and :await_ctx_var are captured. 618 // Ensure that :await_jump_var and :await_ctx_var are captured.
609 if (node->async_marker() == FunctionNode::kSyncYielding) { 619 if (node->async_marker() == FunctionNode::kSyncYielding) {
610 { 620 {
611 LocalVariable* temp = NULL; 621 LocalVariable* temp = NULL;
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 Library* kernel_library = Library::Cast(kernel_klass->parent()); 1059 Library* kernel_library = Library::Cast(kernel_klass->parent());
1050 dart::Library& library = 1060 dart::Library& library =
1051 dart::Library::Handle(Z, LookupLibraryByKernelLibrary(kernel_library)); 1061 dart::Library::Handle(Z, LookupLibraryByKernelLibrary(kernel_library));
1052 klass = library.LookupClassAllowPrivate(class_name); 1062 klass = library.LookupClassAllowPrivate(class_name);
1053 1063
1054 ASSERT(klass != Object::null()); 1064 ASSERT(klass != Object::null());
1055 return klass; 1065 return klass;
1056 } 1066 }
1057 1067
1058 1068
1069 dart::RawUnresolvedClass* TranslationHelper::ToUnresolvedClass(
1070 Class* kernel_klass) {
1071 dart::RawClass* klass = NULL;
1072
1073 const dart::String& class_name = DartClassName(kernel_klass);
1074 Library* kernel_library = Library::Cast(kernel_klass->parent());
1075 dart::Library& library =
1076 dart::Library::Handle(Z, LookupLibraryByKernelLibrary(kernel_library));
1077
1078 ASSERT(klass != Object::null());
1079 return dart::UnresolvedClass::New(library, class_name,
1080 TokenPosition::kNoSource);
1081 }
1082
1083
1059 dart::RawField* TranslationHelper::LookupFieldByKernelField( 1084 dart::RawField* TranslationHelper::LookupFieldByKernelField(
1060 Field* kernel_field) { 1085 Field* kernel_field) {
1061 TreeNode* node = kernel_field->parent(); 1086 TreeNode* node = kernel_field->parent();
1062 1087
1063 dart::Class& klass = dart::Class::Handle(Z); 1088 dart::Class& klass = dart::Class::Handle(Z);
1064 if (node->IsClass()) { 1089 if (node->IsClass()) {
1065 klass = LookupClassByKernelClass(Class::Cast(node)); 1090 klass = LookupClassByKernelClass(Class::Cast(node));
1066 } else { 1091 } else {
1067 ASSERT(node->IsLibrary()); 1092 ASSERT(node->IsLibrary());
1068 dart::Library& library = dart::Library::Handle( 1093 dart::Library& library = dart::Library::Handle(
(...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after
1746 const Object& result = Object::Handle( 1771 const Object& result = Object::Handle(
1747 Z, DartEntry::InvokeFunction(function, arguments, args_descriptor)); 1772 Z, DartEntry::InvokeFunction(function, arguments, args_descriptor));
1748 if (result.IsError()) { 1773 if (result.IsError()) {
1749 H.ReportError(Error::Cast(result), "error evaluating constant constructor"); 1774 H.ReportError(Error::Cast(result), "error evaluating constant constructor");
1750 } 1775 }
1751 return result; 1776 return result;
1752 } 1777 }
1753 1778
1754 1779
1755 FlowGraphBuilder::FlowGraphBuilder( 1780 FlowGraphBuilder::FlowGraphBuilder(
1756 TreeNode* node, ParsedFunction* parsed_function, 1781 TreeNode* node,
1782 ParsedFunction* parsed_function,
1757 const ZoneGrowableArray<const ICData*>& ic_data_array, 1783 const ZoneGrowableArray<const ICData*>& ic_data_array,
1758 InlineExitCollector* exit_collector, intptr_t osr_id, 1784 InlineExitCollector* exit_collector,
1785 intptr_t osr_id,
1759 intptr_t first_block_id) 1786 intptr_t first_block_id)
1760 : zone_(Thread::Current()->zone()), 1787 : zone_(Thread::Current()->zone()),
1761 translation_helper_(Thread::Current(), zone_, 1788 translation_helper_(Thread::Current(),
1789 zone_,
1762 Thread::Current()->isolate()), 1790 Thread::Current()->isolate()),
1763 node_(node), 1791 node_(node),
1764 parsed_function_(parsed_function), 1792 parsed_function_(parsed_function),
1765 osr_id_(osr_id), 1793 osr_id_(osr_id),
1766 ic_data_array_(ic_data_array), 1794 ic_data_array_(ic_data_array),
1767 exit_collector_(exit_collector), 1795 exit_collector_(exit_collector),
1768 next_block_id_(first_block_id), 1796 next_block_id_(first_block_id),
1769 next_function_id_(0), 1797 next_function_id_(0),
1770 context_depth_(0), 1798 context_depth_(0),
1771 loop_depth_(0), 1799 loop_depth_(0),
1772 try_depth_(0), 1800 try_depth_(0),
1773 catch_depth_(0), 1801 catch_depth_(0),
1774 for_in_depth_(0), 1802 for_in_depth_(0),
1775 stack_(NULL), 1803 stack_(NULL),
1776 pending_argument_count_(0), 1804 pending_argument_count_(0),
1777 graph_entry_(NULL), 1805 graph_entry_(NULL),
1778 scopes_(NULL), 1806 scopes_(NULL),
1779 breakable_block_(NULL), 1807 breakable_block_(NULL),
1780 switch_block_(NULL), 1808 switch_block_(NULL),
1781 try_finally_block_(NULL), 1809 try_finally_block_(NULL),
1782 try_catch_block_(NULL), 1810 try_catch_block_(NULL),
1783 next_used_try_index_(0), 1811 next_used_try_index_(0),
1784 catch_block_(NULL), 1812 catch_block_(NULL),
1785 type_translator_(&translation_helper_, &active_class_), 1813 type_translator_(&translation_helper_,
1786 constant_evaluator_(this, zone_, &translation_helper_, 1814 &active_class_,
1815 /* finalize= */ true),
1816 constant_evaluator_(this,
1817 zone_,
1818 &translation_helper_,
1787 &type_translator_) {} 1819 &type_translator_) {}
1788 1820
1789 1821
1790 FlowGraphBuilder::~FlowGraphBuilder() {} 1822 FlowGraphBuilder::~FlowGraphBuilder() {}
1791 1823
1792 1824
1793 Fragment FlowGraphBuilder::TranslateFinallyFinalizers( 1825 Fragment FlowGraphBuilder::TranslateFinallyFinalizers(
1794 TryFinallyBlock* outer_finally, intptr_t target_context_depth) { 1826 TryFinallyBlock* outer_finally, intptr_t target_context_depth) {
1795 TryFinallyBlock* const saved_block = try_finally_block_; 1827 TryFinallyBlock* const saved_block = try_finally_block_;
1796 const intptr_t saved_depth = context_depth_; 1828 const intptr_t saved_depth = context_depth_;
(...skipping 1992 matching lines...) Expand 10 before | Expand all | Expand 10 after
3789 // We return a new `ZoneHandle` here on purpose: The intermediate language 3821 // We return a new `ZoneHandle` here on purpose: The intermediate language
3790 // instructions do not make a copy of the handle, so we do it. 3822 // instructions do not make a copy of the handle, so we do it.
3791 return dart::AbstractType::ZoneHandle(Z, result_.raw()); 3823 return dart::AbstractType::ZoneHandle(Z, result_.raw());
3792 } 3824 }
3793 3825
3794 3826
3795 AbstractType& DartTypeTranslator::TranslateTypeWithoutFinalization( 3827 AbstractType& DartTypeTranslator::TranslateTypeWithoutFinalization(
3796 DartType* node) { 3828 DartType* node) {
3797 bool saved_finalize = finalize_; 3829 bool saved_finalize = finalize_;
3798 finalize_ = false; 3830 finalize_ = false;
3799 H.SetFinalize(false);
3800 AbstractType& result = TranslateType(node); 3831 AbstractType& result = TranslateType(node);
3801 finalize_ = saved_finalize; 3832 finalize_ = saved_finalize;
3802 H.SetFinalize(saved_finalize);
3803 return result; 3833 return result;
3804 } 3834 }
3805 3835
3806 3836
3807 void DartTypeTranslator::VisitInvalidType(InvalidType* node) { 3837 void DartTypeTranslator::VisitInvalidType(InvalidType* node) {
3808 result_ = ClassFinalizer::NewFinalizedMalformedType( 3838 result_ = ClassFinalizer::NewFinalizedMalformedType(
3809 Error::Handle(Z), // No previous error. 3839 Error::Handle(Z), // No previous error.
3810 dart::Script::Handle(Z, dart::Script::null()), TokenPosition::kNoSource, 3840 dart::Script::Handle(Z, dart::Script::null()), TokenPosition::kNoSource,
3811 "[InvalidType] in Kernel IR."); 3841 "[InvalidType] in Kernel IR.");
3812 } 3842 }
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
3930 } 3960 }
3931 3961
3932 3962
3933 void DartTypeTranslator::VisitInterfaceType(InterfaceType* node) { 3963 void DartTypeTranslator::VisitInterfaceType(InterfaceType* node) {
3934 // NOTE: That an interface type like `T<A, B>` is considered to be 3964 // NOTE: That an interface type like `T<A, B>` is considered to be
3935 // malformed iff `T` is malformed. 3965 // malformed iff `T` is malformed.
3936 // => We therefore ignore errors in `A` or `B`. 3966 // => We therefore ignore errors in `A` or `B`.
3937 const TypeArguments& type_arguments = TranslateTypeArguments( 3967 const TypeArguments& type_arguments = TranslateTypeArguments(
3938 node->type_arguments().raw_array(), node->type_arguments().length()); 3968 node->type_arguments().raw_array(), node->type_arguments().length());
3939 3969
3940 const dart::Class& klass = 3970
3941 dart::Class::Handle(Z, H.LookupClassByKernelClass(node->klass())); 3971 dart::Object& klass = dart::Object::Handle(Z);
3972
3973 if (finalize_) {
3974 klass = H.LookupClassByKernelClass(node->klass());
3975 } else {
3976 klass = H.ToUnresolvedClass(node->klass());
3977 }
3978
3942 3979
3943 result_ = Type::New(klass, type_arguments, TokenPosition::kNoSource); 3980 result_ = Type::New(klass, type_arguments, TokenPosition::kNoSource);
3944 result_.SetIsResolved();
3945 if (finalize_) { 3981 if (finalize_) {
3946 result_ = ClassFinalizer::FinalizeType(klass, result_, 3982 result_.SetIsResolved();
3983 result_ = ClassFinalizer::FinalizeType(dart::Class::Cast(klass), result_,
3947 ClassFinalizer::kCanonicalize); 3984 ClassFinalizer::kCanonicalize);
3948 } 3985 }
3949 } 3986 }
3950 3987
3951 3988
3952 void DartTypeTranslator::VisitDynamicType(DynamicType* node) { 3989 void DartTypeTranslator::VisitDynamicType(DynamicType* node) {
3953 result_ = Object::dynamic_type().raw(); 3990 result_ = Object::dynamic_type().raw();
3954 } 3991 }
3955 3992
3956 3993
(...skipping 1604 matching lines...) Expand 10 before | Expand all | Expand 10 after
5561 // ... 5598 // ...
5562 // } 5599 // }
5563 // 5600 //
5564 LocalScope* scope = parsed_function_->node_sequence()->scope(); 5601 LocalScope* scope = parsed_function_->node_sequence()->scope();
5565 LocalVariable* exception_var = scope->VariableAt(2); 5602 LocalVariable* exception_var = scope->VariableAt(2);
5566 LocalVariable* stack_trace_var = scope->VariableAt(3); 5603 LocalVariable* stack_trace_var = scope->VariableAt(3);
5567 ASSERT(exception_var->name().raw() == Symbols::ExceptionParameter().raw()); 5604 ASSERT(exception_var->name().raw() == Symbols::ExceptionParameter().raw());
5568 ASSERT(stack_trace_var->name().raw() == 5605 ASSERT(stack_trace_var->name().raw() ==
5569 Symbols::StackTraceParameter().raw()); 5606 Symbols::StackTraceParameter().raw());
5570 5607
5571 exception_var->set_is_forced_stack();
5572 stack_trace_var->set_is_forced_stack();
5573
5574 TargetEntryInstr* no_error; 5608 TargetEntryInstr* no_error;
5575 TargetEntryInstr* error; 5609 TargetEntryInstr* error;
5576 5610
5577 continuation += LoadLocal(exception_var); 5611 continuation += LoadLocal(exception_var);
5578 continuation += BranchIfNull(&no_error, &error); 5612 continuation += BranchIfNull(&no_error, &error);
5579 5613
5580 Fragment rethrow(error); 5614 Fragment rethrow(error);
5581 rethrow += LoadLocal(exception_var); 5615 rethrow += LoadLocal(exception_var);
5582 rethrow += PushArgument(); 5616 rethrow += PushArgument();
5583 rethrow += LoadLocal(stack_trace_var); 5617 rethrow += LoadLocal(stack_trace_var);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
5653 instructions += LoadLocal(closure); 5687 instructions += LoadLocal(closure);
5654 instructions += LoadLocal(parsed_function_->current_context_var()); 5688 instructions += LoadLocal(parsed_function_->current_context_var());
5655 instructions += StoreInstanceField(Closure::context_offset()); 5689 instructions += StoreInstanceField(Closure::context_offset());
5656 5690
5657 return instructions; 5691 return instructions;
5658 } 5692 }
5659 5693
5660 5694
5661 } // namespace kernel 5695 } // namespace kernel
5662 } // namespace dart 5696 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698