1*38fd1498Szrj /* A self-testing framework, for use by -fself-test. 2*38fd1498Szrj Copyright (C) 2016-2018 Free Software Foundation, Inc. 3*38fd1498Szrj 4*38fd1498Szrj This file is part of GCC. 5*38fd1498Szrj 6*38fd1498Szrj GCC is free software; you can redistribute it and/or modify it under 7*38fd1498Szrj the terms of the GNU General Public License as published by the Free 8*38fd1498Szrj Software Foundation; either version 3, or (at your option) any later 9*38fd1498Szrj version. 10*38fd1498Szrj 11*38fd1498Szrj GCC is distributed in the hope that it will be useful, but WITHOUT ANY 12*38fd1498Szrj WARRANTY; without even the implied warranty of MERCHANTABILITY or 13*38fd1498Szrj FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14*38fd1498Szrj for more details. 15*38fd1498Szrj 16*38fd1498Szrj You should have received a copy of the GNU General Public License 17*38fd1498Szrj along with GCC; see the file COPYING3. If not see 18*38fd1498Szrj <http://www.gnu.org/licenses/>. */ 19*38fd1498Szrj 20*38fd1498Szrj #ifndef GCC_SELFTEST_RTL_H 21*38fd1498Szrj #define GCC_SELFTEST_RTL_H 22*38fd1498Szrj 23*38fd1498Szrj /* The selftest code should entirely disappear in a production 24*38fd1498Szrj configuration, hence we guard all of it with #if CHECKING_P. */ 25*38fd1498Szrj 26*38fd1498Szrj #if CHECKING_P 27*38fd1498Szrj 28*38fd1498Szrj class rtx_reuse_manager; 29*38fd1498Szrj 30*38fd1498Szrj namespace selftest { 31*38fd1498Szrj 32*38fd1498Szrj /* Verify that X is dumped as EXPECTED_DUMP, using compact mode. 33*38fd1498Szrj Use LOC as the effective location when reporting errors. */ 34*38fd1498Szrj 35*38fd1498Szrj extern void 36*38fd1498Szrj assert_rtl_dump_eq (const location &loc, const char *expected_dump, rtx x, 37*38fd1498Szrj rtx_reuse_manager *reuse_manager); 38*38fd1498Szrj 39*38fd1498Szrj /* Verify that RTX is dumped as EXPECTED_DUMP, using compact mode. */ 40*38fd1498Szrj 41*38fd1498Szrj #define ASSERT_RTL_DUMP_EQ(EXPECTED_DUMP, RTX) \ 42*38fd1498Szrj assert_rtl_dump_eq (SELFTEST_LOCATION, (EXPECTED_DUMP), (RTX), NULL) 43*38fd1498Szrj 44*38fd1498Szrj /* As above, but using REUSE_MANAGER when dumping. */ 45*38fd1498Szrj 46*38fd1498Szrj #define ASSERT_RTL_DUMP_EQ_WITH_REUSE(EXPECTED_DUMP, RTX, REUSE_MANAGER) \ 47*38fd1498Szrj assert_rtl_dump_eq (SELFTEST_LOCATION, (EXPECTED_DUMP), (RTX), \ 48*38fd1498Szrj (REUSE_MANAGER)) 49*38fd1498Szrj 50*38fd1498Szrj #define ASSERT_RTX_EQ(EXPECTED, ACTUAL) \ 51*38fd1498Szrj SELFTEST_BEGIN_STMT \ 52*38fd1498Szrj const char *desc_ = "ASSERT_RTX_EQ (" #EXPECTED ", " #ACTUAL ")"; \ 53*38fd1498Szrj ::selftest::assert_rtx_eq_at (SELFTEST_LOCATION, desc_, (EXPECTED), \ 54*38fd1498Szrj (ACTUAL)); \ 55*38fd1498Szrj SELFTEST_END_STMT 56*38fd1498Szrj 57*38fd1498Szrj extern void assert_rtx_eq_at (const location &, const char *, rtx, rtx); 58*38fd1498Szrj 59*38fd1498Szrj /* Evaluate rtx EXPECTED and ACTUAL and compare them with == 60*38fd1498Szrj (i.e. pointer equality), calling ::selftest::pass if they are 61*38fd1498Szrj equal, aborting if they are non-equal. */ 62*38fd1498Szrj 63*38fd1498Szrj #define ASSERT_RTX_PTR_EQ(EXPECTED, ACTUAL) \ 64*38fd1498Szrj SELFTEST_BEGIN_STMT \ 65*38fd1498Szrj const char *desc_ = "ASSERT_RTX_PTR_EQ (" #EXPECTED ", " #ACTUAL ")"; \ 66*38fd1498Szrj ::selftest::assert_rtx_ptr_eq_at (SELFTEST_LOCATION, desc_, (EXPECTED), \ 67*38fd1498Szrj (ACTUAL)); \ 68*38fd1498Szrj SELFTEST_END_STMT 69*38fd1498Szrj 70*38fd1498Szrj /* Compare rtx EXPECTED and ACTUAL by pointer equality, calling 71*38fd1498Szrj ::selftest::pass if they are equal, aborting if they are non-equal. 72*38fd1498Szrj LOC is the effective location of the assertion, MSG describes it. */ 73*38fd1498Szrj 74*38fd1498Szrj extern void assert_rtx_ptr_eq_at (const location &loc, const char *msg, 75*38fd1498Szrj rtx expected, rtx actual); 76*38fd1498Szrj 77*38fd1498Szrj /* A class for testing RTL function dumps. */ 78*38fd1498Szrj 79*38fd1498Szrj class rtl_dump_test 80*38fd1498Szrj { 81*38fd1498Szrj public: 82*38fd1498Szrj /* Takes ownership of PATH. */ 83*38fd1498Szrj rtl_dump_test (const location &loc, char *path); 84*38fd1498Szrj ~rtl_dump_test (); 85*38fd1498Szrj 86*38fd1498Szrj private: 87*38fd1498Szrj char *m_path; 88*38fd1498Szrj }; 89*38fd1498Szrj 90*38fd1498Szrj /* Get the insn with the given uid, or NULL if not found. */ 91*38fd1498Szrj 92*38fd1498Szrj extern rtx_insn *get_insn_by_uid (int uid); 93*38fd1498Szrj 94*38fd1498Szrj extern void verify_three_block_rtl_cfg (function *fun); 95*38fd1498Szrj 96*38fd1498Szrj } /* end of namespace selftest. */ 97*38fd1498Szrj 98*38fd1498Szrj #endif /* #if CHECKING_P */ 99*38fd1498Szrj 100*38fd1498Szrj #endif /* GCC_SELFTEST_RTL_H */ 101