/* Dump infrastructure for optimizations and intermediate representation.
- Copyright (C) 2012-2019 Free Software Foundation, Inc.
+ Copyright (C) 2012-2020 Free Software Foundation, Inc.
This file is part of GCC.
#include "tree-pass.h" /* for "current_pass". */
#include "optinfo-emit-json.h"
#include "stringpool.h" /* for get_identifier. */
+#include "spellcheck.h"
/* If non-NULL, return one past-the-end of the matching SUBPART of
the WHOLE string. */
in dumpfile.h and opt_info_options below. */
static const kv_pair<dump_flags_t> dump_options[] =
{
+ {"none", TDF_NONE},
{"address", TDF_ADDRESS},
{"asmname", TDF_ASMNAME},
{"slim", TDF_SLIM},
gcc::dump_manager::
dump_begin (int phase, dump_flags_t *flag_ptr, int part)
{
- char *name;
- struct dump_file_info *dfi;
- FILE *stream;
-
if (phase == TDI_none || !dump_phase_enabled_p (phase))
return NULL;
- name = get_dump_file_name (phase, part);
+ char *name = get_dump_file_name (phase, part);
if (!name)
return NULL;
- dfi = get_dump_file_info (phase);
+ struct dump_file_info *dfi = get_dump_file_info (phase);
/* We do not support re-opening of dump files with parts. This would require
tracking pstate per part of the dump file. */
- stream = dump_open (name, part != -1 || dfi->pstate < 0);
+ FILE *stream = dump_open (name, part != -1 || dfi->pstate < 0);
if (stream)
dfi->pstate = 1;
free (name);
return true;
}
-/* Parse ARG as a dump switch. Return nonzero if it is, and store the
- relevant details in the dump_files array. */
+/* Helper routine to parse -<dump format>[=filename]
+ and return the corresponding dump flag. If POS_P is non-NULL,
+ assign start of filename into *POS_P. */
-int
-gcc::dump_manager::
-dump_switch_p_1 (const char *arg, struct dump_file_info *dfi, bool doglob)
+dump_flags_t
+parse_dump_option (const char *option_value, const char **pos_p)
{
- const char *option_value;
const char *ptr;
dump_flags_t flags;
- if (doglob && !dfi->glob)
- return 0;
-
- option_value = skip_leading_substring (arg, doglob ? dfi->glob : dfi->swtch);
- if (!option_value)
- return 0;
-
- if (*option_value && *option_value != '-' && *option_value != '=')
- return 0;
-
ptr = option_value;
+ if (pos_p)
+ *pos_p = NULL;
/* Retain "user-facing" and "internals" messages, but filter out
those from an opt_problem being re-emitted at the top level
const char *end_ptr;
const char *eq_ptr;
unsigned length;
-
while (*ptr == '-')
ptr++;
end_ptr = strchr (ptr, '-');
eq_ptr = strchr (ptr, '=');
if (eq_ptr && !end_ptr)
- end_ptr = eq_ptr;
+ end_ptr = eq_ptr;
if (!end_ptr)
end_ptr = ptr + strlen (ptr);
for (option_ptr = dump_options; option_ptr->name; option_ptr++)
if (strlen (option_ptr->name) == length
&& !memcmp (option_ptr->name, ptr, length))
- {
- flags |= option_ptr->value;
+ {
+ flags |= option_ptr->value;
goto found;
- }
+ }
if (*ptr == '=')
- {
+ {
/* Interpret rest of the argument as a dump filename. This
filename overrides other command line filenames. */
- if (dfi->pfilename)
- free (CONST_CAST (char *, dfi->pfilename));
- dfi->pfilename = xstrdup (ptr + 1);
- break;
- }
+ if (pos_p)
+ *pos_p = ptr + 1;
+ break;
+ }
else
- warning (0, "ignoring unknown option %q.*s in %<-fdump-%s%>",
- length, ptr, dfi->swtch);
- found:;
+ {
+ warning (0, "ignoring unknown option %q.*s",
+ length, ptr);
+ flags = TDF_ERROR;
+ }
+ found:
ptr = end_ptr;
+ }
+
+ return flags;
+}
+
+/* Parse ARG as a dump switch. Return nonzero if it is, and store the
+ relevant details in the dump_files array. */
+
+int
+gcc::dump_manager::
+dump_switch_p_1 (const char *arg, struct dump_file_info *dfi, bool doglob)
+{
+ const char *option_value;
+ dump_flags_t flags = TDF_NONE;
+
+ if (doglob && !dfi->glob)
+ return 0;
+
+ option_value = skip_leading_substring (arg, doglob ? dfi->glob : dfi->swtch);
+ if (!option_value)
+ return 0;
+
+ if (*option_value && *option_value != '-' && *option_value != '=')
+ return 0;
+
+ const char *filename;
+ flags = parse_dump_option (option_value, &filename);
+ if (filename)
+ {
+ if (dfi->pfilename)
+ free (CONST_CAST (char *, dfi->pfilename));
+ dfi->pfilename = xstrdup (filename);
}
dfi->pstate = -1;
return 1;
}
-int
+void
gcc::dump_manager::
dump_switch_p (const char *arg)
{
for (i = 0; i < m_extra_dump_files_in_use; i++)
any |= dump_switch_p_1 (arg, &m_extra_dump_files[i], true);
-
- return any;
+ if (!any)
+ {
+ auto_vec<const char *> candidates;
+ for (size_t i = TDI_none + 1; i != TDI_end; i++)
+ candidates.safe_push (dump_files[i].swtch);
+ for (size_t i = 0; i < m_extra_dump_files_in_use; i++)
+ candidates.safe_push (m_extra_dump_files[i].swtch);
+ const char *hint = find_closest_string (arg, &candidates);
+ if (hint)
+ error ("unrecognized command-line option %<-fdump-%s%>; "
+ "did you mean %<-fdump-%s%>?", arg, hint);
+ else
+ error ("unrecognized command-line option %<-fdump-%s%>", arg);
+ }
}
/* Parse ARG as a -fopt-info switch and store flags, optgroup_flags
return num_enabled > 0;
}
+/* debug_dump_context's ctor. Temporarily override the dump_context
+ (to forcibly enable output to stderr). */
+
+debug_dump_context::debug_dump_context ()
+: m_context (),
+ m_saved (&dump_context::get ()),
+ m_saved_flags (dump_flags),
+ m_saved_pflags (pflags),
+ m_saved_file (dump_file)
+{
+ set_dump_file (stderr);
+ dump_context::s_current = &m_context;
+ pflags = dump_flags = MSG_ALL_KINDS | MSG_ALL_PRIORITIES;
+ dump_context::get ().refresh_dumps_are_enabled ();
+}
+
+/* debug_dump_context's dtor. Restore the saved dump_context. */
+
+debug_dump_context::~debug_dump_context ()
+{
+ set_dump_file (m_saved_file);
+ dump_context::s_current = m_saved;
+ dump_flags = m_saved_flags;
+ pflags = m_saved_pflags;
+ dump_context::get ().refresh_dumps_are_enabled ();
+}
+
+
#if CHECKING_P
namespace selftest {
bool forcibly_enable_dumping,
dump_flags_t test_pp_flags)
: m_context (),
- m_saved (&dump_context ().get ())
+ m_saved (&dump_context::get ())
{
dump_context::s_current = &m_context;
if (forcibly_enable_optinfo)