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 "vm/kernel_binary_flowgraph.h" | 5 #include "vm/kernel_binary_flowgraph.h" |
6 | 6 |
7 #include "vm/object_store.h" | 7 #include "vm/object_store.h" |
8 | 8 |
9 #if !defined(DART_PRECOMPILED_RUNTIME) | 9 #if !defined(DART_PRECOMPILED_RUNTIME) |
10 | 10 |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
300 return BuildBoolLiteral(false); | 300 return BuildBoolLiteral(false); |
301 case kNullLiteral: | 301 case kNullLiteral: |
302 return BuildNullLiteral(); | 302 return BuildNullLiteral(); |
303 default: | 303 default: |
304 UNREACHABLE(); | 304 UNREACHABLE(); |
305 } | 305 } |
306 | 306 |
307 return Fragment(); | 307 return Fragment(); |
308 } | 308 } |
309 | 309 |
310 intptr_t StreamingFlowGraphBuilder::GetStringTableOffset(intptr_t index) { | 310 intptr_t StreamingFlowGraphBuilder::GetStringOffset(intptr_t index) { |
311 if (string_table_offsets_ != NULL && string_table_entries_read_ > index) { | 311 if (string_offsets_ == NULL) { |
312 return string_table_offsets_[index]; | 312 intptr_t saved_offset = ReaderOffset(); |
313 reader_->set_offset(4); // Skip kMagicProgramFile to the string table. | |
314 string_offset_count_ = ReadListLength() + 1; | |
315 string_offsets_ = new intptr_t[string_offset_count_]; | |
316 | |
317 // Build a table of the 0-based string start and end offsets. | |
318 string_offsets_[0] = 0; | |
319 for (intptr_t i = 1; i < string_offset_count_; ++i) { | |
320 string_offsets_[i] = ReadUInt(); | |
321 } | |
322 // And adjust the offsets now that we know the start offset of the first | |
323 // string relative to the start of the binary. | |
324 intptr_t base = ReaderOffset(); | |
jensj
2017/04/04 09:42:16
One could also save the base as a class variable a
| |
325 for (intptr_t i = 0; i < string_offset_count_; ++i) { | |
326 string_offsets_[i] += base; | |
327 } | |
328 | |
329 SetOffset(saved_offset); | |
313 } | 330 } |
314 | 331 return string_offsets_[index]; |
315 intptr_t saved_offset = ReaderOffset(); | |
316 if (string_table_offsets_ == NULL) { | |
317 reader_->set_offset(4); // Skip kMagicProgramFile - now at string table. | |
318 string_table_size_ = ReadListLength(); | |
319 string_table_offsets_ = new intptr_t[string_table_size_]; | |
320 string_table_offsets_[0] = ReaderOffset(); | |
321 string_table_entries_read_ = 1; | |
322 } | |
323 | |
324 ASSERT(string_table_size_ > index); | |
325 --string_table_entries_read_; | |
326 reader_->set_offset(string_table_offsets_[string_table_entries_read_]); | |
327 for (; string_table_entries_read_ < index; ++string_table_entries_read_) { | |
328 string_table_offsets_[string_table_entries_read_] = ReaderOffset(); | |
329 uint32_t bytes = ReadUInt(); | |
330 SkipBytes(bytes); | |
331 } | |
332 string_table_offsets_[string_table_entries_read_] = ReaderOffset(); | |
333 ++string_table_entries_read_; | |
334 | |
335 SetOffset(saved_offset); | |
336 return string_table_offsets_[index]; | |
337 } | 332 } |
338 | 333 |
339 CanonicalName* StreamingFlowGraphBuilder::GetCanonicalName(intptr_t index) { | 334 CanonicalName* StreamingFlowGraphBuilder::GetCanonicalName(intptr_t index) { |
340 if (index == 0) return NULL; | 335 if (index == 0) return NULL; |
341 --index; | 336 --index; |
342 | 337 |
343 if (canonical_names_ != NULL && canonical_names_entries_read_ > index) { | 338 if (canonical_names_ != NULL && canonical_names_entries_read_ > index) { |
344 return canonical_names_[index]; | 339 return canonical_names_[index]; |
345 } | 340 } |
346 | 341 |
347 intptr_t saved_offset = ReaderOffset(); | 342 intptr_t saved_offset = ReaderOffset(); |
348 if (canonical_names_ == NULL) { | 343 if (canonical_names_ == NULL) { |
349 // Find offset from where to read canonical names table. | 344 // Find offset from where to read canonical names table. |
350 | 345 |
351 // First skip the string table: | 346 // First skip the string table. The last offset is the end offset of the |
352 // Get first string to make sure we have the table size, get last string and | 347 // last string. |
353 // read it to get past the string table. | 348 if (string_offsets_ == NULL) { |
354 // Note that this will also cache all string positions. | 349 // Ensure that the length and all the offsets are available. |
355 GetStringTableOffset(0); | 350 GetStringOffset(0); |
356 SetOffset(GetStringTableOffset(string_table_size_ - 1)); | 351 } |
357 uint32_t bytes = ReadUInt(); | 352 SetOffset(GetStringOffset(string_offset_count_ - 1)); |
358 SkipBytes(bytes); | |
359 | 353 |
360 // Another string table (source URIs) | 354 // There is another string table for the source URIs. Skip it as well. |
361 intptr_t list_length = ReadListLength(); | 355 intptr_t list_length = ReadListLength(); |
356 intptr_t end_offset = 0; | |
362 for (intptr_t i = 0; i < list_length; ++i) { | 357 for (intptr_t i = 0; i < list_length; ++i) { |
363 uint32_t bytes = ReadUInt(); | 358 end_offset = ReadUInt(); |
jensj
2017/04/04 09:42:16
Should this be "+=", or should the SkipBytes be ca
jensj
2017/04/04 09:52:59
Ignore that comment... The string table starts wit
| |
364 SkipBytes(bytes); | |
365 } | 359 } |
360 SkipBytes(end_offset); | |
366 | 361 |
367 // Source code table | 362 // Source code table |
368 for (intptr_t i = 0; i < list_length; ++i) { | 363 for (intptr_t i = 0; i < list_length; ++i) { |
369 // Source code | 364 // Source code |
370 intptr_t bytes = ReadUInt(); | 365 intptr_t bytes = ReadUInt(); |
371 SkipBytes(bytes); | 366 SkipBytes(bytes); |
372 | 367 |
373 // Line starts table | 368 // Line starts table |
374 intptr_t line_count = ReadUInt(); | 369 intptr_t line_count = ReadUInt(); |
375 for (intptr_t j = 0; j < line_count; ++j) { | 370 for (intptr_t j = 0; j < line_count; ++j) { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
443 } | 438 } |
444 | 439 |
445 ScopeBuildingResult* StreamingFlowGraphBuilder::scopes() { | 440 ScopeBuildingResult* StreamingFlowGraphBuilder::scopes() { |
446 return flow_graph_builder_->scopes_; | 441 return flow_graph_builder_->scopes_; |
447 } | 442 } |
448 | 443 |
449 ParsedFunction* StreamingFlowGraphBuilder::parsed_function() { | 444 ParsedFunction* StreamingFlowGraphBuilder::parsed_function() { |
450 return flow_graph_builder_->parsed_function_; | 445 return flow_graph_builder_->parsed_function_; |
451 } | 446 } |
452 | 447 |
453 dart::String& StreamingFlowGraphBuilder::DartSymbol(intptr_t str_index) { | 448 dart::String& StreamingFlowGraphBuilder::DartSymbol(intptr_t index) { |
454 intptr_t saved_offset = ReaderOffset(); | 449 intptr_t start = GetStringOffset(index); |
455 | 450 intptr_t end = GetStringOffset(index + 1); |
456 SetOffset(GetStringTableOffset(str_index)); | 451 return H.DartSymbol(reader_->buffer() + start, end - start); |
457 uint32_t bytes = ReadUInt(); | |
458 const uint8_t* data = &reader_->buffer()[ReaderOffset()]; | |
459 | |
460 SetOffset(saved_offset); | |
461 return H.DartSymbol(data, bytes); | |
462 } | 452 } |
463 | 453 |
464 dart::String& StreamingFlowGraphBuilder::DartString(intptr_t str_index) { | 454 dart::String& StreamingFlowGraphBuilder::DartString(intptr_t index) { |
465 intptr_t saved_offset = ReaderOffset(); | 455 intptr_t start = GetStringOffset(index); |
466 | 456 intptr_t end = GetStringOffset(index + 1); |
467 SetOffset(GetStringTableOffset(str_index)); | 457 return H.DartString(reader_->buffer() + start, end - start); |
468 uint32_t bytes = ReadUInt(); | |
469 const uint8_t* data = &reader_->buffer()[ReaderOffset()]; | |
470 | |
471 SetOffset(saved_offset); | |
472 return H.DartString(data, bytes); | |
473 } | 458 } |
474 | 459 |
475 String* StreamingFlowGraphBuilder::KernelString(intptr_t str_index) { | 460 String* StreamingFlowGraphBuilder::KernelString(intptr_t index) { |
476 intptr_t savedOffset = ReaderOffset(); | 461 intptr_t start = GetStringOffset(index); |
477 | 462 intptr_t end = GetStringOffset(index + 1); |
478 SetOffset(GetStringTableOffset(str_index)); | 463 return new String(reader_->buffer() + start, end - start); |
479 uint32_t bytes = ReadUInt(); | |
480 const uint8_t* data = &reader_->buffer()[ReaderOffset()]; | |
481 | |
482 SetOffset(savedOffset); | |
483 return new String(data, bytes); | |
484 } | 464 } |
485 | 465 |
486 Fragment StreamingFlowGraphBuilder::DebugStepCheck(TokenPosition position) { | 466 Fragment StreamingFlowGraphBuilder::DebugStepCheck(TokenPosition position) { |
487 return flow_graph_builder_->DebugStepCheck(position); | 467 return flow_graph_builder_->DebugStepCheck(position); |
488 } | 468 } |
489 | 469 |
490 Fragment StreamingFlowGraphBuilder::LoadLocal(LocalVariable* variable) { | 470 Fragment StreamingFlowGraphBuilder::LoadLocal(LocalVariable* variable) { |
491 return flow_graph_builder_->LoadLocal(variable); | 471 return flow_graph_builder_->LoadLocal(variable); |
492 } | 472 } |
493 | 473 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
621 } | 601 } |
622 | 602 |
623 Fragment StreamingFlowGraphBuilder::BuildNullLiteral() { | 603 Fragment StreamingFlowGraphBuilder::BuildNullLiteral() { |
624 return Constant(Instance::ZoneHandle(Z, Instance::null())); | 604 return Constant(Instance::ZoneHandle(Z, Instance::null())); |
625 } | 605 } |
626 | 606 |
627 } // namespace kernel | 607 } // namespace kernel |
628 } // namespace dart | 608 } // namespace dart |
629 | 609 |
630 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 610 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
OLD | NEW |