gas: add as_info() for informational diagnostics

This patch adds as_info(), a shortened version of as_info_where(),
for emitting informational diagnostics from Gas.
This new helper provides the same formatting and source location
handling as as_info_where(), while offering a simpler interface
for the common case. It respects the --no-info flag, and supports
indentation in the same way as its sibling.
This commit is contained in:
Matthieu Longo
2025-12-22 15:50:02 +00:00
parent 5d8562e89a
commit dd0ccd82d7
2 changed files with 52 additions and 8 deletions

View File

@@ -471,10 +471,13 @@ typedef struct _pseudo_type pseudo_typeS;
#define PRINTF_LIKE(FCN) \
void FCN (const char *format, ...) \
__attribute__ ((__format__ (__printf__, 1, 2)))
#define PRINTF_INDENT_LIKE(FCN) \
void FCN (unsigned int indent, const char *format, ...) \
__attribute__ ((__format__ (__printf__, 2, 3)))
#define PRINTF_WHERE_LIKE(FCN) \
void FCN (const char *file, unsigned int line, const char *format, ...) \
__attribute__ ((__format__ (__printf__, 3, 4)))
#define PRINTF_INDENT_LIKE(FCN) \
#define PRINTF_WHERE_INDENT_LIKE(FCN) \
void FCN (const char *file, unsigned int line, unsigned int indent, \
const char *format, ...) \
__attribute__ ((__format__ (__printf__, 4, 5)))
@@ -482,13 +485,15 @@ typedef struct _pseudo_type pseudo_typeS;
#else /* __GNUC__ < 2 || defined(VMS) */
#define PRINTF_LIKE(FCN) void FCN (const char *format, ...)
#define PRINTF_INDENT_LIKE(FCN) void FCN (unsigned int indent, \
const char *format, ...)
#define PRINTF_WHERE_LIKE(FCN) void FCN (const char *file, \
unsigned int line, \
const char *format, ...)
#define PRINTF_INDENT_LIKE(FCN) void FCN (const char *file, \
unsigned int line, \
unsigned int indent, \
const char *format, ...)
#define PRINTF_WHERE_INDENT_LIKE(FCN) void FCN (const char *file, \
unsigned int line, \
unsigned int indent, \
const char *format, ...)
#endif /* __GNUC__ < 2 || defined(VMS) */
@@ -496,9 +501,10 @@ PRINTF_LIKE (as_bad);
PRINTF_LIKE (as_fatal) ATTRIBUTE_NORETURN;
PRINTF_LIKE (as_tsktsk);
PRINTF_LIKE (as_warn);
PRINTF_INDENT_LIKE (as_info);
PRINTF_WHERE_LIKE (as_bad_where);
PRINTF_WHERE_LIKE (as_warn_where);
PRINTF_INDENT_LIKE (as_info_where);
PRINTF_WHERE_INDENT_LIKE (as_info_where);
void set_identify_name (const char *);
void as_abort (const char *, int, const char *) ATTRIBUTE_NORETURN;

View File

@@ -127,6 +127,45 @@ as_show_where (void)
}
}
/* The common portion of as_info, and as_info_where. */
static void
as_info_internal (const char *file, unsigned int line, unsigned int indent,
const char *buffer)
{
if (file == NULL)
file = as_where_top (&line);
if (file)
{
if (line != 0)
fprintf (stderr, "%s:%u: %*s%s%s\n",
file, line, (int)indent, "", _("Info: "), buffer);
else
fprintf (stderr, "%s: %s%s\n", file, _("Info: "), buffer);
}
else
fprintf (stderr, "%s%s\n", _("Info: "), buffer);
}
/* Send to stderr a string as a information, and locate information
in input file(s). */
void
as_info (unsigned int indent, const char *format, ...)
{
if (flag_no_information)
return;
va_list args;
char buffer[2000];
va_start (args, format);
vsnprintf (buffer, sizeof (buffer), format, args);
va_end (args);
as_info_internal (NULL, 0, indent, buffer);
}
/* Send to stderr a string as information, with location data passed in.
Note that for now this is not intended for general use. */
@@ -143,8 +182,7 @@ as_info_where (const char *file, unsigned int line, unsigned int indent,
va_start (args, format);
vsnprintf (buffer, sizeof (buffer), format, args);
va_end (args);
fprintf (stderr, "%s:%u: %*s%s%s\n",
file, line, (int)indent, "", _("Info: "), buffer);
as_info_internal (file, line, indent, buffer);
}
/* The common portion of as_warn, as_warn_where, and as_tsktsk. */