| 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 <vector> | |
| 9 | |
| 10 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
| 11 #include "src/identity-map.h" | |
| 12 #include "src/interpreter/bytecodes.h" | 9 #include "src/interpreter/bytecodes.h" |
| 13 #include "src/zone.h" | 10 #include "src/interpreter/constant-array-builder.h" |
| 14 #include "src/zone-containers.h" | 11 #include "src/zone-containers.h" |
| 15 | 12 |
| 16 namespace v8 { | 13 namespace v8 { |
| 17 namespace internal { | 14 namespace internal { |
| 18 | 15 |
| 19 class Isolate; | 16 class Isolate; |
| 20 | 17 |
| 21 namespace interpreter { | 18 namespace interpreter { |
| 22 | 19 |
| 23 class BytecodeLabel; | 20 class BytecodeLabel; |
| 21 class ConstantArrayBuilder; |
| 24 class Register; | 22 class Register; |
| 25 | 23 |
| 26 // TODO(rmcilroy): Unify this with CreateArgumentsParameters::Type in Turbofan | 24 // TODO(rmcilroy): Unify this with CreateArgumentsParameters::Type in Turbofan |
| 27 // when rest parameters implementation has settled down. | 25 // when rest parameters implementation has settled down. |
| 28 enum class CreateArgumentsType { kMappedArguments, kUnmappedArguments }; | 26 enum class CreateArgumentsType { kMappedArguments, kUnmappedArguments }; |
| 29 | 27 |
| 30 class BytecodeArrayBuilder final { | 28 class BytecodeArrayBuilder final { |
| 31 public: | 29 public: |
| 32 BytecodeArrayBuilder(Isolate* isolate, Zone* zone); | 30 BytecodeArrayBuilder(Isolate* isolate, Zone* zone); |
| 33 ~BytecodeArrayBuilder(); | 31 ~BytecodeArrayBuilder(); |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 Register cache_array, Register index); | 220 Register cache_array, Register index); |
| 223 BytecodeArrayBuilder& ForInStep(Register index); | 221 BytecodeArrayBuilder& ForInStep(Register index); |
| 224 | 222 |
| 225 // Accessors | 223 // Accessors |
| 226 Zone* zone() const { return zone_; } | 224 Zone* zone() const { return zone_; } |
| 227 | 225 |
| 228 private: | 226 private: |
| 229 ZoneVector<uint8_t>* bytecodes() { return &bytecodes_; } | 227 ZoneVector<uint8_t>* bytecodes() { return &bytecodes_; } |
| 230 const ZoneVector<uint8_t>* bytecodes() const { return &bytecodes_; } | 228 const ZoneVector<uint8_t>* bytecodes() const { return &bytecodes_; } |
| 231 Isolate* isolate() const { return isolate_; } | 229 Isolate* isolate() const { return isolate_; } |
| 230 ConstantArrayBuilder* constant_array_builder() { |
| 231 return &constant_array_builder_; |
| 232 } |
| 233 const ConstantArrayBuilder* constant_array_builder() const { |
| 234 return &constant_array_builder_; |
| 235 } |
| 232 | 236 |
| 233 static Bytecode BytecodeForBinaryOperation(Token::Value op); | 237 static Bytecode BytecodeForBinaryOperation(Token::Value op); |
| 234 static Bytecode BytecodeForCountOperation(Token::Value op); | 238 static Bytecode BytecodeForCountOperation(Token::Value op); |
| 235 static Bytecode BytecodeForCompareOperation(Token::Value op); | 239 static Bytecode BytecodeForCompareOperation(Token::Value op); |
| 236 static Bytecode BytecodeForWideOperands(Bytecode bytecode); | 240 static Bytecode BytecodeForWideOperands(Bytecode bytecode); |
| 237 static Bytecode BytecodeForLoadIC(LanguageMode language_mode); | 241 static Bytecode BytecodeForLoadIC(LanguageMode language_mode); |
| 238 static Bytecode BytecodeForKeyedLoadIC(LanguageMode language_mode); | 242 static Bytecode BytecodeForKeyedLoadIC(LanguageMode language_mode); |
| 239 static Bytecode BytecodeForStoreIC(LanguageMode language_mode); | 243 static Bytecode BytecodeForStoreIC(LanguageMode language_mode); |
| 240 static Bytecode BytecodeForKeyedStoreIC(LanguageMode language_mode); | 244 static Bytecode BytecodeForKeyedStoreIC(LanguageMode language_mode); |
| 241 static Bytecode BytecodeForLoadGlobal(LanguageMode language_mode, | 245 static Bytecode BytecodeForLoadGlobal(LanguageMode language_mode, |
| 242 TypeofMode typeof_mode); | 246 TypeofMode typeof_mode); |
| 243 static Bytecode BytecodeForStoreGlobal(LanguageMode language_mode); | 247 static Bytecode BytecodeForStoreGlobal(LanguageMode language_mode); |
| 244 static Bytecode BytecodeForStoreLookupSlot(LanguageMode language_mode); | 248 static Bytecode BytecodeForStoreLookupSlot(LanguageMode language_mode); |
| 245 static Bytecode BytecodeForCreateArguments(CreateArgumentsType type); | 249 static Bytecode BytecodeForCreateArguments(CreateArgumentsType type); |
| 246 static Bytecode BytecodeForDelete(LanguageMode language_mode); | 250 static Bytecode BytecodeForDelete(LanguageMode language_mode); |
| 247 | 251 |
| 248 static bool FitsInIdx8Operand(int value); | 252 static bool FitsInIdx8Operand(int value); |
| 249 static bool FitsInIdx8Operand(size_t value); | 253 static bool FitsInIdx8Operand(size_t value); |
| 250 static bool FitsInImm8Operand(int value); | 254 static bool FitsInImm8Operand(int value); |
| 251 static bool FitsInIdx16Operand(int value); | 255 static bool FitsInIdx16Operand(int value); |
| 252 static bool FitsInIdx16Operand(size_t value); | 256 static bool FitsInIdx16Operand(size_t value); |
| 253 static bool FitsInReg8Operand(Register value); | 257 static bool FitsInReg8Operand(Register value); |
| 254 static bool FitsInReg16Operand(Register value); | 258 static bool FitsInReg16Operand(Register value); |
| 255 | 259 |
| 256 static Bytecode GetJumpWithConstantOperand(Bytecode jump_with_smi8_operand); | 260 static Bytecode GetJumpWithConstantOperand(Bytecode jump_smi8_operand); |
| 257 static Bytecode GetJumpWithToBoolean(Bytecode jump); | 261 static Bytecode GetJumpWithConstantWideOperand(Bytecode jump_smi8_operand); |
| 262 static Bytecode GetJumpWithToBoolean(Bytecode jump_smi8_operand); |
| 258 | 263 |
| 259 Register MapRegister(Register reg); | 264 Register MapRegister(Register reg); |
| 260 Register MapRegisters(Register reg, Register args_base, int args_length = 1); | 265 Register MapRegisters(Register reg, Register args_base, int args_length = 1); |
| 261 | 266 |
| 262 template <size_t N> | 267 template <size_t N> |
| 263 INLINE(void Output(Bytecode bytecode, uint32_t(&operands)[N])); | 268 INLINE(void Output(Bytecode bytecode, uint32_t(&operands)[N])); |
| 264 void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1, | 269 void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1, |
| 265 uint32_t operand2, uint32_t operand3); | 270 uint32_t operand2, uint32_t operand3); |
| 266 void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1, | 271 void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1, |
| 267 uint32_t operand2); | 272 uint32_t operand2); |
| 268 void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1); | 273 void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1); |
| 269 void Output(Bytecode bytecode, uint32_t operand0); | 274 void Output(Bytecode bytecode, uint32_t operand0); |
| 270 void Output(Bytecode bytecode); | 275 void Output(Bytecode bytecode); |
| 271 | 276 |
| 272 BytecodeArrayBuilder& OutputJump(Bytecode jump_bytecode, | 277 BytecodeArrayBuilder& OutputJump(Bytecode jump_bytecode, |
| 273 BytecodeLabel* label); | 278 BytecodeLabel* label); |
| 274 void PatchJump(const ZoneVector<uint8_t>::iterator& jump_target, | 279 void PatchJump(const ZoneVector<uint8_t>::iterator& jump_target, |
| 275 ZoneVector<uint8_t>::iterator jump_location); | 280 const ZoneVector<uint8_t>::iterator& jump_location); |
| 281 void PatchIndirectJumpWith8BitOperand( |
| 282 const ZoneVector<uint8_t>::iterator& jump_location, int delta); |
| 283 void PatchIndirectJumpWith16BitOperand( |
| 284 const ZoneVector<uint8_t>::iterator& jump_location, int delta); |
| 276 | 285 |
| 277 void LeaveBasicBlock(); | 286 void LeaveBasicBlock(); |
| 278 void EnsureReturn(); | 287 void EnsureReturn(); |
| 279 | 288 |
| 280 bool OperandIsValid(Bytecode bytecode, int operand_index, | 289 bool OperandIsValid(Bytecode bytecode, int operand_index, |
| 281 uint32_t operand_value) const; | 290 uint32_t operand_value) const; |
| 282 bool LastBytecodeInSameBlock() const; | 291 bool LastBytecodeInSameBlock() const; |
| 283 | 292 |
| 284 bool NeedToBooleanCast(); | 293 bool NeedToBooleanCast(); |
| 285 bool IsRegisterInAccumulator(Register reg); | 294 bool IsRegisterInAccumulator(Register reg); |
| 286 | 295 |
| 296 // Temporary register management. |
| 287 int BorrowTemporaryRegister(); | 297 int BorrowTemporaryRegister(); |
| 288 int BorrowTemporaryRegisterNotInRange(int start_index, int end_index); | 298 int BorrowTemporaryRegisterNotInRange(int start_index, int end_index); |
| 289 int AllocateAndBorrowTemporaryRegister(); | 299 int AllocateAndBorrowTemporaryRegister(); |
| 290 void ReturnTemporaryRegister(int reg_index); | 300 void ReturnTemporaryRegister(int reg_index); |
| 291 int PrepareForConsecutiveTemporaryRegisters(size_t count); | 301 int PrepareForConsecutiveTemporaryRegisters(size_t count); |
| 292 void BorrowConsecutiveTemporaryRegister(int reg_index); | 302 void BorrowConsecutiveTemporaryRegister(int reg_index); |
| 293 bool TemporaryRegisterIsLive(Register reg) const; | 303 bool TemporaryRegisterIsLive(Register reg) const; |
| 294 | 304 |
| 295 Register first_temporary_register() const; | 305 Register first_temporary_register() const; |
| 296 Register last_temporary_register() const; | 306 Register last_temporary_register() const; |
| 297 | 307 |
| 298 // Gets a constant pool entry for the |object|. | 308 // Gets a constant pool entry for the |object|. |
| 299 size_t GetConstantPoolEntry(Handle<Object> object); | 309 size_t GetConstantPoolEntry(Handle<Object> object); |
| 300 | 310 |
| 301 Isolate* isolate_; | 311 Isolate* isolate_; |
| 302 Zone* zone_; | 312 Zone* zone_; |
| 303 ZoneVector<uint8_t> bytecodes_; | 313 ZoneVector<uint8_t> bytecodes_; |
| 304 bool bytecode_generated_; | 314 bool bytecode_generated_; |
| 315 ConstantArrayBuilder constant_array_builder_; |
| 305 size_t last_block_end_; | 316 size_t last_block_end_; |
| 306 size_t last_bytecode_start_; | 317 size_t last_bytecode_start_; |
| 307 bool exit_seen_in_block_; | 318 bool exit_seen_in_block_; |
| 308 int unbound_jumps_; | 319 int unbound_jumps_; |
| 309 | 320 |
| 310 IdentityMap<size_t> constants_map_; | |
| 311 ZoneVector<Handle<Object>> constants_; | |
| 312 | |
| 313 int parameter_count_; | 321 int parameter_count_; |
| 314 int local_register_count_; | 322 int local_register_count_; |
| 315 int context_register_count_; | 323 int context_register_count_; |
| 316 int temporary_register_count_; | 324 int temporary_register_count_; |
| 317 | |
| 318 ZoneSet<int> free_temporaries_; | 325 ZoneSet<int> free_temporaries_; |
| 319 | 326 |
| 320 class PreviousBytecodeHelper; | 327 class PreviousBytecodeHelper; |
| 321 friend class TemporaryRegisterScope; | 328 friend class TemporaryRegisterScope; |
| 322 DISALLOW_COPY_AND_ASSIGN(BytecodeArrayBuilder); | 329 DISALLOW_COPY_AND_ASSIGN(BytecodeArrayBuilder); |
| 323 }; | 330 }; |
| 324 | 331 |
| 325 | 332 |
| 326 // A label representing a branch target in a bytecode array. When a | 333 // A label representing a branch target in a bytecode array. When a |
| 327 // label is bound, it represents a known position in the bytecode | 334 // label is bound, it represents a known position in the bytecode |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 | 401 |
| 395 DISALLOW_COPY_AND_ASSIGN(TemporaryRegisterScope); | 402 DISALLOW_COPY_AND_ASSIGN(TemporaryRegisterScope); |
| 396 }; | 403 }; |
| 397 | 404 |
| 398 | 405 |
| 399 } // namespace interpreter | 406 } // namespace interpreter |
| 400 } // namespace internal | 407 } // namespace internal |
| 401 } // namespace v8 | 408 } // namespace v8 |
| 402 | 409 |
| 403 #endif // V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ | 410 #endif // V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ |
| OLD | NEW |