OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_COMPILER_AST_GRAPH_BUILDER_H_ | 5 #ifndef V8_COMPILER_AST_GRAPH_BUILDER_H_ |
6 #define V8_COMPILER_AST_GRAPH_BUILDER_H_ | 6 #define V8_COMPILER_AST_GRAPH_BUILDER_H_ |
7 | 7 |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/ast.h" | 10 #include "src/ast.h" |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 int parameters_count() const { return parameters_count_; } | 196 int parameters_count() const { return parameters_count_; } |
197 int locals_count() const { return locals_count_; } | 197 int locals_count() const { return locals_count_; } |
198 int stack_height() { | 198 int stack_height() { |
199 return static_cast<int>(values()->size()) - parameters_count_ - | 199 return static_cast<int>(values()->size()) - parameters_count_ - |
200 locals_count_; | 200 locals_count_; |
201 } | 201 } |
202 | 202 |
203 // Operations on parameter or local variables. The parameter indices are | 203 // Operations on parameter or local variables. The parameter indices are |
204 // shifted by 1 (receiver is parameter index -1 but environment index 0). | 204 // shifted by 1 (receiver is parameter index -1 but environment index 0). |
205 void Bind(Variable* variable, Node* node) { | 205 void Bind(Variable* variable, Node* node) { |
206 ASSERT(variable->IsStackAllocated()); | 206 DCHECK(variable->IsStackAllocated()); |
207 if (variable->IsParameter()) { | 207 if (variable->IsParameter()) { |
208 values()->at(variable->index() + 1) = node; | 208 values()->at(variable->index() + 1) = node; |
209 parameters_dirty_ = true; | 209 parameters_dirty_ = true; |
210 } else { | 210 } else { |
211 ASSERT(variable->IsStackLocal()); | 211 DCHECK(variable->IsStackLocal()); |
212 values()->at(variable->index() + parameters_count_) = node; | 212 values()->at(variable->index() + parameters_count_) = node; |
213 locals_dirty_ = true; | 213 locals_dirty_ = true; |
214 } | 214 } |
215 } | 215 } |
216 Node* Lookup(Variable* variable) { | 216 Node* Lookup(Variable* variable) { |
217 ASSERT(variable->IsStackAllocated()); | 217 DCHECK(variable->IsStackAllocated()); |
218 if (variable->IsParameter()) { | 218 if (variable->IsParameter()) { |
219 return values()->at(variable->index() + 1); | 219 return values()->at(variable->index() + 1); |
220 } else { | 220 } else { |
221 ASSERT(variable->IsStackLocal()); | 221 DCHECK(variable->IsStackLocal()); |
222 return values()->at(variable->index() + parameters_count_); | 222 return values()->at(variable->index() + parameters_count_); |
223 } | 223 } |
224 } | 224 } |
225 | 225 |
226 // Operations on the operand stack. | 226 // Operations on the operand stack. |
227 void Push(Node* node) { | 227 void Push(Node* node) { |
228 values()->push_back(node); | 228 values()->push_back(node); |
229 stack_dirty_ = true; | 229 stack_dirty_ = true; |
230 } | 230 } |
231 Node* Top() { | 231 Node* Top() { |
232 ASSERT(stack_height() > 0); | 232 DCHECK(stack_height() > 0); |
233 return values()->back(); | 233 return values()->back(); |
234 } | 234 } |
235 Node* Pop() { | 235 Node* Pop() { |
236 ASSERT(stack_height() > 0); | 236 DCHECK(stack_height() > 0); |
237 Node* back = values()->back(); | 237 Node* back = values()->back(); |
238 values()->pop_back(); | 238 values()->pop_back(); |
239 return back; | 239 return back; |
240 } | 240 } |
241 | 241 |
242 // Direct mutations of the operand stack. | 242 // Direct mutations of the operand stack. |
243 void Poke(int depth, Node* node) { | 243 void Poke(int depth, Node* node) { |
244 ASSERT(depth >= 0 && depth < stack_height()); | 244 DCHECK(depth >= 0 && depth < stack_height()); |
245 int index = static_cast<int>(values()->size()) - depth - 1; | 245 int index = static_cast<int>(values()->size()) - depth - 1; |
246 values()->at(index) = node; | 246 values()->at(index) = node; |
247 } | 247 } |
248 Node* Peek(int depth) { | 248 Node* Peek(int depth) { |
249 ASSERT(depth >= 0 && depth < stack_height()); | 249 DCHECK(depth >= 0 && depth < stack_height()); |
250 int index = static_cast<int>(values()->size()) - depth - 1; | 250 int index = static_cast<int>(values()->size()) - depth - 1; |
251 return values()->at(index); | 251 return values()->at(index); |
252 } | 252 } |
253 void Drop(int depth) { | 253 void Drop(int depth) { |
254 ASSERT(depth >= 0 && depth <= stack_height()); | 254 DCHECK(depth >= 0 && depth <= stack_height()); |
255 values()->erase(values()->end() - depth, values()->end()); | 255 values()->erase(values()->end() - depth, values()->end()); |
256 } | 256 } |
257 | 257 |
258 // Preserve a checkpoint of the environment for the IR graph. Any | 258 // Preserve a checkpoint of the environment for the IR graph. Any |
259 // further mutation of the environment will not affect checkpoints. | 259 // further mutation of the environment will not affect checkpoints. |
260 Node* Checkpoint(BailoutId ast_id); | 260 Node* Checkpoint(BailoutId ast_id); |
261 | 261 |
262 private: | 262 private: |
263 int parameters_count_; | 263 int parameters_count_; |
264 int locals_count_; | 264 int locals_count_; |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 }; | 409 }; |
410 | 410 |
411 Scope* AstGraphBuilder::current_scope() const { | 411 Scope* AstGraphBuilder::current_scope() const { |
412 return execution_context_->scope(); | 412 return execution_context_->scope(); |
413 } | 413 } |
414 } | 414 } |
415 } | 415 } |
416 } // namespace v8::internal::compiler | 416 } // namespace v8::internal::compiler |
417 | 417 |
418 #endif // V8_COMPILER_AST_GRAPH_BUILDER_H_ | 418 #endif // V8_COMPILER_AST_GRAPH_BUILDER_H_ |
OLD | NEW |