]> git.feebdaed.xyz Git - 0xmirror/binutils-gdb.git/commitdiff
gas: add as_info() for informational diagnostics
authorMatthieu Longo <matthieu.longo@arm.com>
Mon, 22 Dec 2025 15:50:02 +0000 (15:50 +0000)
committerMatthieu Longo <matthieu.longo@arm.com>
Tue, 23 Dec 2025 16:51:27 +0000 (16:51 +0000)
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.

gas/as.h
gas/messages.c

index b743ba95cc71dfd85aa70c12cb9dd99d0e16beb9..02c799984ecfc85218174cee69ac0eac5186b623 100644 (file)
--- a/gas/as.h
+++ b/gas/as.h
@@ -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_WHERE_LIKE(FCN) void FCN (const char *file, \
-                                         unsigned int line, \
+#define PRINTF_INDENT_LIKE(FCN)        void FCN (unsigned int indent, \
                                          const char *format, ...)
-#define PRINTF_INDENT_LIKE(FCN)        void FCN (const char *file, \
+#define PRINTF_WHERE_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;
index c681e4a39b41a9bedb0820119cb26fd3c038980e..6302c06b58daf0a6fb1ff3d7646dccd1740ad774 100644 (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.  */