| 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 #if !defined(DART_PRECOMPILED_RUNTIME) | 4 #if !defined(DART_PRECOMPILED_RUNTIME) |
| 5 | 5 |
| 6 #include <map> | 6 #include <map> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "platform/globals.h" | 9 #include "platform/globals.h" |
| 10 #include "vm/flags.h" | 10 #include "vm/flags.h" |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 current_count_--; | 185 current_count_--; |
| 186 } | 186 } |
| 187 | 187 |
| 188 void Pop(List<T>* decl) { | 188 void Pop(List<T>* decl) { |
| 189 variables_.resize(variables_.size() - decl->length()); | 189 variables_.resize(variables_.size() - decl->length()); |
| 190 current_count_ -= decl->length(); | 190 current_count_ -= decl->length(); |
| 191 } | 191 } |
| 192 | 192 |
| 193 private: | 193 private: |
| 194 int current_count_; | 194 int current_count_; |
| 195 MallocGrowableArray<T*> variables_; | 195 std::vector<T*> variables_; |
| 196 MallocGrowableArray<int> variable_count_; | 196 std::vector<int> variable_count_; |
| 197 }; | 197 }; |
| 198 | 198 |
| 199 | 199 |
| 200 template <typename T> | 200 template <typename T> |
| 201 class BlockMap { | 201 class BlockMap { |
| 202 public: | 202 public: |
| 203 BlockMap() : current_count_(0), stack_height_(0) {} | 203 BlockMap() : current_count_(0), stack_height_(0) {} |
| 204 | 204 |
| 205 void EnterScope() { | 205 void EnterScope() { |
| 206 variable_count_.push_back(current_count_); | 206 variable_count_.push_back(current_count_); |
| 207 current_count_ = 0; | 207 current_count_ = 0; |
| 208 } | 208 } |
| 209 | 209 |
| 210 void LeaveScope() { | 210 void LeaveScope() { |
| 211 stack_height_ -= current_count_; | 211 stack_height_ -= current_count_; |
| 212 current_count_ = variable_count_[variable_count_.size() - 1]; | 212 current_count_ = variable_count_[variable_count_.size() - 1]; |
| 213 variable_count_.pop_back(); | 213 variable_count_.pop_back(); |
| 214 } | 214 } |
| 215 | 215 |
| 216 int Lookup(T* object) { | 216 int Lookup(T* object) { |
| 217 typename MallocMap<T, int>::Pair* result = variables_.LookupPair(object); | 217 ASSERT(variables_.find(object) != variables_.end()); |
| 218 ASSERT(result != NULL); | 218 if (variables_.find(object) == variables_.end()) FATAL("lookup failure"); |
| 219 if (result == NULL) FATAL("lookup failure"); | 219 return variables_[object]; |
| 220 return RawPointerKeyValueTrait<T, int>::ValueOf(*result); | |
| 221 } | 220 } |
| 222 | 221 |
| 223 void Push(T* v) { | 222 void Push(T* v) { |
| 224 int index = stack_height_++; | 223 int index = stack_height_++; |
| 225 variables_[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 MallocMap<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 MallocMap<T, int> variables_; | 244 std::map<T*, int> variables_; |
| 250 MallocGrowableArray<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 Loading... |
| 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) |
| OLD | NEW |