| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 "vm/compiler.h" | 5 #include "vm/compiler.h" |
| 6 | 6 |
| 7 #include "vm/assembler.h" | 7 #include "vm/assembler.h" |
| 8 | 8 |
| 9 #include "vm/ast_printer.h" | 9 #include "vm/ast_printer.h" |
| 10 #include "vm/code_generator.h" | 10 #include "vm/code_generator.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 error = isolate->object_store()->sticky_error(); | 92 error = isolate->object_store()->sticky_error(); |
| 93 isolate->object_store()->clear_sticky_error(); | 93 isolate->object_store()->clear_sticky_error(); |
| 94 isolate->set_long_jump_base(base); | 94 isolate->set_long_jump_base(base); |
| 95 return error.raw(); | 95 return error.raw(); |
| 96 } | 96 } |
| 97 UNREACHABLE(); | 97 UNREACHABLE(); |
| 98 return Error::null(); | 98 return Error::null(); |
| 99 } | 99 } |
| 100 | 100 |
| 101 | 101 |
| 102 static void AddRelatedClassesToList(const Class& cls, |
| 103 const GrowableObjectArray& parse_list, |
| 104 const GrowableObjectArray& patch_list) { |
| 105 Isolate* isolate = Isolate::Current(); |
| 106 Class& parse_class = Class::Handle(isolate); |
| 107 Type& interface_type = Type::Handle(isolate); |
| 108 Array& interfaces = Array::Handle(isolate); |
| 109 |
| 110 // Add all the interfaces implemented by the class that have not been |
| 111 // already parsed to the parse list. Mark the interface as parsed so that |
| 112 // we don't recursively add it back into the list. |
| 113 interfaces ^= cls.interfaces(); |
| 114 for (intptr_t i = 0; i < interfaces.Length(); i++) { |
| 115 interface_type ^= interfaces.At(i); |
| 116 parse_class ^= interface_type.type_class(); |
| 117 if (!parse_class.is_finalized() && !parse_class.is_marked_for_parsing()) { |
| 118 parse_list.Add(parse_class); |
| 119 parse_class.set_is_marked_for_parsing(); |
| 120 } |
| 121 } |
| 122 |
| 123 // Walk up the super_class chain and add these classes to the list if they |
| 124 // have not been already parsed to the parse list. Mark the class as parsed |
| 125 // so that we don't recursively add it back into the list. |
| 126 parse_class ^= cls.SuperClass(); |
| 127 while (!parse_class.IsNull()) { |
| 128 if (!parse_class.is_finalized() && !parse_class.is_marked_for_parsing()) { |
| 129 parse_list.Add(parse_class); |
| 130 parse_class.set_is_marked_for_parsing(); |
| 131 } |
| 132 parse_class ^= parse_class.SuperClass(); |
| 133 } |
| 134 |
| 135 // Add patch classes if they exist to the parse list if they have not already |
| 136 // been parsed and patched. Mark the class as parsed so that we don't |
| 137 // recursively add it back into the list. |
| 138 parse_class ^= cls.patch_class(); |
| 139 if (!parse_class.IsNull()) { |
| 140 if (!parse_class.is_finalized() && !parse_class.is_marked_for_parsing()) { |
| 141 patch_list.Add(parse_class); |
| 142 parse_class.set_is_marked_for_parsing(); |
| 143 } |
| 144 } |
| 145 } |
| 146 |
| 147 |
| 148 RawError* Compiler::CompileClass(const Class& cls) { |
| 149 // If class is a top level class it is already parsed. |
| 150 if (cls.IsTopLevel()) { |
| 151 return Error::null(); |
| 152 } |
| 153 // If the class is already marked for parsing return immediately. |
| 154 if (cls.is_marked_for_parsing()) { |
| 155 return Error::null(); |
| 156 } |
| 157 // Parse the class and all the interfaces it implements and super classes. |
| 158 Isolate* isolate = Isolate::Current(); |
| 159 StackZone zone(isolate); |
| 160 LongJump* base = isolate->long_jump_base(); |
| 161 LongJump jump; |
| 162 isolate->set_long_jump_base(&jump); |
| 163 if (setjmp(*jump.Set()) == 0) { |
| 164 if (FLAG_trace_compiler) { |
| 165 OS::Print("Compiling Class %s '%s'\n", "", cls.ToCString()); |
| 166 } |
| 167 |
| 168 Class& parse_class = Class::Handle(); |
| 169 const GrowableObjectArray& parse_list = |
| 170 GrowableObjectArray::Handle(GrowableObjectArray::New(4)); |
| 171 const GrowableObjectArray& patch_list = |
| 172 GrowableObjectArray::Handle(GrowableObjectArray::New(4)); |
| 173 |
| 174 // Add the primary class which needs to be parsed to the parse list. |
| 175 // Mark the class as parsed so that we don't recursively add the same |
| 176 // class back into the list. |
| 177 parse_list.Add(cls); |
| 178 cls.set_is_marked_for_parsing(); |
| 179 |
| 180 // Add all super classes, interface classes and patch class if one |
| 181 // exists to the corresponding lists. |
| 182 // NOTE: The parse_list array keeps growing as more classes are added |
| 183 // to it by AddRelatedClassesToList. It is not OK to hoist |
| 184 // parse_list.Length() into a local variable and iterate using the local |
| 185 // variable. |
| 186 for (intptr_t i = 0; i < parse_list.Length(); i++) { |
| 187 parse_class ^= parse_list.At(i); |
| 188 AddRelatedClassesToList(parse_class, parse_list, patch_list); |
| 189 } |
| 190 |
| 191 // Parse all the classes that have been added above. |
| 192 for (intptr_t i = (parse_list.Length() - 1); i >=0 ; i--) { |
| 193 parse_class ^= parse_list.At(i); |
| 194 ASSERT(!parse_class.IsNull()); |
| 195 Parser::ParseClass(parse_class); |
| 196 } |
| 197 |
| 198 // Parse all the patch classes that have been added above. |
| 199 for (intptr_t i = 0; i < patch_list.Length(); i++) { |
| 200 parse_class ^= patch_list.At(i); |
| 201 ASSERT(!parse_class.IsNull()); |
| 202 Parser::ParseClass(parse_class); |
| 203 } |
| 204 |
| 205 // Finalize these classes. |
| 206 for (intptr_t i = (parse_list.Length() - 1); i >=0 ; i--) { |
| 207 parse_class ^= parse_list.At(i); |
| 208 ASSERT(!parse_class.IsNull()); |
| 209 ClassFinalizer::FinalizeClass(parse_class); |
| 210 parse_class.reset_is_marked_for_parsing(); |
| 211 } |
| 212 |
| 213 isolate->set_long_jump_base(base); |
| 214 return Error::null(); |
| 215 } else { |
| 216 Error& error = Error::Handle(); |
| 217 error = isolate->object_store()->sticky_error(); |
| 218 isolate->object_store()->clear_sticky_error(); |
| 219 isolate->set_long_jump_base(base); |
| 220 return error.raw(); |
| 221 } |
| 222 UNREACHABLE(); |
| 223 return Error::null(); |
| 224 } |
| 225 |
| 226 |
| 102 static void InstallUnoptimizedCode(const Function& function) { | 227 static void InstallUnoptimizedCode(const Function& function) { |
| 103 // Disable optimized code. | 228 // Disable optimized code. |
| 104 ASSERT(function.HasOptimizedCode()); | 229 ASSERT(function.HasOptimizedCode()); |
| 105 if (FLAG_trace_compiler) { | 230 if (FLAG_trace_compiler) { |
| 106 OS::Print("--> patching entry %#"Px"\n", | 231 OS::Print("--> patching entry %#"Px"\n", |
| 107 Code::Handle(function.CurrentCode()).EntryPoint()); | 232 Code::Handle(function.CurrentCode()).EntryPoint()); |
| 108 } | 233 } |
| 109 function.SwitchToUnoptimizedCode(); | 234 function.SwitchToUnoptimizedCode(); |
| 110 if (FLAG_trace_compiler) { | 235 if (FLAG_trace_compiler) { |
| 111 OS::Print("--> restoring entry at %#"Px"\n", | 236 OS::Print("--> restoring entry at %#"Px"\n", |
| (...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 736 Object::Handle(isolate->object_store()->sticky_error()); | 861 Object::Handle(isolate->object_store()->sticky_error()); |
| 737 isolate->object_store()->clear_sticky_error(); | 862 isolate->object_store()->clear_sticky_error(); |
| 738 isolate->set_long_jump_base(base); | 863 isolate->set_long_jump_base(base); |
| 739 return result.raw(); | 864 return result.raw(); |
| 740 } | 865 } |
| 741 UNREACHABLE(); | 866 UNREACHABLE(); |
| 742 return Object::null(); | 867 return Object::null(); |
| 743 } | 868 } |
| 744 | 869 |
| 745 } // namespace dart | 870 } // namespace dart |
| OLD | NEW |