1 /* Selftest support for RTL.
2 Copyright (C) 2016-2017 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
22 #include "coretypes.h"
27 #include "read-rtl-function.h"
29 #include "tree-core.h"
32 #include "selftest-rtl.h"
38 /* Compare rtx EXPECTED and ACTUAL by pointer equality, calling
39 ::selftest::pass if they are equal, aborting if they are non-equal.
40 LOC is the effective location of the assertion, MSG describes it. */
43 assert_rtx_ptr_eq_at (const location
&loc
, const char *msg
,
44 rtx expected
, rtx actual
)
46 if (expected
== actual
)
47 ::selftest::pass (loc
, msg
);
50 fprintf (stderr
, "%s:%i: %s: FAIL: %s\n", loc
.m_file
, loc
.m_line
,
52 fprintf (stderr
, " expected (at %p): ", (void *)expected
);
53 print_rtl (stderr
, expected
);
54 fprintf (stderr
, "\n actual (at %p): ", (void *)actual
);
55 print_rtl (stderr
, actual
);
56 fprintf (stderr
, "\n");
61 /* Constructor for selftest::rtl_dump_test.
62 Read a dumped RTL function from PATH.
63 Takes ownership of PATH, freeing in dtor.
64 Use LOC as the effective location when reporting failures. */
66 rtl_dump_test::rtl_dump_test (const location
&loc
, char *path
)
69 bool read_ok
= read_rtl_function_body (path
);
70 ASSERT_TRUE_AT (loc
, read_ok
);
73 /* Destructor for selftest::rtl_dump_test.
74 Cleanup global state relating to the function, and free the path. */
76 selftest::rtl_dump_test::~rtl_dump_test ()
79 current_function_decl
= NULL
;
80 free_after_compilation (cfun
);
85 /* Get the insn with the given uid, or NULL if not found. */
88 get_insn_by_uid (int uid
)
90 for (rtx_insn
*insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
91 if (INSN_UID (insn
) == uid
)
98 } // namespace selftest
100 #endif /* #if CHECKING_P */