public inbox for cgen@sourceware.org
 help / color / mirror / Atom feed
* binutils opcodes error messages
@ 2018-03-02 23:58 Alan Modra
  2018-03-03  0:58 ` Frank Ch. Eigler
  0 siblings, 1 reply; 2+ messages in thread
From: Alan Modra @ 2018-03-02 23:58 UTC (permalink / raw)
  To: cgen; +Cc: Frank Ch. Eigler

This patch is aimed at making binutils/opcodes files comply with the
GNU coding standard regarding error messages, that is, they should
start with the program name followed by a colon, then a lower case
message.  Accomplished by calling opcodes_error_handler to output the
program name (and final '\n'), rather than calling fprintf.

Files used by the simulator, cris/cris-desc.c and sh64/sh-desc.c will
continue to use fprintf via the fallback opcodes_error_handler define.
I initially wrote a patch with a little scheme to select the right
message output function for opcodes by comparing APPLICATION against
'OPCODES.  That was before discovering that APPLICATION is 'OPCODES
when cgen is invoked to create *-desc.c for the simulator.  :-(

OK to apply?

	* desc-cpu.scm (opcodes_error_handler): Define.
	(@arch@_cgen_rebuild_tables): Use opcodes_error_handler.
	(@arch@_cgen_cpu_open): Likewise.
	* opc-asmdis.scm (@arch@_cgen_parse_operand): Likewise.
	(@arch@_cgen_print_operand): Likewise.
	* opc-ibld.scm (@arch@_cgen_get_int_operand): Likewise.
	(@arch@_cgen_get_vma_operand): Likewise.
	(@arch@_cgen_set_int_operand): Likewise.
	(@arch@_cgen_set_vma_operand): Likewise.
	(@arch@_cgen_insert_operand): Likewise.
	(@arch@_cgen_extract_operand): Likewise.
	* utils.scm: Update emitted copyright dates.

Index: cgen/desc-cpu.scm
===================================================================
RCS file: /cvs/src/src/cgen/desc-cpu.scm,v
retrieving revision 1.35
diff -u -p -r1.35 desc-cpu.scm
--- cgen/desc-cpu.scm	13 Apr 2017 11:58:48 -0000	1.35
+++ cgen/desc-cpu.scm	2 Mar 2018 23:25:26 -0000
@@ -588,6 +588,11 @@ static const CGEN_IBASE @arch@_cgen_insn
 (define (/gen-cpu-open)
   (string-append
    "\
+#ifndef opcodes_error_handler
+#define opcodes_error_handler(...) \\
+  fprintf (stderr, __VA_ARGS__); fputc ('\\n', stderr)
+#endif
+
 static const CGEN_MACH * lookup_mach_via_bfd_name (const CGEN_MACH *, const char *);
 static void build_hw_table      (CGEN_CPU_TABLE *);
 static void build_ifield_table  (CGEN_CPU_TABLE *);
@@ -748,8 +753,11 @@ static void
 	{
 	  if (cd->insn_chunk_bitsize != 0 && cd->insn_chunk_bitsize != mach->insn_chunk_bitsize)
 	    {
-	      fprintf (stderr, \"@arch@_cgen_rebuild_tables: conflicting insn-chunk-bitsize values: `%d' vs. `%d'\\n\",
-		       cd->insn_chunk_bitsize, mach->insn_chunk_bitsize);
+	      opcodes_error_handler
+		(/* xgettext:c-format */
+		 _(\"internal error: @arch@_cgen_rebuild_tables: \"
+		   \"conflicting insn-chunk-bitsize values: `%d' vs. `%d'\"),
+		 cd->insn_chunk_bitsize, mach->insn_chunk_bitsize);
 	      abort ();
 	    }
 
@@ -828,8 +836,11 @@ CGEN_CPU_DESC
 	  endian = va_arg (ap, enum cgen_endian);
 	  break;
 	default :
-	  fprintf (stderr, \"@arch@_cgen_cpu_open: unsupported argument `%d'\\n\",
-		   arg_type);
+	  opcodes_error_handler
+	    (/* xgettext:c-format */
+	     _(\"internal error: @arch@_cgen_cpu_open: \"
+	       \"unsupported argument `%d'\"),
+	     arg_type);
 	  abort (); /* ??? return NULL? */
 	}
       arg_type = va_arg (ap, enum cgen_cpu_open_arg);
