[PATCH] binutils: v2: experimental use of libdiagnostics in gas
Jan Beulich
jbeulich@suse.com
Wed Nov 22 07:36:57 GMT 2023
On 21.11.2023 23:20, David Malcolm wrote:
> @@ -101,6 +109,29 @@ had_warnings (void)
> return warning_count;
> }
>
> +#if USE_LIBDIAGNOSTICS
> +static diagnostic_manager *diag_mgr;
> +#endif
> +
> +void messages_init (void)
> +{
> +#if USE_LIBDIAGNOSTICS
> + diag_mgr = diagnostic_manager_new ();
> + diagnostic_manager_add_text_sink (diag_mgr, stderr,
> + DIAGNOSTIC_COLORIZE_IF_TTY);
Coloring will want to be possible to turn off (or maybe be off by default,
and be possible to turn on).
As to the #if-s: I think they all would better be #ifdef.
> @@ -182,6 +213,20 @@ as_warn_internal (const char *file, unsigned int line, char *buffer)
> context = true;
> }
>
> +#if USE_LIBDIAGNOSTICS
> + const diagnostic_file *file_obj
> + = diagnostic_manager_new_file (diag_mgr, file, NULL);
> +
> + const diagnostic_physical_location *loc
> + = diagnostic_manager_new_location_from_file_and_line (diag_mgr,
> + file_obj,
> + line);
> +
> + diagnostic *d = diagnostic_begin (diag_mgr,
> + DIAGNOSTIC_LEVEL_WARNING);
> + diagnostic_set_location (d, loc);
> + diagnostic_finish (d, "%s", buffer);
> +#else
This looks identical to ...
> @@ -256,6 +302,19 @@ as_bad_internal (const char *file, unsigned int line, char *buffer)
> context = true;
> }
>
> +#if USE_LIBDIAGNOSTICS
> + const diagnostic_file *file_obj
> + = diagnostic_manager_new_file (diag_mgr, file, NULL);
> + const diagnostic_physical_location *loc
> + = diagnostic_manager_new_location_from_file_and_line (diag_mgr,
> + file_obj,
> + line);
> +
> + diagnostic *d = diagnostic_begin (diag_mgr,
> + DIAGNOSTIC_LEVEL_ERROR);
> + diagnostic_set_location (d, loc);
> + diagnostic_finish (d, "%s", buffer);
> +#else
... this, except for the level used. Put into a helper function? Which
would the further want using from as_info_where()?
Jan
More information about the Binutils
mailing list