OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 #ifndef RUNTIME_VM_KERNEL_BINARY_FLOWGRAPH_H_ | 5 #ifndef RUNTIME_VM_KERNEL_BINARY_FLOWGRAPH_H_ |
6 #define RUNTIME_VM_KERNEL_BINARY_FLOWGRAPH_H_ | 6 #define RUNTIME_VM_KERNEL_BINARY_FLOWGRAPH_H_ |
7 | 7 |
8 #if !defined(DART_PRECOMPILED_RUNTIME) | 8 #if !defined(DART_PRECOMPILED_RUNTIME) |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 StreamingFlowGraphBuilder* builder_; | 44 StreamingFlowGraphBuilder* builder_; |
45 Isolate* isolate_; | 45 Isolate* isolate_; |
46 Zone* zone_; | 46 Zone* zone_; |
47 TranslationHelper& translation_helper_; | 47 TranslationHelper& translation_helper_; |
48 // DartTypeTranslator& type_translator_; | 48 // DartTypeTranslator& type_translator_; |
49 | 49 |
50 Script& script_; | 50 Script& script_; |
51 Instance& result_; | 51 Instance& result_; |
52 }; | 52 }; |
53 | 53 |
| 54 |
54 class StreamingFlowGraphBuilder { | 55 class StreamingFlowGraphBuilder { |
55 public: | 56 public: |
56 StreamingFlowGraphBuilder(FlowGraphBuilder* flow_graph_builder, | 57 StreamingFlowGraphBuilder(FlowGraphBuilder* flow_graph_builder, |
57 const uint8_t* buffer, | 58 const uint8_t* buffer, |
58 intptr_t buffer_length) | 59 intptr_t buffer_length) |
59 : flow_graph_builder_(flow_graph_builder), | 60 : flow_graph_builder_(flow_graph_builder), |
60 translation_helper_(flow_graph_builder->translation_helper_), | 61 translation_helper_(flow_graph_builder->translation_helper_), |
61 zone_(flow_graph_builder->zone_), | 62 zone_(flow_graph_builder->zone_), |
62 reader_(new kernel::Reader(buffer, buffer_length)), | 63 reader_(new kernel::Reader(buffer, buffer_length)), |
63 constant_evaluator_(this, | 64 constant_evaluator_(this, |
64 flow_graph_builder->zone_, | 65 flow_graph_builder->zone_, |
65 &flow_graph_builder->translation_helper_, | 66 &flow_graph_builder->translation_helper_, |
66 &flow_graph_builder->type_translator_), | 67 &flow_graph_builder->type_translator_), |
67 string_table_offsets_(NULL), | 68 string_offset_count_(0), |
68 string_table_size_(-1), | 69 string_offsets_(NULL), |
69 string_table_entries_read_(0), | |
70 canonical_names_(NULL), | 70 canonical_names_(NULL), |
71 canonical_names_size_(-1), | 71 canonical_names_size_(-1), |
72 canonical_names_entries_read_(0), | 72 canonical_names_entries_read_(0), |
73 canonical_names_next_offset_(-1) {} | 73 canonical_names_next_offset_(-1) {} |
74 | 74 |
75 virtual ~StreamingFlowGraphBuilder() { | 75 virtual ~StreamingFlowGraphBuilder() { |
76 delete reader_; | 76 delete reader_; |
77 if (string_table_offsets_ != NULL) { | 77 delete[] string_offsets_; |
78 delete[] string_table_offsets_; | 78 // The canonical names themselves are not (yet) deallocated. |
79 } | 79 delete[] canonical_names_; |
80 if (canonical_names_ != NULL) { | |
81 // At least for now we'll leak whatever's inside | |
82 delete[] canonical_names_; | |
83 } | |
84 } | 80 } |
85 | 81 |
86 Fragment BuildAt(intptr_t kernel_offset); | 82 Fragment BuildAt(intptr_t kernel_offset); |
87 | 83 |
88 private: | 84 private: |
89 intptr_t GetStringTableOffset(intptr_t index); | 85 intptr_t GetStringOffset(intptr_t index); |
90 CanonicalName* GetCanonicalName(intptr_t index); | 86 CanonicalName* GetCanonicalName(intptr_t index); |
91 | 87 |
92 intptr_t ReaderOffset(); | 88 intptr_t ReaderOffset(); |
93 void SetOffset(intptr_t offset); | 89 void SetOffset(intptr_t offset); |
94 void SkipBytes(intptr_t skip); | 90 void SkipBytes(intptr_t skip); |
95 uint32_t ReadUInt(); | 91 uint32_t ReadUInt(); |
96 intptr_t ReadListLength(); | 92 intptr_t ReadListLength(); |
97 TokenPosition ReadPosition(bool record = true); | 93 TokenPosition ReadPosition(bool record = true); |
98 Tag ReadTag(uint8_t* payload = NULL); | 94 Tag ReadTag(uint8_t* payload = NULL); |
99 | 95 |
(...skipping 28 matching lines...) Expand all Loading... |
128 Fragment BuildIntLiteral(bool is_negative); | 124 Fragment BuildIntLiteral(bool is_negative); |
129 Fragment BuildDoubleLiteral(); | 125 Fragment BuildDoubleLiteral(); |
130 Fragment BuildBoolLiteral(bool value); | 126 Fragment BuildBoolLiteral(bool value); |
131 Fragment BuildNullLiteral(); | 127 Fragment BuildNullLiteral(); |
132 | 128 |
133 FlowGraphBuilder* flow_graph_builder_; | 129 FlowGraphBuilder* flow_graph_builder_; |
134 TranslationHelper& translation_helper_; | 130 TranslationHelper& translation_helper_; |
135 Zone* zone_; | 131 Zone* zone_; |
136 kernel::Reader* reader_; | 132 kernel::Reader* reader_; |
137 StreamingConstantEvaluator constant_evaluator_; | 133 StreamingConstantEvaluator constant_evaluator_; |
138 intptr_t* string_table_offsets_; | 134 |
139 intptr_t string_table_size_; | 135 // We build a table that gives us the start and end offsets of all the strings |
140 intptr_t string_table_entries_read_; | 136 // in the binary. |
| 137 // |
| 138 // The number of string offsets. Note that this is one more than the number |
| 139 // of strings in the binary. |
| 140 intptr_t string_offset_count_; |
| 141 |
| 142 // An array of offsets of size string_table_size_ + 1, in order to include the |
| 143 // end offset of the last string. The string with index N consists of the |
| 144 // UTF-8 encoded bytes stretching from string_table_offsets_[N] (enclusive) to |
| 145 // string_table_offsets_[N+1] (exclusive). |
| 146 intptr_t* string_offsets_; |
| 147 |
141 CanonicalName** canonical_names_; | 148 CanonicalName** canonical_names_; |
142 intptr_t canonical_names_size_; | 149 intptr_t canonical_names_size_; |
143 intptr_t canonical_names_entries_read_; | 150 intptr_t canonical_names_entries_read_; |
144 intptr_t canonical_names_next_offset_; | 151 intptr_t canonical_names_next_offset_; |
145 | 152 |
146 friend class StreamingConstantEvaluator; | 153 friend class StreamingConstantEvaluator; |
147 }; | 154 }; |
148 | 155 |
| 156 |
149 } // namespace kernel | 157 } // namespace kernel |
150 } // namespace dart | 158 } // namespace dart |
151 | 159 |
152 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 160 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
153 #endif // RUNTIME_VM_KERNEL_BINARY_FLOWGRAPH_H_ | 161 #endif // RUNTIME_VM_KERNEL_BINARY_FLOWGRAPH_H_ |
OLD | NEW |