selftest-rtl.h 3.2 KB

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