Chromium Code Reviews| Index: src/interpreter/bytecode-array-builder.h |
| diff --git a/src/interpreter/bytecode-array-builder.h b/src/interpreter/bytecode-array-builder.h |
| index f7a8dddebd3f77d78cc90ce58264ad3736b3be4e..e224d2975cb47589875842e4b9c32329fe29550e 100644 |
| --- a/src/interpreter/bytecode-array-builder.h |
| +++ b/src/interpreter/bytecode-array-builder.h |
| @@ -20,6 +20,7 @@ class Isolate; |
| namespace interpreter { |
| +class BytecodeLabel; |
| class Register; |
| class BytecodeArrayBuilder { |
| @@ -43,6 +44,8 @@ class BytecodeArrayBuilder { |
| // Constant loads to accumulator. |
| BytecodeArrayBuilder& LoadLiteral(v8::internal::Smi* value); |
| BytecodeArrayBuilder& LoadLiteral(Handle<Object> object); |
| + BytecodeArrayBuilder& LoadLiteral(int value); |
|
rmcilroy
2015/09/18 10:42:23
I would prefer not to add this since it's not clea
oth
2015/09/23 10:46:55
Done. The intent was to enable writing slightly cl
|
| + BytecodeArrayBuilder& LoadLiteral(double value); |
| BytecodeArrayBuilder& LoadUndefined(); |
| BytecodeArrayBuilder& LoadNull(); |
| BytecodeArrayBuilder& LoadTheHole(); |
| @@ -74,21 +77,50 @@ class BytecodeArrayBuilder { |
| BytecodeArrayBuilder& Call(Register callable, Register receiver, |
| size_t arg_count); |
| - // Operators. |
| + // Operators (register == lhs, accumulator = rhs). |
| BytecodeArrayBuilder& BinaryOperation(Token::Value binop, Register reg); |
| + BytecodeArrayBuilder& Add(Register reg); |
| + BytecodeArrayBuilder& Subtract(Register reg); |
| + BytecodeArrayBuilder& Multiply(Register reg); |
| + BytecodeArrayBuilder& Divide(Register reg); |
| + BytecodeArrayBuilder& Modulo(Register reg); |
| + |
| + // Tests. |
| + BytecodeArrayBuilder& CompareOperation(Token::Value op, Register reg); |
| // Flow Control. |
| + BytecodeArrayBuilder& Bind(BytecodeLabel* label); |
| + BytecodeArrayBuilder& Jump(BytecodeLabel* label); |
| + BytecodeArrayBuilder& JumpIfTrue(BytecodeLabel* label); |
| + BytecodeArrayBuilder& JumpIfFalse(BytecodeLabel* label); |
| BytecodeArrayBuilder& Return(); |
| private: |
| static Bytecode BytecodeForBinaryOperation(Token::Value op); |
| - static bool FitsInByteOperand(int value); |
| - static bool FitsInByteOperand(size_t value); |
| - |
| - void Output(Bytecode bytecode, uint8_t r0, uint8_t r1, uint8_t r2); |
| - void Output(Bytecode bytecode, uint8_t r0, uint8_t r1); |
| - void Output(Bytecode bytecode, uint8_t r0); |
| + static Bytecode BytecodeForCompareOperation(Token::Value op); |
| + static bool FitsInIdxOperand(int value); |
| + static bool FitsInIdxOperand(size_t value); |
| + static bool FitsInImm8Operand(int value); |
| + static bool IsJumpWithSmi8Operand(Bytecode jump_bytecode); |
| + static Bytecode GetJumpWithConstantOperand(Bytecode jump_with_smi8_operand); |
| + |
| + ZoneVector<uint8_t>* bytecodes() { return &bytecodes_; } |
| + const ZoneVector<uint8_t>* bytecodes() const { return &bytecodes_; } |
| + Isolate* isolate() const { return isolate_; } |
| + |
| + template <size_t N> |
| + void RawOutputAt(ZoneVector<uint8_t>::iterator pos, uint8_t(&bytes)[N]); |
| + void Output(const ZoneVector<uint8_t>::iterator& pos, Bytecode bytecode, |
| + uint8_t operand); |
| + void Output(Bytecode bytecode, uint8_t operand0, uint8_t operand1, |
| + uint8_t operand2); |
| + void Output(Bytecode bytecode, uint8_t operand0, uint8_t operand1); |
| + void Output(Bytecode bytecode, uint8_t operand0); |
| void Output(Bytecode bytecode); |
| + void OutputJump(Bytecode jump_bytecode, |
| + const ZoneVector<uint8_t>::iterator& jump_location, |
| + const ZoneVector<uint8_t>::iterator& jump_target); |
| + BytecodeArrayBuilder& Jump(Bytecode jump_bytecode, BytecodeLabel* label); |
| bool OperandIsValid(Bytecode bytecode, int operand_index, |
| uint8_t operand_value) const; |
| @@ -104,6 +136,8 @@ class BytecodeArrayBuilder { |
| IdentityMap<size_t> constants_map_; |
| ZoneVector<Handle<Object>> constants_; |
| + ZoneSet<BytecodeLabel*> forward_labels_; |
| + ZoneSet<BytecodeLabel*> bound_labels_; |
| int parameter_count_; |
| int local_register_count_; |
| @@ -114,6 +148,31 @@ class BytecodeArrayBuilder { |
| DISALLOW_IMPLICIT_CONSTRUCTORS(BytecodeArrayBuilder); |
| }; |
| + |
| +// A label representing a branch target in a bytecode array. When a |
| +// label is bound, it represents a known position in the bytecode |
| +// array. For labels that are forward references there can be at most |
| +// one reference whilst it is unbound. |
| +class BytecodeLabel { |
| + public: |
| + static const size_t kUnbound = 0; |
| + BytecodeLabel() : offset_(kUnbound) {} |
| + |
| + private: |
| + // For forward references |offset_| is the offset of the branch that |
| + // refers to this label. For bound references it is the offset of |
| + // the label itself in the bytecode array. |
| + size_t offset_; |
| + |
| + INLINE(void bind_to(size_t offset)) { offset_ = offset; } |
| + INLINE(size_t offset() const) { return offset_; } |
| + |
| + friend class BytecodeArrayBuilder; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(BytecodeLabel); |
| +}; |
| + |
| + |
| // A stack-allocated class than allows the instantiator to allocate |
| // temporary registers that are cleaned up when scope is closed. |
| class TemporaryRegisterScope { |