@@ -844,7 +855,9 @@ CGEN_CPU_DESC
   if (endian == CGEN_ENDIAN_UNKNOWN)
     {
       /* ??? If target has only one, could have a default.  */
-      fprintf (stderr, \"@arch@_cgen_cpu_open: no endianness specified\\n\");
+      opcodes_error_handler
+	(/* xgettext:c-format */
+	 _(\"internal error: @arch@_cgen_cpu_open: no endianness specified\"));
       abort ();
     }
 
Index: cgen/opc-asmdis.scm
===================================================================
RCS file: /cvs/src/src/cgen/opc-asmdis.scm,v
retrieving revision 1.8
diff -u -p -r1.8 opc-asmdis.scm
--- cgen/opc-asmdis.scm	7 Sep 2009 22:17:34 -0000	1.8
+++ cgen/opc-asmdis.scm	2 Mar 2018 23:25:26 -0000
@@ -41,7 +41,9 @@ const char *
 "
     default :
       /* xgettext:c-format */
-      fprintf (stderr, _(\"Unrecognized field %d while parsing.\\n\"), opindex);
+      opcodes_error_handler
+	(_(\"internal error: unrecognized field %d while parsing\"),
+	 opindex);
       abort ();
   }
 
@@ -136,9 +138,10 @@ void
 "
     default :
       /* xgettext:c-format */
-      fprintf (stderr, _(\"Unrecognized field %d while printing insn.\\n\"),
-	       opindex);
-    abort ();
+      opcodes_error_handler
+	(_(\"internal error: unrecognized field %d while printing insn\"),
+	 opindex);
+      abort ();
   }
 }\n\n")
 )
Index: cgen/opc-ibld.scm
===================================================================
RCS file: /cvs/src/src/cgen/opc-ibld.scm,v
retrieving revision 1.9
diff -u -p -r1.9 opc-ibld.scm
--- cgen/opc-ibld.scm	7 Sep 2009 22:17:34 -0000	1.9
+++ cgen/opc-ibld.scm	2 Mar 2018 23:25:26 -0000
@@ -30,8 +30,9 @@ int
 "
     default :
       /* xgettext:c-format */
-      fprintf (stderr, _(\"Unrecognized field %d while getting int operand.\\n\"),
-		       opindex);
+      opcodes_error_handler
+	(_(\"internal error: unrecognized field %d while getting int operand\"),
+	 opindex);
       abort ();
   }
 
@@ -52,8 +53,9 @@ bfd_vma
 "
     default :
       /* xgettext:c-format */
-      fprintf (stderr, _(\"Unrecognized field %d while getting vma operand.\\n\"),
-		       opindex);
+      opcodes_error_handler
+	(_(\"internal error: unrecognized field %d while getting vma operand\"),
+	 opindex);
       abort ();
   }
 
@@ -87,8 +89,9 @@ void
 "
     default :
       /* xgettext:c-format */
-      fprintf (stderr, _(\"Unrecognized field %d while setting int operand.\\n\"),
-		       opindex);
+      opcodes_error_handler
+	(_(\"internal error: unrecognized field %d while setting int operand\"),
+	 opindex);
       abort ();
   }
 }
@@ -106,8 +109,9 @@ void
 "
     default :
       /* xgettext:c-format */
-      fprintf (stderr, _(\"Unrecognized field %d while setting vma operand.\\n\"),
-		       opindex);
+      opcodes_error_handler
+	(_(\"internal error: unrecognized field %d while setting vma operand\"),
+	 opindex);
       abort ();
   }
 }
@@ -197,8 +201,9 @@ const char *
 "
     default :
       /* xgettext:c-format */
-      fprintf (stderr, _(\"Unrecognized field %d while building insn.\\n\"),
-	       opindex);
+      opcodes_error_handler
+	(_(\"internal error: unrecognized field %d while building insn\"),
+	 opindex);
       abort ();
   }
 
@@ -247,8 +252,9 @@ int
 "
     default :
       /* xgettext:c-format */
-      fprintf (stderr, _(\"Unrecognized field %d while decoding insn.\\n\"),
-	       opindex);
+      opcodes_error_handler
+	(_(\"internal error: unrecognized field %d while decoding insn\"),
+	 opindex);
       abort ();
     }
 
Index: cgen/utils.scm
===================================================================
RCS file: /cvs/src/src/cgen/utils.scm,v
retrieving revision 1.40
diff -u -p -r1.40 utils.scm
--- cgen/utils.scm	7 Apr 2017 22:38:16 -0000	1.40
+++ cgen/utils.scm	2 Mar 2018 23:25:27 -0000
@@ -1310,7 +1310,7 @@
   (cons "\
 THIS FILE IS MACHINE GENERATED WITH CGEN.
 
-Copyright (C) 1996-2017 Free Software Foundation, Inc.
+Copyright (C) 1996-2018 Free Software Foundation, Inc.
 "
 	"\
    This file is free software; you can redistribute it and/or modify
@@ -1335,7 +1335,7 @@ Copyright (C) 1996-2017 Free Software Fo
   (cons "\
 THIS FILE IS MACHINE GENERATED WITH CGEN.
 
-Copyright (C) 2000-2017 Red Hat, Inc.
+Copyright (C) 2000-2018 Red Hat, Inc.
 "
 	"\
 "))

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: binutils opcodes error messages
  2018-03-02 23:58 binutils opcodes error messages Alan Modra
@ 2018-03-03  0:58 ` Frank Ch. Eigler
  0 siblings, 0 replies; 2+ messages in thread
From: Frank Ch. Eigler @ 2018-03-03  0:58 UTC (permalink / raw)
  To: Alan Modra; +Cc: cgen

Hi -

> This patch is aimed at making binutils/opcodes files comply with the
> GNU coding standard regarding error messages [...]

lgtm, thanks.

- FChE

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-03-03  0:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-02 23:58 binutils opcodes error messages Alan Modra
2018-03-03  0:58 ` Frank Ch. Eigler

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).