ASSERT_STREQ (expected, pp_formatted_text (&pp));
}
+/* Verify that X is dumped as EXPECTED_DUMP, using compact mode.
+ Use LOC as the effective location when reporting errors. */
+
+static void
+assert_rtl_dump_eq (const location &loc, const char *expected_dump, rtx x)
+{
+ named_temp_file tmp_out (".rtl");
+ FILE *outfile = fopen (tmp_out.get_filename (), "w");
+ flag_compact = true;
+ print_rtl (outfile, x);
+ flag_compact = false;
+ fclose (outfile);
+
+ char *dump = read_file (SELFTEST_LOCATION, tmp_out.get_filename ());
+ ASSERT_STREQ_AT (loc, expected_dump, dump);
+ free (dump);
+}
+
+/* Verify that RTX is dumped as EXPECTED_DUMP, using compact mode. */
+
+#define ASSERT_RTL_DUMP_EQ(EXPECTED_DUMP, RTX) \
+ assert_rtl_dump_eq (SELFTEST_LOCATION, (EXPECTED_DUMP), (RTX))
+
+/* Verify that regs are dumped as expected (in compact mode). */
+
+static void
+test_dumping_regs ()
+{
+ /* Dumps of hard regs contain a target-specific name, so we don't test
+ it here. */
+
+ /* Test dumping of virtual regs. The various virtual regs are inited as
+ Pmode, so this is target-specific. The tests below assume DImode, so
+ only run the tests for targets where Pmode is DImode. */
+ if (Pmode == DImode)
+ {
+ ASSERT_RTL_DUMP_EQ ("(reg:DI virtual-incoming-args)",
+ virtual_incoming_args_rtx);
+ ASSERT_RTL_DUMP_EQ ("(reg:DI virtual-stack-vars)",
+ virtual_stack_vars_rtx);
+ ASSERT_RTL_DUMP_EQ ("(reg:DI virtual-stack-dynamic)",
+ virtual_stack_dynamic_rtx);
+ ASSERT_RTL_DUMP_EQ ("(reg:DI virtual-outgoing-args)",
+ virtual_outgoing_args_rtx);
+ ASSERT_RTL_DUMP_EQ ("(reg:DI virtual-cfa)",
+ virtual_cfa_rtx);
+ ASSERT_RTL_DUMP_EQ ("(reg:DI virtual-preferred-stack-boundary)",
+ virtual_preferred_stack_boundary_rtx);
+ }
+
+ /* Test dumping of non-virtual pseudos. */
+ ASSERT_RTL_DUMP_EQ ("(reg:SI %0)",
+ gen_raw_REG (SImode, LAST_VIRTUAL_REGISTER + 1));
+ ASSERT_RTL_DUMP_EQ ("(reg:SI %1)",
+ gen_raw_REG (SImode, LAST_VIRTUAL_REGISTER + 2));
+}
+
+/* Verify that insns are dumped as expected (in compact mode). */
+
+static void
+test_dumping_insns ()
+{
+ /* Barriers. */
+ rtx_barrier *barrier = as_a <rtx_barrier *> (rtx_alloc (BARRIER));
+ SET_NEXT_INSN (barrier) = NULL;
+ ASSERT_RTL_DUMP_EQ ("(cbarrier)\n", barrier);
+
+ /* Labels. */
+ rtx_insn *label = gen_label_rtx ();
+ CODE_LABEL_NUMBER (label) = 42;
+ ASSERT_RTL_DUMP_EQ ("(clabel 0 42 \"\")\n", label);
+
+ LABEL_NAME (label)= "some_label";
+ ASSERT_RTL_DUMP_EQ ("(clabel 0 42 (\"some_label\"))\n", label);
+}
+
/* Unit testing of "single_set". */
static void
verify_print_pattern ("pc=L0", jump_pat);
+ ASSERT_RTL_DUMP_EQ ("(set (pc)\n"
+ " (label_ref 0))",
+ jump_pat);
+
rtx_insn *jump_insn = emit_jump_insn (jump_pat);
ASSERT_FALSE (any_condjump_p (jump_insn));
ASSERT_TRUE (any_uncondjump_p (jump_insn));
ASSERT_TRUE (simplejump_p (jump_insn));
ASSERT_TRUE (onlyjump_p (jump_insn));
ASSERT_TRUE (control_flow_insn_p (jump_insn));
+
+ ASSERT_RTL_DUMP_EQ ("(cjump_insn (set (pc)\n"
+ " (label_ref 0))\n"
+ " (nil))\n",
+ jump_insn);
}
/* Run all of the selftests within this file. */
void
rtl_tests_c_tests ()
{
+ test_dumping_regs ();
+ test_dumping_insns ();
test_single_set ();
test_uncond_jump ();