Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: runtime/vm/kernel_binary.cc

Issue 2650333002: Revert "Removed usage of std::map and std::vector from kernel code. Issue #28064." (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | runtime/vm/kernel_reader.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #if !defined(DART_PRECOMPILED_RUNTIME) 4 #if !defined(DART_PRECOMPILED_RUNTIME)
5 5
6 #include <map>
7 #include <vector>
8
6 #include "platform/globals.h" 9 #include "platform/globals.h"
7 #include "vm/flags.h" 10 #include "vm/flags.h"
8 #include "vm/growable_array.h"
9 #include "vm/kernel.h" 11 #include "vm/kernel.h"
10 #include "vm/kernel_to_il.h"
11 #include "vm/os.h" 12 #include "vm/os.h"
12 13
13 #if defined(DEBUG) 14 #if defined(DEBUG)
14 #define TRACE_READ_OFFSET() \ 15 #define TRACE_READ_OFFSET() \
15 do { \ 16 do { \
16 if (FLAG_trace_kernel_binary) reader->DumpOffset(DART_PRETTY_FUNCTION); \ 17 if (FLAG_trace_kernel_binary) reader->DumpOffset(DART_PRETTY_FUNCTION); \
17 } while (0) 18 } while (0)
18 #else 19 #else
19 #define TRACE_READ_OFFSET() 20 #define TRACE_READ_OFFSET()
20 #endif 21 #endif
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 146
146 static const int SpecializedIntLiteralBias = 3; 147 static const int SpecializedIntLiteralBias = 3;
147 148
148 149
149 template <typename T> 150 template <typename T>
150 class BlockStack { 151 class BlockStack {
151 public: 152 public:
152 BlockStack() : current_count_(0) {} 153 BlockStack() : current_count_(0) {}
153 154
154 void EnterScope() { 155 void EnterScope() {
155 variable_count_.Add(current_count_); 156 variable_count_.push_back(current_count_);
156 current_count_ = 0; 157 current_count_ = 0;
157 } 158 }
158 159
159 void LeaveScope() { 160 void LeaveScope() {
160 variables_.TruncateTo(variables_.length() - current_count_); 161 variables_.resize(variables_.size() - current_count_);
161 current_count_ = variable_count_[variable_count_.length() - 1]; 162 current_count_ = variable_count_[variable_count_.size() - 1];
162 variable_count_.RemoveLast(); 163 variable_count_.pop_back();
163 } 164 }
164 165
165 T* Lookup(int index) { 166 T* Lookup(int index) {
166 ASSERT(index < variables_.length()); 167 ASSERT(static_cast<unsigned>(index) < variables_.size());
167 return variables_[index]; 168 return variables_[index];
168 } 169 }
169 170
170 void Push(T* v) { 171 void Push(T* v) {
171 variables_.Add(v); 172 variables_.push_back(v);
172 current_count_++; 173 current_count_++;
173 } 174 }
174 175
175 void Push(List<T>* decl) { 176 void Push(List<T>* decl) {
176 for (int i = 0; i < decl->length(); i++) { 177 for (int i = 0; i < decl->length(); i++) {
177 variables_.Add(decl[i]); 178 variables_.push_back(decl[i]);
178 current_count_++; 179 current_count_++;
179 } 180 }
180 } 181 }
181 182
182 void Pop(T* decl) { 183 void Pop(T* decl) {
183 variables_.RemoveLast(); 184 variables_.resize(variables_.size() - 1);
184 current_count_--; 185 current_count_--;
185 } 186 }
186 187
187 void Pop(List<T>* decl) { 188 void Pop(List<T>* decl) {
188 variables_.TruncateTo(variables_.length() - decl->length()); 189 variables_.resize(variables_.size() - decl->length());
189 current_count_ -= decl->length(); 190 current_count_ -= decl->length();
190 } 191 }
191 192
192 private: 193 private:
193 int current_count_; 194 int current_count_;
194 GrowableArray<T*> variables_; 195 std::vector<T*> variables_;
195 GrowableArray<int> variable_count_; 196 std::vector<int> variable_count_;
196 }; 197 };
197 198
198 199
199 template <typename T> 200 template <typename T>
200 class BlockMap { 201 class BlockMap {
201 public: 202 public:
202 BlockMap() : current_count_(0), stack_height_(0) {} 203 BlockMap() : current_count_(0), stack_height_(0) {}
203 204
204 void EnterScope() { 205 void EnterScope() {
205 variable_count_.Add(current_count_); 206 variable_count_.push_back(current_count_);
206 current_count_ = 0; 207 current_count_ = 0;
207 } 208 }
208 209
209 void LeaveScope() { 210 void LeaveScope() {
210 stack_height_ -= current_count_; 211 stack_height_ -= current_count_;
211 current_count_ = variable_count_[variable_count_.length() - 1]; 212 current_count_ = variable_count_[variable_count_.size() - 1];
212 variable_count_.RemoveLast(); 213 variable_count_.pop_back();
213 } 214 }
214 215
215 int Lookup(T* object) { 216 int Lookup(T* object) {
216 typename Map<T, int>::Pair* result = variables_.LookupPair(object); 217 ASSERT(variables_.find(object) != variables_.end());
217 ASSERT(result != NULL); 218 if (variables_.find(object) == variables_.end()) FATAL("lookup failure");
218 if (result == NULL) FATAL("lookup failure"); 219 return variables_[object];
219 return RawPointerKeyValueTrait<T, int>::ValueOf(*result);
220 } 220 }
221 221
222 void Push(T* v) { 222 void Push(T* v) {
223 ASSERT(variables_.LookupPair(v) == NULL);
224 int index = stack_height_++; 223 int index = stack_height_++;
225 variables_.Insert(v, index); 224 variables_[v] = index;
226 current_count_++; 225 current_count_++;
227 } 226 }
228 227
229 void Set(T* v, int index) { 228 void Set(T* v, int index) { variables_[v] = index; }
230 typename Map<T, int>::Pair* entry = variables_.LookupPair(v);
231 ASSERT(entry != NULL);
232 entry->value = index;
233 }
234 229
235 void Push(List<T>* decl) { 230 void Push(List<T>* decl) {
236 for (int i = 0; i < decl->length(); i++) { 231 for (int i = 0; i < decl->length(); i++) {
237 Push(decl[i]); 232 Push(decl[i]);
238 } 233 }
239 } 234 }
240 235
241 void Pop(T* v) { 236 void Pop(T* v) {
242 current_count_--; 237 current_count_--;
243 stack_height_--; 238 stack_height_--;
244 } 239 }
245 240
246 private: 241 private:
247 int current_count_; 242 int current_count_;
248 int stack_height_; 243 int stack_height_;
249 Map<T, int> variables_; 244 std::map<T*, int> variables_;
250 GrowableArray<int> variable_count_; 245 std::vector<int> variable_count_;
251 }; 246 };
252 247
253 248
254 template <typename T> 249 template <typename T>
255 class VariableScope { 250 class VariableScope {
256 public: 251 public:
257 explicit VariableScope(T* builder) : builder_(builder) { 252 explicit VariableScope(T* builder) : builder_(builder) {
258 builder_->variables().EnterScope(); 253 builder_->variables().EnterScope();
259 } 254 }
260 ~VariableScope() { builder_->variables().LeaveScope(); } 255 ~VariableScope() { builder_->variables().LeaveScope(); }
(...skipping 1631 matching lines...) Expand 10 before | Expand all | Expand 10 after
1892 1887
1893 kernel::Program* ReadPrecompiledKernelFromBuffer(const uint8_t* buffer, 1888 kernel::Program* ReadPrecompiledKernelFromBuffer(const uint8_t* buffer,
1894 intptr_t buffer_length) { 1889 intptr_t buffer_length) {
1895 kernel::Reader reader(buffer, buffer_length); 1890 kernel::Reader reader(buffer, buffer_length);
1896 return kernel::Program::ReadFrom(&reader); 1891 return kernel::Program::ReadFrom(&reader);
1897 } 1892 }
1898 1893
1899 1894
1900 } // namespace dart 1895 } // namespace dart
1901 #endif // !defined(DART_PRECOMPILED_RUNTIME) 1896 #endif // !defined(DART_PRECOMPILED_RUNTIME)
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/kernel_reader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698