| OLD | NEW | 
|---|
|  | (Empty) | 
| 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 |  | 
| 3 // found in the LICENSE file. |  | 
| 4 |  | 
| 5 #ifndef V8_UNITTESTS_COMPILER_INSTRUCTION_SELECTOR_TEST_H_ |  | 
| 6 #define V8_UNITTESTS_COMPILER_INSTRUCTION_SELECTOR_TEST_H_ |  | 
| 7 |  | 
| 8 #include <deque> |  | 
| 9 |  | 
| 10 #include "src/compiler/instruction-selector.h" |  | 
| 11 #include "src/compiler/raw-machine-assembler.h" |  | 
| 12 #include "test/unittests/test-zone.h" |  | 
| 13 |  | 
| 14 namespace v8 { |  | 
| 15 namespace internal { |  | 
| 16 namespace compiler { |  | 
| 17 |  | 
| 18 class InstructionSelectorTest : public ContextTest, public ZoneTest { |  | 
| 19  public: |  | 
| 20   InstructionSelectorTest() {} |  | 
| 21 |  | 
| 22  protected: |  | 
| 23   class Stream; |  | 
| 24 |  | 
| 25   enum StreamBuilderMode { kAllInstructions, kTargetInstructions }; |  | 
| 26 |  | 
| 27   class StreamBuilder : public RawMachineAssembler { |  | 
| 28    public: |  | 
| 29     StreamBuilder(InstructionSelectorTest* test, |  | 
| 30                   MachineRepresentation return_type) |  | 
| 31         : RawMachineAssembler(new (test->zone()) Graph(test->zone()), |  | 
| 32                               CallDescriptorBuilder(test->zone(), return_type)), |  | 
| 33           test_(test) {} |  | 
| 34 |  | 
| 35     Stream Build(StreamBuilderMode mode = kTargetInstructions); |  | 
| 36 |  | 
| 37    private: |  | 
| 38     MachineCallDescriptorBuilder* CallDescriptorBuilder( |  | 
| 39         Zone* zone, MachineRepresentation return_type) { |  | 
| 40       return new (zone) MachineCallDescriptorBuilder(return_type, 0, NULL); |  | 
| 41     } |  | 
| 42 |  | 
| 43    private: |  | 
| 44     InstructionSelectorTest* test_; |  | 
| 45   }; |  | 
| 46 |  | 
| 47   class Stream { |  | 
| 48    public: |  | 
| 49     size_t size() const { return instructions_.size(); } |  | 
| 50     const Instruction* operator[](size_t index) const { |  | 
| 51       EXPECT_LT(index, size()); |  | 
| 52       return instructions_[index]; |  | 
| 53     } |  | 
| 54 |  | 
| 55     int32_t ToInt32(const InstructionOperand* operand) const { |  | 
| 56       return ToConstant(operand).ToInt32(); |  | 
| 57     } |  | 
| 58 |  | 
| 59    private: |  | 
| 60     Constant ToConstant(const InstructionOperand* operand) const { |  | 
| 61       ConstantMap::const_iterator i; |  | 
| 62       if (operand->IsConstant()) { |  | 
| 63         i = constants_.find(operand->index()); |  | 
| 64         EXPECT_NE(constants_.end(), i); |  | 
| 65       } else { |  | 
| 66         EXPECT_EQ(InstructionOperand::IMMEDIATE, operand->kind()); |  | 
| 67         i = immediates_.find(operand->index()); |  | 
| 68         EXPECT_NE(immediates_.end(), i); |  | 
| 69       } |  | 
| 70       EXPECT_EQ(operand->index(), i->first); |  | 
| 71       return i->second; |  | 
| 72     } |  | 
| 73 |  | 
| 74     friend class StreamBuilder; |  | 
| 75 |  | 
| 76     typedef std::map<int, Constant> ConstantMap; |  | 
| 77 |  | 
| 78     ConstantMap constants_; |  | 
| 79     ConstantMap immediates_; |  | 
| 80     std::deque<Instruction*> instructions_; |  | 
| 81   }; |  | 
| 82 }; |  | 
| 83 |  | 
| 84 }  // namespace compiler |  | 
| 85 }  // namespace internal |  | 
| 86 }  // namespace v8 |  | 
| 87 |  | 
| 88 #endif  // V8_UNITTESTS_COMPILER_INSTRUCTION_SELECTOR_TEST_H_ |  | 
| OLD | NEW | 
|---|