| 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 |
| 30 namespace compiler { | 31 namespace compiler { |
| 31 | 32 |
| 32 namespace { | 33 namespace { |
| 33 | 34 |
| 34 template <typename T> | 35 template <typename T> |
| 35 bool PrintMatchAndExplain(const T& value, const std::string& value_name, | 36 bool PrintMatchAndExplain(const T& value, const std::string& value_name, |
| 36 const Matcher<T>& value_matcher, | 37 const Matcher<T>& value_matcher, |
| 37 MatchResultListener* listener) { | 38 MatchResultListener* listener) { |
| 38 StringMatchResultListener value_listener; | 39 StringMatchResultListener value_listener; |
| 39 if (!value_matcher.MatchAndExplain(value, &value_listener)) { | 40 if (!value_matcher.MatchAndExplain(value, &value_listener)) { |
| (...skipping 1811 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1851 PrintMatchAndExplain(NodeProperties::GetControlInput(node), | 1852 PrintMatchAndExplain(NodeProperties::GetControlInput(node), |
| 1852 "control", control_matcher_, listener)); | 1853 "control", control_matcher_, listener)); |
| 1853 } | 1854 } |
| 1854 | 1855 |
| 1855 private: | 1856 private: |
| 1856 const std::vector<Matcher<Node*>> value_matchers_; | 1857 const std::vector<Matcher<Node*>> value_matchers_; |
| 1857 const Matcher<Node*> effect_matcher_; | 1858 const Matcher<Node*> effect_matcher_; |
| 1858 const Matcher<Node*> control_matcher_; | 1859 const Matcher<Node*> control_matcher_; |
| 1859 }; | 1860 }; |
| 1860 | 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 |
| 1861 } // namespace | 1912 } // namespace |
| 1862 | 1913 |
| 1863 | 1914 |
| 1864 Matcher<Node*> IsDead() { | 1915 Matcher<Node*> IsDead() { |
| 1865 return MakeMatcher(new NodeMatcher(IrOpcode::kDead)); | 1916 return MakeMatcher(new NodeMatcher(IrOpcode::kDead)); |
| 1866 } | 1917 } |
| 1867 | 1918 |
| 1868 | 1919 |
| 1869 Matcher<Node*> IsEnd(const Matcher<Node*>& control0_matcher) { | 1920 Matcher<Node*> IsEnd(const Matcher<Node*>& control0_matcher) { |
| 1870 return MakeMatcher(new IsControl1Matcher(IrOpcode::kEnd, control0_matcher)); | 1921 return MakeMatcher(new IsControl1Matcher(IrOpcode::kEnd, control0_matcher)); |
| (...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2528 | 2579 |
| 2529 Matcher<Node*> IsJSCallRuntime(std::vector<Matcher<Node*>> value_matchers, | 2580 Matcher<Node*> IsJSCallRuntime(std::vector<Matcher<Node*>> value_matchers, |
| 2530 const Matcher<Node*>& effect_matcher, | 2581 const Matcher<Node*>& effect_matcher, |
| 2531 const Matcher<Node*>& control_matcher) { | 2582 const Matcher<Node*>& control_matcher) { |
| 2532 return MakeMatcher(new IsJSCallMatcher(IrOpcode::kJSCallRuntime, | 2583 return MakeMatcher(new IsJSCallMatcher(IrOpcode::kJSCallRuntime, |
| 2533 value_matchers, effect_matcher, | 2584 value_matchers, effect_matcher, |
| 2534 control_matcher)); | 2585 control_matcher)); |
| 2535 } | 2586 } |
| 2536 | 2587 |
| 2537 | 2588 |
| 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 |
| 2538 #define IS_BINOP_MATCHER(Name) \ | 2598 #define IS_BINOP_MATCHER(Name) \ |
| 2539 Matcher<Node*> Is##Name(const Matcher<Node*>& lhs_matcher, \ | 2599 Matcher<Node*> Is##Name(const Matcher<Node*>& lhs_matcher, \ |
| 2540 const Matcher<Node*>& rhs_matcher) { \ | 2600 const Matcher<Node*>& rhs_matcher) { \ |
| 2541 return MakeMatcher( \ | 2601 return MakeMatcher( \ |
| 2542 new IsBinopMatcher(IrOpcode::k##Name, lhs_matcher, rhs_matcher)); \ | 2602 new IsBinopMatcher(IrOpcode::k##Name, lhs_matcher, rhs_matcher)); \ |
| 2543 } | 2603 } |
| 2544 IS_BINOP_MATCHER(NumberEqual) | 2604 IS_BINOP_MATCHER(NumberEqual) |
| 2545 IS_BINOP_MATCHER(NumberLessThan) | 2605 IS_BINOP_MATCHER(NumberLessThan) |
| 2546 IS_BINOP_MATCHER(NumberSubtract) | 2606 IS_BINOP_MATCHER(NumberSubtract) |
| 2547 IS_BINOP_MATCHER(NumberMultiply) | 2607 IS_BINOP_MATCHER(NumberMultiply) |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2613 IS_UNOP_MATCHER(NumberToUint32) | 2673 IS_UNOP_MATCHER(NumberToUint32) |
| 2614 IS_UNOP_MATCHER(ObjectIsSmi) | 2674 IS_UNOP_MATCHER(ObjectIsSmi) |
| 2615 IS_UNOP_MATCHER(Word32Clz) | 2675 IS_UNOP_MATCHER(Word32Clz) |
| 2616 IS_UNOP_MATCHER(JSUnaryNot) | 2676 IS_UNOP_MATCHER(JSUnaryNot) |
| 2617 IS_UNOP_MATCHER(JSTypeOf) | 2677 IS_UNOP_MATCHER(JSTypeOf) |
| 2618 #undef IS_UNOP_MATCHER | 2678 #undef IS_UNOP_MATCHER |
| 2619 | 2679 |
| 2620 } // namespace compiler | 2680 } // namespace compiler |
| 2621 } // namespace internal | 2681 } // namespace internal |
| 2622 } // namespace v8 | 2682 } // namespace v8 |
| OLD | NEW |