| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 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 | 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 #include "test/unittests/compiler/node-test-utils.h" | 5 #include "test/unittests/compiler/node-test-utils.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "src/assembler.h" | 9 #include "src/assembler.h" |
| 10 #include "src/compiler/common-operator.h" | 10 #include "src/compiler/common-operator.h" |
| 11 #include "src/compiler/js-operator.h" | 11 #include "src/compiler/js-operator.h" |
| 12 #include "src/compiler/node-properties.h" | 12 #include "src/compiler/node-properties.h" |
| 13 #include "src/compiler/simplified-operator.h" | 13 #include "src/compiler/simplified-operator.h" |
| 14 #include "src/handles-inl.h" | 14 #include "src/handles-inl.h" |
| 15 #include "src/objects.h" | 15 #include "src/objects.h" |
| 16 | 16 |
| 17 using testing::_; | 17 using testing::_; |
| 18 using testing::MakeMatcher; | 18 using testing::MakeMatcher; |
| 19 using testing::MatcherInterface; | 19 using testing::MatcherInterface; |
| 20 using testing::MatchResultListener; | 20 using testing::MatchResultListener; |
| 21 using testing::StringMatchResultListener; | 21 using testing::StringMatchResultListener; |
| 22 | 22 |
| 23 namespace v8 { | 23 namespace v8 { |
| 24 namespace internal { | 24 namespace internal { |
| 25 | 25 |
| 26 bool operator==(Handle<HeapObject> const& lhs, Handle<HeapObject> const& rhs) { | 26 bool operator==(Handle<HeapObject> const& lhs, Handle<HeapObject> const& rhs) { |
| 27 return lhs.is_identical_to(rhs); | 27 return lhs.is_identical_to(rhs); |
| 28 } | 28 } |
| 29 | 29 |
| 30 | |
| 31 namespace compiler { | 30 namespace compiler { |
| 32 | 31 |
| 33 namespace { | 32 namespace { |
| 34 | 33 |
| 35 template <typename T> | 34 template <typename T> |
| 36 bool PrintMatchAndExplain(const T& value, const std::string& value_name, | 35 bool PrintMatchAndExplain(const T& value, const std::string& value_name, |
| 37 const Matcher<T>& value_matcher, | 36 const Matcher<T>& value_matcher, |
| 38 MatchResultListener* listener) { | 37 MatchResultListener* listener) { |
| 39 StringMatchResultListener value_listener; | 38 StringMatchResultListener value_listener; |
| 40 if (!value_matcher.MatchAndExplain(value, &value_listener)) { | 39 if (!value_matcher.MatchAndExplain(value, &value_listener)) { |
| (...skipping 1810 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1851 effect_matcher_, listener) && | 1850 effect_matcher_, listener) && |
| 1852 PrintMatchAndExplain(NodeProperties::GetControlInput(node), | 1851 PrintMatchAndExplain(NodeProperties::GetControlInput(node), |
| 1853 "control", control_matcher_, listener)); | 1852 "control", control_matcher_, listener)); |
| 1854 } | 1853 } |
| 1855 | 1854 |
| 1856 private: | 1855 private: |
| 1857 const std::vector<Matcher<Node*>> value_matchers_; | 1856 const std::vector<Matcher<Node*>> value_matchers_; |
| 1858 const Matcher<Node*> effect_matcher_; | 1857 const Matcher<Node*> effect_matcher_; |
| 1859 const Matcher<Node*> control_matcher_; | 1858 const Matcher<Node*> control_matcher_; |
| 1860 }; | 1859 }; |
| 1861 | |
| 1862 | |
| 1863 class IsCreateClosureMatcher final : public NodeMatcher { | |
| 1864 public: | |
| 1865 IsCreateClosureMatcher( | |
| 1866 const Matcher<Handle<SharedFunctionInfo>>& shared_info_matcher, | |
| 1867 const Matcher<PretenureFlag>& pretenure_matcher, | |
| 1868 const Matcher<Node*>& effect_matcher, | |
| 1869 const Matcher<Node*>& control_matcher) | |
| 1870 : NodeMatcher(IrOpcode::Value::kJSCreateClosure), | |
| 1871 shared_info_matcher_(shared_info_matcher), | |
| 1872 pretenure_matcher_(pretenure_matcher), | |
| 1873 effect_matcher_(effect_matcher), | |
| 1874 control_matcher_(control_matcher) {} | |
| 1875 | |
| 1876 void DescribeTo(std::ostream* os) const final { | |
| 1877 NodeMatcher::DescribeTo(os); | |
| 1878 *os << " whose value ("; | |
| 1879 shared_info_matcher_.DescribeTo(os); | |
| 1880 *os << ","; | |
| 1881 pretenure_matcher_.DescribeTo(os); | |
| 1882 *os << "), effect ("; | |
| 1883 effect_matcher_.DescribeTo(os); | |
| 1884 *os << ") and control ("; | |
| 1885 control_matcher_.DescribeTo(os); | |
| 1886 *os << ")"; | |
| 1887 } | |
| 1888 | |
| 1889 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final { | |
| 1890 if (!NodeMatcher::MatchAndExplain(node, listener)) { | |
| 1891 return false; | |
| 1892 } | |
| 1893 return (PrintMatchAndExplain( | |
| 1894 OpParameter<const CreateClosureParameters>(node).shared_info(), | |
| 1895 "value", shared_info_matcher_, listener) && | |
| 1896 PrintMatchAndExplain( | |
| 1897 OpParameter<CreateClosureParameters>(node).pretenure(), "value", | |
| 1898 pretenure_matcher_, listener) && | |
| 1899 PrintMatchAndExplain(NodeProperties::GetEffectInput(node), "effect", | |
| 1900 effect_matcher_, listener) && | |
| 1901 PrintMatchAndExplain(NodeProperties::GetControlInput(node), | |
| 1902 "control", control_matcher_, listener)); | |
| 1903 } | |
| 1904 | |
| 1905 private: | |
| 1906 const Matcher<Handle<SharedFunctionInfo>> shared_info_matcher_; | |
| 1907 const Matcher<PretenureFlag> pretenure_matcher_; | |
| 1908 const Matcher<Node*> effect_matcher_; | |
| 1909 const Matcher<Node*> control_matcher_; | |
| 1910 }; | |
| 1911 | 1860 |
| 1912 } // namespace | 1861 } // namespace |
| 1913 | 1862 |
| 1914 | 1863 |
| 1915 Matcher<Node*> IsDead() { | 1864 Matcher<Node*> IsDead() { |
| 1916 return MakeMatcher(new NodeMatcher(IrOpcode::kDead)); | 1865 return MakeMatcher(new NodeMatcher(IrOpcode::kDead)); |
| 1917 } | 1866 } |
| 1918 | 1867 |
| 1919 | 1868 |
| 1920 Matcher<Node*> IsEnd(const Matcher<Node*>& control0_matcher) { | 1869 Matcher<Node*> IsEnd(const Matcher<Node*>& control0_matcher) { |
| (...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2579 | 2528 |
| 2580 Matcher<Node*> IsJSCallRuntime(std::vector<Matcher<Node*>> value_matchers, | 2529 Matcher<Node*> IsJSCallRuntime(std::vector<Matcher<Node*>> value_matchers, |
| 2581 const Matcher<Node*>& effect_matcher, | 2530 const Matcher<Node*>& effect_matcher, |
| 2582 const Matcher<Node*>& control_matcher) { | 2531 const Matcher<Node*>& control_matcher) { |
| 2583 return MakeMatcher(new IsJSCallMatcher(IrOpcode::kJSCallRuntime, | 2532 return MakeMatcher(new IsJSCallMatcher(IrOpcode::kJSCallRuntime, |
| 2584 value_matchers, effect_matcher, | 2533 value_matchers, effect_matcher, |
| 2585 control_matcher)); | 2534 control_matcher)); |
| 2586 } | 2535 } |
| 2587 | 2536 |
| 2588 | 2537 |
| 2589 Matcher<Node*> IsCreateClosure(const Handle<SharedFunctionInfo> shared_info, | |
| 2590 PretenureFlag pretenure, | |
| 2591 const Matcher<Node*>& effect_matcher, | |
| 2592 const Matcher<Node*>& control_matcher) { | |
| 2593 return MakeMatcher(new IsCreateClosureMatcher( | |
| 2594 shared_info, pretenure, effect_matcher, control_matcher)); | |
| 2595 } | |
| 2596 | |
| 2597 | |
| 2598 #define IS_BINOP_MATCHER(Name) \ | 2538 #define IS_BINOP_MATCHER(Name) \ |
| 2599 Matcher<Node*> Is##Name(const Matcher<Node*>& lhs_matcher, \ | 2539 Matcher<Node*> Is##Name(const Matcher<Node*>& lhs_matcher, \ |
| 2600 const Matcher<Node*>& rhs_matcher) { \ | 2540 const Matcher<Node*>& rhs_matcher) { \ |
| 2601 return MakeMatcher( \ | 2541 return MakeMatcher( \ |
| 2602 new IsBinopMatcher(IrOpcode::k##Name, lhs_matcher, rhs_matcher)); \ | 2542 new IsBinopMatcher(IrOpcode::k##Name, lhs_matcher, rhs_matcher)); \ |
| 2603 } | 2543 } |
| 2604 IS_BINOP_MATCHER(NumberEqual) | 2544 IS_BINOP_MATCHER(NumberEqual) |
| 2605 IS_BINOP_MATCHER(NumberLessThan) | 2545 IS_BINOP_MATCHER(NumberLessThan) |
| 2606 IS_BINOP_MATCHER(NumberSubtract) | 2546 IS_BINOP_MATCHER(NumberSubtract) |
| 2607 IS_BINOP_MATCHER(NumberMultiply) | 2547 IS_BINOP_MATCHER(NumberMultiply) |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2673 IS_UNOP_MATCHER(NumberToUint32) | 2613 IS_UNOP_MATCHER(NumberToUint32) |
| 2674 IS_UNOP_MATCHER(ObjectIsSmi) | 2614 IS_UNOP_MATCHER(ObjectIsSmi) |
| 2675 IS_UNOP_MATCHER(Word32Clz) | 2615 IS_UNOP_MATCHER(Word32Clz) |
| 2676 IS_UNOP_MATCHER(JSUnaryNot) | 2616 IS_UNOP_MATCHER(JSUnaryNot) |
| 2677 IS_UNOP_MATCHER(JSTypeOf) | 2617 IS_UNOP_MATCHER(JSTypeOf) |
| 2678 #undef IS_UNOP_MATCHER | 2618 #undef IS_UNOP_MATCHER |
| 2679 | 2619 |
| 2680 } // namespace compiler | 2620 } // namespace compiler |
| 2681 } // namespace internal | 2621 } // namespace internal |
| 2682 } // namespace v8 | 2622 } // namespace v8 |
| OLD | NEW |