Chromium Code Reviews| 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 | |
|
hausner
2013/05/21 20:07:30
Nit: extra blank line.
siva
2013/05/23 00:54:31
Done.
| |
| 110 | |
| 111 // Add all the interfaces implemented by the class that have not been | |
| 112 // already parsed to the parse list. Mark the interface as parsed so that | |
| 113 // we don't recursively add it back into the list. | |
| 114 interfaces ^= cls.interfaces(); | |
| 115 for (intptr_t i = 0; i < interfaces.Length(); i++) { | |
| 116 interface_type ^= interfaces.At(i); | |
| 117 parse_class ^= interface_type.type_class(); | |
| 118 if (!parse_class.is_parsed()) { | |
| 119 parse_list.Add(parse_class); | |
| 120 parse_class.set_is_parsed(); | |
| 121 } | |
| 122 } | |
| 123 | |
| 124 // Walk up the super_class chain and add these classes to the list if they | |
| 125 // have not been already parsed to the parse list. Mark the class as parsed | |
| 126 // so that we don't recursively add it back into the list. | |
| 127 parse_class ^= cls.SuperClass(); | |
| 128 while (!parse_class.IsNull()) { | |
| 129 if (!parse_class.is_parsed()) { | |
| 130 parse_list.Add(parse_class); | |
| 131 parse_class.set_is_parsed(); | |
| 132 } | |
| 133 parse_class ^= parse_class.SuperClass(); | |
| 134 } | |
| 135 | |
| 136 // Add patch classes if they exist to the parse list if they have not already | |
| 137 // been parsed and patched. Mark the class as parsed so that we don't | |
| 138 // recursively add it back into the list. | |
| 139 const GrowableObjectArray& patch_class_array = | |
| 140 GrowableObjectArray::Handle(cls.patch_classes()); | |
| 141 if (!patch_class_array.IsNull()) { | |
| 142 for (intptr_t i = 0; i < patch_class_array.Length(); i++) { | |
| 143 parse_class ^= patch_class_array.At(i); | |
| 144 ASSERT(!parse_class.IsNull()); | |
| 145 if (!parse_class.is_parsed()) { | |
| 146 patch_list.Add(parse_class); | |
| 147 parse_class.set_is_parsed(); | |
| 148 } | |
| 149 } | |
| 150 } | |
| 151 } | |
| 152 | |
| 153 | |
| 154 RawError* Compiler::ParseClass(const Class& cls) { | |
| 155 Isolate* isolate = Isolate::Current(); | |
| 156 StackZone zone(isolate); | |
| 157 LongJump* base = isolate->long_jump_base(); | |
| 158 LongJump jump; | |
| 159 isolate->set_long_jump_base(&jump); | |
| 160 if (setjmp(*jump.Set()) == 0) { | |
| 161 if (FLAG_trace_compiler) { | |
| 162 OS::Print("Compiling Class %s '%s'\n", "", cls.ToCString()); | |
| 163 } | |
| 164 | |
| 165 Class& parse_class = Class::Handle(); | |
| 166 const GrowableObjectArray& parse_list = | |
| 167 GrowableObjectArray::Handle(GrowableObjectArray::New(4)); | |
| 168 const GrowableObjectArray& patch_list = | |
| 169 GrowableObjectArray::Handle(GrowableObjectArray::New(4)); | |
| 170 | |
| 171 // Add the primary class which needs to be parsed to the parse list. | |
| 172 // Mark the class as parsed so that we don't recursively add the same | |
| 173 // class back into the list. | |
| 174 parse_list.Add(cls); | |
| 175 cls.set_is_parsed(); | |
|
hausner
2013/05/21 20:07:30
I am slightly concerned about setting the 'is_pars
siva
2013/05/23 00:54:31
I have renamed the is_parsed bit to is_marked_for_
| |
| 176 | |
| 177 // Add all super classes, interface classes and patch class if one | |
| 178 // exists to the corresponding lists. | |
| 179 for (intptr_t i = 0; i < parse_list.Length(); i++) { | |
| 180 parse_class ^= parse_list.At(i); | |
| 181 AddRelatedClassesToList(parse_class, parse_list, patch_list); | |
| 182 } | |
| 183 | |
| 184 // Parse all the classes that have been added above. | |
| 185 for (intptr_t i = (parse_list.Length() - 1); i >=0 ; i--) { | |
| 186 parse_class ^= parse_list.At(i); | |
| 187 ASSERT(!parse_class.IsNull()); | |
| 188 Parser::ParseClass(parse_class); | |
| 189 } | |
| 190 | |
| 191 // Parse all the patch classes that have been added above. | |
| 192 for (intptr_t i = 0; i < patch_list.Length(); i++) { | |
| 193 parse_class ^= patch_list.At(i); | |
| 194 ASSERT(!parse_class.IsNull()); | |
| 195 Parser::ParseClass(parse_class); | |
| 196 } | |
| 197 | |
| 198 // Finalize these classes. | |
| 199 for (intptr_t i = (parse_list.Length() - 1); i >=0 ; i--) { | |
| 200 parse_class ^= parse_list.At(i); | |
| 201 ASSERT(!parse_class.IsNull()); | |
| 202 ClassFinalizer::FinalizeClass(parse_class); | |
| 203 } | |
| 204 | |
| 205 isolate->set_long_jump_base(base); | |
| 206 return Error::null(); | |
| 207 } else { | |
| 208 Error& error = Error::Handle(); | |
| 209 error = isolate->object_store()->sticky_error(); | |
| 210 isolate->object_store()->clear_sticky_error(); | |
| 211 isolate->set_long_jump_base(base); | |
| 212 return error.raw(); | |
| 213 } | |
| 214 UNREACHABLE(); | |
| 215 return Error::null(); | |
| 216 } | |
| 217 | |
| 218 | |
| 102 static void InstallUnoptimizedCode(const Function& function) { | 219 static void InstallUnoptimizedCode(const Function& function) { |
| 103 // Disable optimized code. | 220 // Disable optimized code. |
| 104 ASSERT(function.HasOptimizedCode()); | 221 ASSERT(function.HasOptimizedCode()); |
| 105 if (FLAG_trace_compiler) { | 222 if (FLAG_trace_compiler) { |
| 106 OS::Print("--> patching entry %#"Px"\n", | 223 OS::Print("--> patching entry %#"Px"\n", |
| 107 Code::Handle(function.CurrentCode()).EntryPoint()); | 224 Code::Handle(function.CurrentCode()).EntryPoint()); |
| 108 } | 225 } |
| 109 function.SwitchToUnoptimizedCode(); | 226 function.SwitchToUnoptimizedCode(); |
| 110 if (FLAG_trace_compiler) { | 227 if (FLAG_trace_compiler) { |
| 111 OS::Print("--> restoring entry at %#"Px"\n", | 228 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()); | 853 Object::Handle(isolate->object_store()->sticky_error()); |
| 737 isolate->object_store()->clear_sticky_error(); | 854 isolate->object_store()->clear_sticky_error(); |
| 738 isolate->set_long_jump_base(base); | 855 isolate->set_long_jump_base(base); |
| 739 return result.raw(); | 856 return result.raw(); |
| 740 } | 857 } |
| 741 UNREACHABLE(); | 858 UNREACHABLE(); |
| 742 return Object::null(); | 859 return Object::null(); |
| 743 } | 860 } |
| 744 | 861 |
| 745 } // namespace dart | 862 } // namespace dart |
| OLD | NEW |