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-register-allocator.h" | 10 #include "src/interpreter/bytecode-register-allocator.h" |
10 #include "src/interpreter/bytecodes.h" | 11 #include "src/interpreter/bytecodes.h" |
11 #include "src/interpreter/constant-array-builder.h" | 12 #include "src/interpreter/constant-array-builder.h" |
12 #include "src/interpreter/handler-table-builder.h" | 13 #include "src/interpreter/handler-table-builder.h" |
13 #include "src/interpreter/source-position-table.h" | 14 #include "src/interpreter/source-position-table.h" |
14 #include "src/zone-containers.h" | 15 #include "src/zone-containers.h" |
15 | 16 |
16 namespace v8 { | 17 namespace v8 { |
17 namespace internal { | 18 namespace internal { |
18 | 19 |
19 class Isolate; | 20 class Isolate; |
20 | 21 |
21 namespace interpreter { | 22 namespace interpreter { |
22 | 23 |
23 class BytecodeLabel; | 24 class BytecodeLabel; |
| 25 class BytecodePipelineStage; |
24 class Register; | 26 class Register; |
25 | 27 |
26 class BytecodeArrayBuilder final : public ZoneObject { | 28 class BytecodeArrayBuilder final : public ZoneObject { |
27 public: | 29 public: |
28 BytecodeArrayBuilder(Isolate* isolate, Zone* zone, int parameter_count, | 30 BytecodeArrayBuilder(Isolate* isolate, Zone* zone, int parameter_count, |
29 int context_count, int locals_count, | 31 int context_count, int locals_count, |
30 FunctionLiteral* literal = nullptr); | 32 FunctionLiteral* literal = nullptr); |
31 | 33 |
32 Handle<BytecodeArray> ToBytecodeArray(); | 34 Handle<BytecodeArray> ToBytecodeArray(); |
33 | 35 |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 // entry, so that it can be referenced by above exception handling support. | 257 // entry, so that it can be referenced by above exception handling support. |
256 int NewHandlerEntry() { return handler_table_builder()->NewHandlerEntry(); } | 258 int NewHandlerEntry() { return handler_table_builder()->NewHandlerEntry(); } |
257 | 259 |
258 void InitializeReturnPosition(FunctionLiteral* literal); | 260 void InitializeReturnPosition(FunctionLiteral* literal); |
259 | 261 |
260 void SetStatementPosition(Statement* stmt); | 262 void SetStatementPosition(Statement* stmt); |
261 void SetExpressionPosition(Expression* expr); | 263 void SetExpressionPosition(Expression* expr); |
262 void SetExpressionAsStatementPosition(Expression* expr); | 264 void SetExpressionAsStatementPosition(Expression* expr); |
263 | 265 |
264 // Accessors | 266 // Accessors |
265 Zone* zone() const { return zone_; } | |
266 TemporaryRegisterAllocator* temporary_register_allocator() { | 267 TemporaryRegisterAllocator* temporary_register_allocator() { |
267 return &temporary_allocator_; | 268 return &temporary_allocator_; |
268 } | 269 } |
269 const TemporaryRegisterAllocator* temporary_register_allocator() const { | 270 const TemporaryRegisterAllocator* temporary_register_allocator() const { |
270 return &temporary_allocator_; | 271 return &temporary_allocator_; |
271 } | 272 } |
| 273 Zone* zone() const { return zone_; } |
272 | 274 |
273 void EnsureReturn(); | 275 void EnsureReturn(); |
274 | 276 |
275 static OperandScale OperandSizesToScale( | |
276 OperandSize size0, OperandSize size1 = OperandSize::kByte, | |
277 OperandSize size2 = OperandSize::kByte, | |
278 OperandSize size3 = OperandSize::kByte); | |
279 | |
280 static OperandSize SizeForRegisterOperand(Register reg); | |
281 static OperandSize SizeForSignedOperand(int value); | |
282 static OperandSize SizeForUnsignedOperand(int value); | |
283 static OperandSize SizeForUnsignedOperand(size_t value); | |
284 | |
285 static uint32_t RegisterOperand(Register reg); | 277 static uint32_t RegisterOperand(Register reg); |
286 static Register RegisterFromOperand(uint32_t operand); | 278 static Register RegisterFromOperand(uint32_t operand); |
287 static uint32_t SignedOperand(int value, OperandSize size); | 279 static uint32_t SignedOperand(int value, OperandSize size); |
288 static uint32_t UnsignedOperand(int value); | 280 static uint32_t UnsignedOperand(int value); |
289 static uint32_t UnsignedOperand(size_t value); | 281 static uint32_t UnsignedOperand(size_t value); |
290 | 282 |
291 private: | 283 private: |
292 class PreviousBytecodeHelper; | |
293 friend class BytecodeRegisterAllocator; | 284 friend class BytecodeRegisterAllocator; |
294 | 285 |
295 static Bytecode BytecodeForBinaryOperation(Token::Value op); | 286 static Bytecode BytecodeForBinaryOperation(Token::Value op); |
296 static Bytecode BytecodeForCountOperation(Token::Value op); | 287 static Bytecode BytecodeForCountOperation(Token::Value op); |
297 static Bytecode BytecodeForCompareOperation(Token::Value op); | 288 static Bytecode BytecodeForCompareOperation(Token::Value op); |
298 static Bytecode BytecodeForStoreIC(LanguageMode language_mode); | 289 static Bytecode BytecodeForStoreIC(LanguageMode language_mode); |
299 static Bytecode BytecodeForKeyedStoreIC(LanguageMode language_mode); | 290 static Bytecode BytecodeForKeyedStoreIC(LanguageMode language_mode); |
300 static Bytecode BytecodeForLoadGlobal(TypeofMode typeof_mode); | 291 static Bytecode BytecodeForLoadGlobal(TypeofMode typeof_mode); |
301 static Bytecode BytecodeForStoreGlobal(LanguageMode language_mode); | 292 static Bytecode BytecodeForStoreGlobal(LanguageMode language_mode); |
302 static Bytecode BytecodeForStoreLookupSlot(LanguageMode language_mode); | 293 static Bytecode BytecodeForStoreLookupSlot(LanguageMode language_mode); |
303 static Bytecode BytecodeForCreateArguments(CreateArgumentsType type); | 294 static Bytecode BytecodeForCreateArguments(CreateArgumentsType type); |
304 static Bytecode BytecodeForDelete(LanguageMode language_mode); | 295 static Bytecode BytecodeForDelete(LanguageMode language_mode); |
305 static Bytecode BytecodeForCall(TailCallMode tail_call_mode); | 296 static Bytecode BytecodeForCall(TailCallMode tail_call_mode); |
306 | 297 |
307 static Bytecode GetJumpWithConstantOperand(Bytecode jump_smi8_operand); | 298 static Bytecode GetJumpWithConstantOperand(Bytecode jump_smi8_operand); |
308 static Bytecode GetJumpWithToBoolean(Bytecode jump_smi8_operand); | |
309 | 299 |
310 template <size_t N> | |
311 INLINE(void Output(Bytecode bytecode, uint32_t (&operands)[N], | |
312 OperandScale operand_scale = OperandScale::kSingle)); | |
313 void Output(Bytecode bytecode); | 300 void Output(Bytecode bytecode); |
314 void OutputScaled(Bytecode bytecode, OperandScale operand_scale, | 301 void OutputScaled(Bytecode bytecode, OperandScale operand_scale, |
315 uint32_t operand0, uint32_t operand1, uint32_t operand2, | 302 uint32_t operand0, uint32_t operand1, uint32_t operand2, |
316 uint32_t operand3); | 303 uint32_t operand3); |
317 void OutputScaled(Bytecode bytecode, OperandScale operand_scale, | 304 void OutputScaled(Bytecode bytecode, OperandScale operand_scale, |
318 uint32_t operand0, uint32_t operand1, uint32_t operand2); | 305 uint32_t operand0, uint32_t operand1, uint32_t operand2); |
319 void OutputScaled(Bytecode bytecode, OperandScale operand_scale, | 306 void OutputScaled(Bytecode bytecode, OperandScale operand_scale, |
320 uint32_t operand0, uint32_t operand1); | 307 uint32_t operand0, uint32_t operand1); |
321 void OutputScaled(Bytecode bytecode, OperandScale operand_scale, | 308 void OutputScaled(Bytecode bytecode, OperandScale operand_scale, |
322 uint32_t operand0); | 309 uint32_t operand0); |
323 | 310 |
324 BytecodeArrayBuilder& OutputJump(Bytecode jump_bytecode, | 311 BytecodeArrayBuilder& OutputJump(Bytecode jump_bytecode, |
325 BytecodeLabel* label); | 312 BytecodeLabel* label); |
326 void PatchJump(const ZoneVector<uint8_t>::iterator& jump_target, | 313 void PatchJump(size_t jump_target, size_t jump_location); |
327 const ZoneVector<uint8_t>::iterator& jump_location); | 314 void PatchJumpWith8BitOperand(ZoneVector<uint8_t>* bytecodes, |
328 void PatchIndirectJumpWith8BitOperand( | 315 size_t jump_location, int delta); |
329 const ZoneVector<uint8_t>::iterator& jump_location, int delta); | 316 void PatchJumpWith16BitOperand(ZoneVector<uint8_t>* bytecodes, |
330 void PatchIndirectJumpWith16BitOperand( | 317 size_t jump_location, int delta); |
331 const ZoneVector<uint8_t>::iterator& jump_location, int delta); | 318 void PatchJumpWith32BitOperand(ZoneVector<uint8_t>* bytecodes, |
332 void PatchIndirectJumpWith32BitOperand( | 319 size_t jump_location, int delta); |
333 const ZoneVector<uint8_t>::iterator& jump_location, int delta); | |
334 | 320 |
335 void LeaveBasicBlock(); | 321 void LeaveBasicBlock(); |
336 | 322 |
337 bool OperandIsValid(Bytecode bytecode, OperandScale operand_scale, | 323 bool OperandIsValid(Bytecode bytecode, OperandScale operand_scale, |
338 int operand_index, uint32_t operand_value) const; | 324 int operand_index, uint32_t operand_value) const; |
339 bool RegisterIsValid(Register reg, OperandSize reg_size) const; | 325 bool RegisterIsValid(Register reg, OperandSize reg_size) const; |
340 | 326 |
341 bool LastBytecodeInSameBlock() const; | |
342 bool NeedToBooleanCast(); | |
343 bool IsRegisterInAccumulator(Register reg); | |
344 | |
345 // Set position for return. | 327 // Set position for return. |
346 void SetReturnPosition(); | 328 void SetReturnPosition(); |
347 | 329 |
348 // Gets a constant pool entry for the |object|. | 330 // Gets a constant pool entry for the |object|. |
349 size_t GetConstantPoolEntry(Handle<Object> object); | 331 size_t GetConstantPoolEntry(Handle<Object> object); |
350 | 332 |
351 ZoneVector<uint8_t>* bytecodes() { return &bytecodes_; } | |
352 const ZoneVector<uint8_t>* bytecodes() const { return &bytecodes_; } | |
353 Isolate* isolate() const { return isolate_; } | 333 Isolate* isolate() const { return isolate_; } |
| 334 BytecodeArrayWriter* bytecode_array_writer() { |
| 335 return &bytecode_array_writer_; |
| 336 } |
| 337 BytecodePipelineStage* pipeline() { return pipeline_; } |
354 ConstantArrayBuilder* constant_array_builder() { | 338 ConstantArrayBuilder* constant_array_builder() { |
355 return &constant_array_builder_; | 339 return &constant_array_builder_; |
356 } | 340 } |
357 const ConstantArrayBuilder* constant_array_builder() const { | 341 const ConstantArrayBuilder* constant_array_builder() const { |
358 return &constant_array_builder_; | 342 return &constant_array_builder_; |
359 } | 343 } |
360 HandlerTableBuilder* handler_table_builder() { | 344 HandlerTableBuilder* handler_table_builder() { |
361 return &handler_table_builder_; | 345 return &handler_table_builder_; |
362 } | 346 } |
363 SourcePositionTableBuilder* source_position_table_builder() { | 347 SourcePositionTableBuilder* source_position_table_builder() { |
364 return &source_position_table_builder_; | 348 return &source_position_table_builder_; |
365 } | 349 } |
366 | 350 |
367 Isolate* isolate_; | 351 Isolate* isolate_; |
368 Zone* zone_; | 352 Zone* zone_; |
369 ZoneVector<uint8_t> bytecodes_; | |
370 bool bytecode_generated_; | 353 bool bytecode_generated_; |
371 ConstantArrayBuilder constant_array_builder_; | 354 ConstantArrayBuilder constant_array_builder_; |
372 HandlerTableBuilder handler_table_builder_; | 355 HandlerTableBuilder handler_table_builder_; |
373 SourcePositionTableBuilder source_position_table_builder_; | 356 SourcePositionTableBuilder source_position_table_builder_; |
374 size_t last_block_end_; | |
375 size_t last_bytecode_start_; | |
376 bool exit_seen_in_block_; | 357 bool exit_seen_in_block_; |
377 int unbound_jumps_; | 358 int unbound_jumps_; |
378 int parameter_count_; | 359 int parameter_count_; |
379 int local_register_count_; | 360 int local_register_count_; |
380 int context_register_count_; | 361 int context_register_count_; |
381 int return_position_; | 362 int return_position_; |
382 TemporaryRegisterAllocator temporary_allocator_; | 363 TemporaryRegisterAllocator temporary_allocator_; |
| 364 BytecodeArrayWriter bytecode_array_writer_; |
| 365 BytecodePipelineStage* pipeline_; |
| 366 BytecodeSourceInfo latest_source_info_; |
383 | 367 |
384 DISALLOW_COPY_AND_ASSIGN(BytecodeArrayBuilder); | 368 DISALLOW_COPY_AND_ASSIGN(BytecodeArrayBuilder); |
385 }; | 369 }; |
386 | 370 |
387 | 371 |
388 // A label representing a branch target in a bytecode array. When a | 372 // A label representing a branch target in a bytecode array. When a |
389 // label is bound, it represents a known position in the bytecode | 373 // label is bound, it represents a known position in the bytecode |
390 // array. For labels that are forward references there can be at most | 374 // array. For labels that are forward references there can be at most |
391 // one reference whilst it is unbound. | 375 // one reference whilst it is unbound. |
392 class BytecodeLabel final { | 376 class BytecodeLabel final { |
(...skipping 30 matching lines...) Expand all Loading... |
423 size_t offset_; | 407 size_t offset_; |
424 | 408 |
425 friend class BytecodeArrayBuilder; | 409 friend class BytecodeArrayBuilder; |
426 }; | 410 }; |
427 | 411 |
428 } // namespace interpreter | 412 } // namespace interpreter |
429 } // namespace internal | 413 } // namespace internal |
430 } // namespace v8 | 414 } // namespace v8 |
431 | 415 |
432 #endif // V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ | 416 #endif // V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ |
OLD | NEW |