summaryrefslogtreecommitdiff
path: root/gcc/selftest-rtl.c
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-05-02 14:43:35 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-05-02 14:43:35 +0000
commit34efdaf078b01a7387007c4e6bde6db86384c4b7 (patch)
treed503eaf41d085669d1481bb46ec038bc866fece6 /gcc/selftest-rtl.c
parentf733cf303bcdc952c92b81dd62199a40a1f555ec (diff)
downloadgcc-tarball-master.tar.gz
gcc-7.1.0gcc-7.1.0
Diffstat (limited to 'gcc/selftest-rtl.c')
-rw-r--r--gcc/selftest-rtl.c100
1 files changed, 100 insertions, 0 deletions
diff --git a/gcc/selftest-rtl.c b/gcc/selftest-rtl.c
new file mode 100644
index 0000000000..bfb1ab733a
--- /dev/null
+++ b/gcc/selftest-rtl.c
@@ -0,0 +1,100 @@
+/* Selftest support for RTL.
+ Copyright (C) 2016-2017 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3. If not see
+<http://www.gnu.org/licenses/>. */
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "selftest.h"
+#include "backend.h"
+#include "target.h"
+#include "rtl.h"
+#include "read-rtl-function.h"
+#include "read-md.h"
+#include "tree-core.h"
+#include "memmodel.h"
+#include "emit-rtl.h"
+#include "selftest-rtl.h"
+
+#if CHECKING_P
+
+namespace selftest {
+
+/* Compare rtx EXPECTED and ACTUAL by pointer equality, calling
+ ::selftest::pass if they are equal, aborting if they are non-equal.
+ LOC is the effective location of the assertion, MSG describes it. */
+
+void
+assert_rtx_ptr_eq_at (const location &loc, const char *msg,
+ rtx expected, rtx actual)
+{
+ if (expected == actual)
+ ::selftest::pass (loc, msg);
+ else
+ {
+ fprintf (stderr, "%s:%i: %s: FAIL: %s\n", loc.m_file, loc.m_line,
+ loc.m_function, msg);
+ fprintf (stderr, " expected (at %p): ", (void *)expected);
+ print_rtl (stderr, expected);
+ fprintf (stderr, "\n actual (at %p): ", (void *)actual);
+ print_rtl (stderr, actual);
+ fprintf (stderr, "\n");
+ abort ();
+ }
+}
+
+/* Constructor for selftest::rtl_dump_test.
+ Read a dumped RTL function from PATH.
+ Takes ownership of PATH, freeing in dtor.
+ Use LOC as the effective location when reporting failures. */
+
+rtl_dump_test::rtl_dump_test (const location &loc, char *path)
+ : m_path (path)
+{
+ bool read_ok = read_rtl_function_body (path);
+ ASSERT_TRUE_AT (loc, read_ok);
+}
+
+/* Destructor for selftest::rtl_dump_test.
+ Cleanup global state relating to the function, and free the path. */
+
+selftest::rtl_dump_test::~rtl_dump_test ()
+{
+ /* Cleanups. */
+ current_function_decl = NULL;
+ free_after_compilation (cfun);
+ set_cfun (NULL);
+ free (m_path);
+}
+
+/* Get the insn with the given uid, or NULL if not found. */
+
+rtx_insn *
+get_insn_by_uid (int uid)
+{
+ for (rtx_insn *insn = get_insns (); insn; insn = NEXT_INSN (insn))
+ if (INSN_UID (insn) == uid)
+ return insn;
+
+ /* Not found. */
+ return NULL;
+}
+
+} // namespace selftest
+
+#endif /* #if CHECKING_P */