OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ | 5 #ifndef V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ |
6 #define V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ | 6 #define V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ |
7 | 7 |
8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
9 #include "src/interpreter/bytecode-array-writer.h" | 9 #include "src/interpreter/bytecode-array-writer.h" |
10 #include "src/interpreter/bytecode-register-allocator.h" | 10 #include "src/interpreter/bytecode-register-allocator.h" |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 // entry, so that it can be referenced by above exception handling support. | 302 // entry, so that it can be referenced by above exception handling support. |
303 int NewHandlerEntry() { return handler_table_builder()->NewHandlerEntry(); } | 303 int NewHandlerEntry() { return handler_table_builder()->NewHandlerEntry(); } |
304 | 304 |
305 // Allocates a slot in the constant pool which can later be inserted. | 305 // Allocates a slot in the constant pool which can later be inserted. |
306 size_t AllocateConstantPoolEntry(); | 306 size_t AllocateConstantPoolEntry(); |
307 // Inserts a entry into an allocated constant pool entry. | 307 // Inserts a entry into an allocated constant pool entry. |
308 void InsertConstantPoolEntryAt(size_t entry, Handle<Object> object); | 308 void InsertConstantPoolEntryAt(size_t entry, Handle<Object> object); |
309 | 309 |
310 void InitializeReturnPosition(FunctionLiteral* literal); | 310 void InitializeReturnPosition(FunctionLiteral* literal); |
311 | 311 |
312 void SetStatementPosition(Statement* stmt); | 312 void SetStatementPosition(Statement* stmt) { |
313 void SetExpressionPosition(Expression* expr); | 313 if (stmt->position() == kNoSourcePosition) return; |
314 void SetExpressionAsStatementPosition(Expression* expr); | 314 latest_source_info_.MakeStatementPosition(stmt->position()); |
| 315 } |
| 316 |
| 317 void SetExpressionPosition(Expression* expr) { |
| 318 if (expr->position() == kNoSourcePosition) return; |
| 319 if (!latest_source_info_.is_statement()) { |
| 320 // Ensure the current expression position is overwritten with the |
| 321 // latest value. |
| 322 latest_source_info_.MakeExpressionPosition(expr->position()); |
| 323 } |
| 324 } |
| 325 |
| 326 void SetExpressionAsStatementPosition(Expression* expr) { |
| 327 if (expr->position() == kNoSourcePosition) return; |
| 328 latest_source_info_.MakeStatementPosition(expr->position()); |
| 329 } |
315 | 330 |
316 // Accessors | 331 // Accessors |
317 TemporaryRegisterAllocator* temporary_register_allocator() { | 332 TemporaryRegisterAllocator* temporary_register_allocator() { |
318 return &temporary_allocator_; | 333 return &temporary_allocator_; |
319 } | 334 } |
320 const TemporaryRegisterAllocator* temporary_register_allocator() const { | 335 const TemporaryRegisterAllocator* temporary_register_allocator() const { |
321 return &temporary_allocator_; | 336 return &temporary_allocator_; |
322 } | 337 } |
323 Zone* zone() const { return zone_; } | 338 Zone* zone() const { return zone_; } |
324 | 339 |
(...skipping 13 matching lines...) Expand all Loading... |
338 } | 353 } |
339 | 354 |
340 static uint32_t UnsignedOperand(size_t value) { | 355 static uint32_t UnsignedOperand(size_t value) { |
341 DCHECK_LE(value, kMaxUInt32); | 356 DCHECK_LE(value, kMaxUInt32); |
342 return static_cast<uint32_t>(value); | 357 return static_cast<uint32_t>(value); |
343 } | 358 } |
344 | 359 |
345 private: | 360 private: |
346 friend class BytecodeRegisterAllocator; | 361 friend class BytecodeRegisterAllocator; |
347 | 362 |
348 static Bytecode BytecodeForBinaryOperation(Token::Value op); | 363 INLINE(void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1, |
349 static Bytecode BytecodeForCountOperation(Token::Value op); | 364 uint32_t operand2, uint32_t operand3)); |
350 static Bytecode BytecodeForCompareOperation(Token::Value op); | 365 INLINE(void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1, |
351 static Bytecode BytecodeForStoreNamedProperty(LanguageMode language_mode); | 366 uint32_t operand2)); |
352 static Bytecode BytecodeForStoreKeyedProperty(LanguageMode language_mode); | 367 INLINE(void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1)); |
353 static Bytecode BytecodeForLoadGlobal(TypeofMode typeof_mode); | 368 INLINE(void Output(Bytecode bytecode, uint32_t operand0)); |
354 static Bytecode BytecodeForStoreGlobal(LanguageMode language_mode); | 369 INLINE(void Output(Bytecode bytecode)); |
355 static Bytecode BytecodeForStoreLookupSlot(LanguageMode language_mode); | |
356 static Bytecode BytecodeForCreateArguments(CreateArgumentsType type); | |
357 static Bytecode BytecodeForDelete(LanguageMode language_mode); | |
358 static Bytecode BytecodeForCall(TailCallMode tail_call_mode); | |
359 | 370 |
360 void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1, | 371 INLINE(void OutputJump(Bytecode bytecode, BytecodeLabel* label)); |
361 uint32_t operand2, uint32_t operand3); | 372 INLINE(void OutputJump(Bytecode bytecode, uint32_t operand0, |
362 void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1, | 373 BytecodeLabel* label)); |
363 uint32_t operand2); | |
364 void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1); | |
365 void Output(Bytecode bytecode, uint32_t operand0); | |
366 void Output(Bytecode bytecode); | |
367 | |
368 BytecodeArrayBuilder& OutputJump(BytecodeNode* node, BytecodeLabel* label); | |
369 | 374 |
370 bool RegisterIsValid(Register reg) const; | 375 bool RegisterIsValid(Register reg) const; |
371 bool OperandsAreValid(Bytecode bytecode, int operand_count, | 376 bool OperandsAreValid(Bytecode bytecode, int operand_count, |
372 uint32_t operand0 = 0, uint32_t operand1 = 0, | 377 uint32_t operand0 = 0, uint32_t operand1 = 0, |
373 uint32_t operand2 = 0, uint32_t operand3 = 0) const; | 378 uint32_t operand2 = 0, uint32_t operand3 = 0) const; |
374 | 379 |
375 // Attach latest source position to |node|. | |
376 void AttachSourceInfo(BytecodeNode* node); | |
377 | |
378 // Set position for return. | 380 // Set position for return. |
379 void SetReturnPosition(); | 381 void SetReturnPosition(); |
380 | 382 |
381 // Gets a constant pool entry for the |object|. | 383 // Gets a constant pool entry for the |object|. |
382 size_t GetConstantPoolEntry(Handle<Object> object); | 384 size_t GetConstantPoolEntry(Handle<Object> object); |
383 | 385 |
384 // Not implemented as the illegal bytecode is used inside internally | 386 // Not implemented as the illegal bytecode is used inside internally |
385 // to indicate a bytecode field is not valid or an error has occured | 387 // to indicate a bytecode field is not valid or an error has occured |
386 // during bytecode generation. | 388 // during bytecode generation. |
387 BytecodeArrayBuilder& Illegal(); | 389 BytecodeArrayBuilder& Illegal(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 static int const kNoFeedbackSlot = 0; | 421 static int const kNoFeedbackSlot = 0; |
420 | 422 |
421 DISALLOW_COPY_AND_ASSIGN(BytecodeArrayBuilder); | 423 DISALLOW_COPY_AND_ASSIGN(BytecodeArrayBuilder); |
422 }; | 424 }; |
423 | 425 |
424 } // namespace interpreter | 426 } // namespace interpreter |
425 } // namespace internal | 427 } // namespace internal |
426 } // namespace v8 | 428 } // namespace v8 |
427 | 429 |
428 #endif // V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ | 430 #endif // V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ |
OLD | NEW |