OLD | NEW |
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 <set> | 5 #include <set> |
6 | 6 |
7 #include "vm/kernel_to_il.h" | 7 #include "vm/kernel_to_il.h" |
8 | 8 |
9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
10 #include "vm/intermediate_language.h" | 10 #include "vm/intermediate_language.h" |
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 try_catch_block_(NULL), | 608 try_catch_block_(NULL), |
609 next_used_try_index_(0), | 609 next_used_try_index_(0), |
610 catch_block_(NULL), | 610 catch_block_(NULL), |
611 streaming_flow_graph_builder_(NULL) { | 611 streaming_flow_graph_builder_(NULL) { |
612 Script& script = Script::Handle(Z, parsed_function->function().script()); | 612 Script& script = Script::Handle(Z, parsed_function->function().script()); |
613 H.SetStringOffsets(TypedData::Handle(Z, script.kernel_string_offsets())); | 613 H.SetStringOffsets(TypedData::Handle(Z, script.kernel_string_offsets())); |
614 H.SetStringData(TypedData::Handle(Z, script.kernel_string_data())); | 614 H.SetStringData(TypedData::Handle(Z, script.kernel_string_data())); |
615 H.SetCanonicalNames(TypedData::Handle(Z, script.kernel_canonical_names())); | 615 H.SetCanonicalNames(TypedData::Handle(Z, script.kernel_canonical_names())); |
616 } | 616 } |
617 | 617 |
618 FlowGraphBuilder::~FlowGraphBuilder() { | 618 FlowGraphBuilder::~FlowGraphBuilder() {} |
619 if (streaming_flow_graph_builder_ != NULL) { | |
620 delete streaming_flow_graph_builder_; | |
621 } | |
622 } | |
623 | 619 |
624 Fragment FlowGraphBuilder::TranslateFinallyFinalizers( | 620 Fragment FlowGraphBuilder::TranslateFinallyFinalizers( |
625 TryFinallyBlock* outer_finally, | 621 TryFinallyBlock* outer_finally, |
626 intptr_t target_context_depth) { | 622 intptr_t target_context_depth) { |
627 TryFinallyBlock* const saved_block = try_finally_block_; | 623 TryFinallyBlock* const saved_block = try_finally_block_; |
628 TryCatchBlock* const saved_try_catch_block = try_catch_block_; | 624 TryCatchBlock* const saved_try_catch_block = try_catch_block_; |
629 const intptr_t saved_depth = context_depth_; | 625 const intptr_t saved_depth = context_depth_; |
630 const intptr_t saved_try_depth = try_depth_; | 626 const intptr_t saved_try_depth = try_depth_; |
631 | 627 |
632 Fragment instructions; | 628 Fragment instructions; |
(...skipping 991 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1624 parsed_function_->function().set_is_inlinable(false); | 1620 parsed_function_->function().set_is_inlinable(false); |
1625 parsed_function_->Bailout("kernel::FlowGraphBuilder", reason); | 1621 parsed_function_->Bailout("kernel::FlowGraphBuilder", reason); |
1626 } | 1622 } |
1627 } | 1623 } |
1628 | 1624 |
1629 FlowGraph* FlowGraphBuilder::BuildGraph() { | 1625 FlowGraph* FlowGraphBuilder::BuildGraph() { |
1630 const Function& function = parsed_function_->function(); | 1626 const Function& function = parsed_function_->function(); |
1631 | 1627 |
1632 if (function.IsConstructorClosureFunction()) return NULL; | 1628 if (function.IsConstructorClosureFunction()) return NULL; |
1633 | 1629 |
1634 if (streaming_flow_graph_builder_ != NULL) { | 1630 StreamingFlowGraphBuilder streaming_flow_graph_builder( |
1635 delete streaming_flow_graph_builder_; | 1631 this, function.kernel_offset(), |
1636 streaming_flow_graph_builder_ = NULL; | 1632 TypedData::Handle(Z, function.kernel_body())); |
1637 } | 1633 streaming_flow_graph_builder_ = &streaming_flow_graph_builder; |
1638 | 1634 FlowGraph* result = streaming_flow_graph_builder_->BuildGraph(0); |
1639 Script& script = Script::Handle(Z, function.script()); | 1635 streaming_flow_graph_builder_ = NULL; |
1640 streaming_flow_graph_builder_ = new StreamingFlowGraphBuilder( | 1636 return result; |
1641 this, script.kernel_data(), script.kernel_data_size()); | |
1642 | |
1643 return streaming_flow_graph_builder_->BuildGraph(kernel_offset_); | |
1644 } | 1637 } |
1645 | 1638 |
1646 Fragment FlowGraphBuilder::NativeFunctionBody(intptr_t first_positional_offset, | 1639 Fragment FlowGraphBuilder::NativeFunctionBody(intptr_t first_positional_offset, |
1647 const Function& function) { | 1640 const Function& function) { |
1648 ASSERT(function.is_native()); | 1641 ASSERT(function.is_native()); |
1649 // We explicitly build the graph for native functions in the same way that the | 1642 // We explicitly build the graph for native functions in the same way that the |
1650 // from-source backend does. We should find a way to have a single component | 1643 // from-source backend does. We should find a way to have a single component |
1651 // to build these graphs so that this code is not duplicated. | 1644 // to build these graphs so that this code is not duplicated. |
1652 | 1645 |
1653 Fragment body; | 1646 Fragment body; |
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2222 Zone* zone_ = thread->zone(); | 2215 Zone* zone_ = thread->zone(); |
2223 TranslationHelper helper(thread); | 2216 TranslationHelper helper(thread); |
2224 Script& script = Script::Handle(Z, metadata_field.Script()); | 2217 Script& script = Script::Handle(Z, metadata_field.Script()); |
2225 helper.SetStringOffsets( | 2218 helper.SetStringOffsets( |
2226 TypedData::Handle(Z, script.kernel_string_offsets())); | 2219 TypedData::Handle(Z, script.kernel_string_offsets())); |
2227 helper.SetStringData(TypedData::Handle(Z, script.kernel_string_data())); | 2220 helper.SetStringData(TypedData::Handle(Z, script.kernel_string_data())); |
2228 helper.SetCanonicalNames( | 2221 helper.SetCanonicalNames( |
2229 TypedData::Handle(Z, script.kernel_canonical_names())); | 2222 TypedData::Handle(Z, script.kernel_canonical_names())); |
2230 | 2223 |
2231 StreamingFlowGraphBuilder streaming_flow_graph_builder( | 2224 StreamingFlowGraphBuilder streaming_flow_graph_builder( |
2232 &helper, zone_, script.kernel_data(), script.kernel_data_size()); | 2225 &helper, zone_, metadata_field.kernel_offset(), |
2233 return streaming_flow_graph_builder.EvaluateMetadata( | 2226 TypedData::Handle(Z, metadata_field.kernel_body())); |
2234 metadata_field.kernel_offset()); | 2227 return streaming_flow_graph_builder.EvaluateMetadata(0); |
2235 } else { | 2228 } else { |
2236 Thread* thread = Thread::Current(); | 2229 Thread* thread = Thread::Current(); |
2237 Error& error = Error::Handle(); | 2230 Error& error = Error::Handle(); |
2238 error = thread->sticky_error(); | 2231 error = thread->sticky_error(); |
2239 thread->clear_sticky_error(); | 2232 thread->clear_sticky_error(); |
2240 return error.raw(); | 2233 return error.raw(); |
2241 } | 2234 } |
2242 } | 2235 } |
2243 | 2236 |
2244 RawObject* BuildParameterDescriptor(const Function& function) { | 2237 RawObject* BuildParameterDescriptor(const Function& function) { |
2245 LongJumpScope jump; | 2238 LongJumpScope jump; |
2246 if (setjmp(*jump.Set()) == 0) { | 2239 if (setjmp(*jump.Set()) == 0) { |
2247 Thread* thread = Thread::Current(); | 2240 Thread* thread = Thread::Current(); |
2248 Zone* zone_ = thread->zone(); | 2241 Zone* zone_ = thread->zone(); |
2249 TranslationHelper helper(thread); | 2242 TranslationHelper helper(thread); |
2250 Script& script = Script::Handle(Z, function.script()); | 2243 Script& script = Script::Handle(Z, function.script()); |
2251 helper.SetStringOffsets( | 2244 helper.SetStringOffsets( |
2252 TypedData::Handle(Z, script.kernel_string_offsets())); | 2245 TypedData::Handle(Z, script.kernel_string_offsets())); |
2253 helper.SetStringData(TypedData::Handle(Z, script.kernel_string_data())); | 2246 helper.SetStringData(TypedData::Handle(Z, script.kernel_string_data())); |
2254 helper.SetCanonicalNames( | 2247 helper.SetCanonicalNames( |
2255 TypedData::Handle(Z, script.kernel_canonical_names())); | 2248 TypedData::Handle(Z, script.kernel_canonical_names())); |
2256 | 2249 |
2257 StreamingFlowGraphBuilder streaming_flow_graph_builder( | 2250 StreamingFlowGraphBuilder streaming_flow_graph_builder( |
2258 &helper, zone_, script.kernel_data(), script.kernel_data_size()); | 2251 &helper, zone_, function.kernel_offset(), |
2259 return streaming_flow_graph_builder.BuildParameterDescriptor( | 2252 TypedData::Handle(Z, function.kernel_body())); |
2260 function.kernel_offset()); | 2253 return streaming_flow_graph_builder.BuildParameterDescriptor(0); |
2261 } else { | 2254 } else { |
2262 Thread* thread = Thread::Current(); | 2255 Thread* thread = Thread::Current(); |
2263 Error& error = Error::Handle(); | 2256 Error& error = Error::Handle(); |
2264 error = thread->sticky_error(); | 2257 error = thread->sticky_error(); |
2265 thread->clear_sticky_error(); | 2258 thread->clear_sticky_error(); |
2266 return error.raw(); | 2259 return error.raw(); |
2267 } | 2260 } |
2268 } | 2261 } |
2269 | 2262 |
2270 static int LowestFirst(const intptr_t* a, const intptr_t* b) { | 2263 static int LowestFirst(const intptr_t* a, const intptr_t* b) { |
(...skipping 25 matching lines...) Expand all Loading... |
2296 Array& array_object = Array::Handle(); | 2289 Array& array_object = Array::Handle(); |
2297 array_object = Array::New(last + 1, Heap::kOld); | 2290 array_object = Array::New(last + 1, Heap::kOld); |
2298 Smi& smi_value = Smi::Handle(); | 2291 Smi& smi_value = Smi::Handle(); |
2299 for (intptr_t i = 0; i <= last; ++i) { | 2292 for (intptr_t i = 0; i <= last; ++i) { |
2300 smi_value = Smi::New(source->At(i)); | 2293 smi_value = Smi::New(source->At(i)); |
2301 array_object.SetAt(i, smi_value); | 2294 array_object.SetAt(i, smi_value); |
2302 } | 2295 } |
2303 return array_object.raw(); | 2296 return array_object.raw(); |
2304 } | 2297 } |
2305 | 2298 |
| 2299 void ProcessTokenPositionsEntry(const TypedData& body, |
| 2300 const Script& script, |
| 2301 const Script& entry_script, |
| 2302 intptr_t kernel_offset, |
| 2303 Zone* zone_, |
| 2304 TranslationHelper* helper, |
| 2305 GrowableArray<intptr_t>* token_positions, |
| 2306 GrowableArray<intptr_t>* yield_positions) { |
| 2307 if (body.IsNull() || |
| 2308 script.kernel_string_offsets() != entry_script.kernel_string_offsets()) { |
| 2309 return; |
| 2310 } |
| 2311 |
| 2312 StreamingFlowGraphBuilder streaming_flow_graph_builder(helper, zone_, |
| 2313 kernel_offset, body); |
| 2314 streaming_flow_graph_builder.CollectTokenPositionsFor( |
| 2315 script.kernel_script_index(), entry_script.kernel_script_index(), |
| 2316 token_positions, yield_positions); |
| 2317 } |
| 2318 |
2306 void CollectTokenPositionsFor(const Script& const_script) { | 2319 void CollectTokenPositionsFor(const Script& const_script) { |
2307 Thread* thread = Thread::Current(); | 2320 Thread* thread = Thread::Current(); |
2308 Zone* zone_ = thread->zone(); | 2321 Zone* zone_ = thread->zone(); |
2309 Script& script = Script::Handle(Z, const_script.raw()); | 2322 Script& script = Script::Handle(Z, const_script.raw()); |
2310 TranslationHelper helper(thread); | 2323 TranslationHelper helper(thread); |
2311 helper.SetStringOffsets(TypedData::Handle(Z, script.kernel_string_offsets())); | 2324 helper.SetStringOffsets(TypedData::Handle(Z, script.kernel_string_offsets())); |
2312 helper.SetStringData(TypedData::Handle(Z, script.kernel_string_data())); | 2325 helper.SetStringData(TypedData::Handle(Z, script.kernel_string_data())); |
2313 helper.SetCanonicalNames( | 2326 helper.SetCanonicalNames( |
2314 TypedData::Handle(Z, script.kernel_canonical_names())); | 2327 TypedData::Handle(Z, script.kernel_canonical_names())); |
2315 | 2328 |
2316 GrowableArray<intptr_t> token_positions(10); | 2329 GrowableArray<intptr_t> token_positions(10); |
2317 GrowableArray<intptr_t> yield_positions(1); | 2330 GrowableArray<intptr_t> yield_positions(1); |
2318 StreamingFlowGraphBuilder streaming_flow_graph_builder( | 2331 |
2319 &helper, zone_, script.kernel_data(), script.kernel_data_size()); | 2332 Isolate* isolate = thread->isolate(); |
2320 streaming_flow_graph_builder.CollectTokenPositionsFor( | 2333 const GrowableObjectArray& libs = |
2321 script.kernel_script_index(), &token_positions, &yield_positions); | 2334 GrowableObjectArray::Handle(Z, isolate->object_store()->libraries()); |
| 2335 Library& lib = Library::Handle(Z); |
| 2336 Object& entry = Object::Handle(); |
| 2337 Script& entry_script = Script::Handle(Z); |
| 2338 TypedData& body = TypedData::Handle(Z); |
| 2339 for (intptr_t i = 0; i < libs.Length(); i++) { |
| 2340 lib ^= libs.At(i); |
| 2341 DictionaryIterator it(lib); |
| 2342 while (it.HasNext()) { |
| 2343 entry = it.GetNext(); |
| 2344 body = TypedData::null(); |
| 2345 if (entry.IsClass()) { |
| 2346 const Class& klass = Class::Cast(entry); |
| 2347 entry_script = klass.script(); |
| 2348 if (!entry_script.IsNull() && script.kernel_script_index() == |
| 2349 entry_script.kernel_script_index()) { |
| 2350 token_positions.Add(klass.token_pos().value()); |
| 2351 } |
| 2352 Array& array = Array::Handle(zone_, klass.fields()); |
| 2353 dart::Field& field = dart::Field::Handle(Z); |
| 2354 for (intptr_t i = 0; i < array.Length(); ++i) { |
| 2355 field ^= array.At(i); |
| 2356 body = field.kernel_body(); |
| 2357 entry_script = field.Script(); |
| 2358 ProcessTokenPositionsEntry(body, script, entry_script, |
| 2359 field.kernel_offset(), zone_, &helper, |
| 2360 &token_positions, &yield_positions); |
| 2361 } |
| 2362 array = klass.functions(); |
| 2363 Function& function = Function::Handle(Z); |
| 2364 for (intptr_t i = 0; i < array.Length(); ++i) { |
| 2365 function ^= array.At(i); |
| 2366 body = function.kernel_body(); |
| 2367 entry_script = function.script(); |
| 2368 ProcessTokenPositionsEntry(body, script, entry_script, |
| 2369 function.kernel_offset(), zone_, &helper, |
| 2370 &token_positions, &yield_positions); |
| 2371 } |
| 2372 } else if (entry.IsFunction()) { |
| 2373 const Function& function = Function::Cast(entry); |
| 2374 body = function.kernel_body(); |
| 2375 entry_script = function.script(); |
| 2376 ProcessTokenPositionsEntry(body, script, entry_script, |
| 2377 function.kernel_offset(), zone_, &helper, |
| 2378 &token_positions, &yield_positions); |
| 2379 } else if (entry.IsField()) { |
| 2380 const dart::Field& field = dart::Field::Cast(entry); |
| 2381 body = field.kernel_body(); |
| 2382 entry_script = field.Script(); |
| 2383 ProcessTokenPositionsEntry(body, script, entry_script, |
| 2384 field.kernel_offset(), zone_, &helper, |
| 2385 &token_positions, &yield_positions); |
| 2386 } |
| 2387 } |
| 2388 } |
| 2389 |
2322 Array& array_object = Array::Handle(Z); | 2390 Array& array_object = Array::Handle(Z); |
2323 array_object = AsSortedDuplicateFreeArray(&token_positions); | 2391 array_object = AsSortedDuplicateFreeArray(&token_positions); |
2324 script.set_debug_positions(array_object); | 2392 script.set_debug_positions(array_object); |
2325 array_object = AsSortedDuplicateFreeArray(&yield_positions); | 2393 array_object = AsSortedDuplicateFreeArray(&yield_positions); |
2326 script.set_yield_positions(array_object); | 2394 script.set_yield_positions(array_object); |
2327 } | 2395 } |
2328 | 2396 |
2329 String& GetSourceFor(const Script& const_script) { | |
2330 Thread* thread = Thread::Current(); | |
2331 Zone* zone_ = thread->zone(); | |
2332 Script& script = Script::Handle(Z, const_script.raw()); | |
2333 TranslationHelper helper(thread); | |
2334 helper.SetStringOffsets(TypedData::Handle(Z, script.kernel_string_offsets())); | |
2335 helper.SetStringData(TypedData::Handle(Z, script.kernel_string_data())); | |
2336 helper.SetCanonicalNames( | |
2337 TypedData::Handle(Z, script.kernel_canonical_names())); | |
2338 | |
2339 StreamingFlowGraphBuilder streaming_flow_graph_builder( | |
2340 &helper, zone_, script.kernel_data(), script.kernel_data_size()); | |
2341 return streaming_flow_graph_builder.GetSourceFor( | |
2342 script.kernel_script_index()); | |
2343 } | |
2344 | |
2345 Array& GetLineStartsFor(const Script& const_script) { | |
2346 Thread* thread = Thread::Current(); | |
2347 Zone* zone_ = thread->zone(); | |
2348 Script& script = Script::Handle(Z, const_script.raw()); | |
2349 TranslationHelper helper(thread); | |
2350 helper.SetStringOffsets(TypedData::Handle(Z, script.kernel_string_offsets())); | |
2351 helper.SetStringData(TypedData::Handle(Z, script.kernel_string_data())); | |
2352 helper.SetCanonicalNames( | |
2353 TypedData::Handle(Z, script.kernel_canonical_names())); | |
2354 | |
2355 StreamingFlowGraphBuilder streaming_flow_graph_builder( | |
2356 &helper, zone_, script.kernel_data(), script.kernel_data_size()); | |
2357 return streaming_flow_graph_builder.GetLineStartsFor( | |
2358 script.kernel_script_index()); | |
2359 } | |
2360 | |
2361 } // namespace kernel | 2397 } // namespace kernel |
2362 } // namespace dart | 2398 } // namespace dart |
2363 | 2399 |
2364 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 2400 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
OLD | NEW |