sim: sh: clean up gencode
authorMike Frysinger <vapier@gentoo.org>
Sat, 28 Mar 2015 18:09:11 +0000 (14:09 -0400)
committerMike Frysinger <vapier@gentoo.org>
Sat, 28 Mar 2015 21:45:30 +0000 (17:45 -0400)
The build line was missing the normal BUILD_xxx flags.  Once we added
that, we get warnings that weren't shown before.  As we fix those, we
notice that the -d option segfaults because it tries to write readonly
memory.  Fix that too as part of the const/prototype clean up.

sim/sh/ChangeLog
sim/sh/Makefile.in
sim/sh/gencode.c

index 810049e0f115dfa7aa574a26a68ef1042323da4c..3e0fff15159c84b35a28e2c535280e7b39c3d16a 100644 (file)
@@ -1,3 +1,25 @@
+2015-03-28  Mike Frysinger  <vapier@gentoo.org>
+
+       * Makefile.in (gencode): Add $(BUILD_CFLAGS), $(BUILD_LDFLAGS),
+       and $(WARN_CFLAGS).
+       * gencode.c: Include ctype.h, stdlib.h, string.h, and unistd.h.
+       (struct op): Mark members const.
+       (tab): Mark static.
+       (nibble_type_list): Mark const.
+       (arg_type_list): Mark const.
+       (make_enum_list): Delete unused func.
+       (qfunc, expand_opcode, dumptable, expand_ppi_code): Convert old
+       style prototype and mark args const.
+       (sorttab, gengastab, conflict_warn, filltable, expand_ppi_movxy,
+       gensim, ppi_filltable): Convert old style prototype.
+       (gensim_caselist): Convert old style prototype.  Mark local
+       variables s and r const.
+       (gendefines): Convert old style prototype.  Mark s const.  Move
+       tolower call into printf statement.
+       (ppi_gensim): Convert old style prototype.  Mark local variable
+       s const.
+       (main): Convert old style prototype.  Change printf %d to %zu.
+
 2015-03-28  Mike Frysinger  <vapier@gentoo.org>
 
        * config.in, configure: Regenerate.
index 61422abf59a3c142f34653c05418b4c1933e2fcb..0594a6e3f7abb542b00e845833deaa49efd739d7 100644 (file)
@@ -41,7 +41,8 @@ ppi.c: gencode
        ./gencode -p >ppi.c
 
 gencode: gencode.c
-       $(CC_FOR_BUILD) -o gencode $(srcdir)/gencode.c
+       $(CC_FOR_BUILD) $(BUILD_CFLAGS) $(BUILD_LDFLAGS) $(WARN_CFLAGS) \
+               -o gencode $(srcdir)/gencode.c
 
 sh-clean:
        rm -f gencode code.c table.c
index bc6560460d4190c10538d1b97e77409b3233f96e..0fb1b87c24f61623bea88c4952cc4840d2fb304f 100644 (file)
 
 */
 
+#include <ctype.h>
 #include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
 
 #define MAX_NR_STUFF 42
 
 typedef struct
 {
-  char *defs;
-  char *refs;
-  char *name;
-  char *code;
-  char *stuff[MAX_NR_STUFF];
+  const char *defs;
+  const char *refs;
+  const char *name;
+  const char *code;
+  const char * const stuff[MAX_NR_STUFF];
   int index;
 } op;
 
 
-op tab[] =
+static op tab[] =
 {
 
   { "n", "", "add #<imm>,<REG_N>", "0111nnnni8*1....",
@@ -2462,7 +2466,8 @@ op ppi_tab[] =
 };
 
 /* Tables of things to put into enums for sh-opc.h */
-static char *nibble_type_list[] =
+static
+const char * const nibble_type_list[] =
 {
   "HEX_0",
   "HEX_1",
@@ -2497,7 +2502,7 @@ static char *nibble_type_list[] =
   0
 };
 static
-char *arg_type_list[] =
+const char * const arg_type_list[] =
 {
   "A_END",
   "A_BDISP12",
@@ -2530,27 +2535,11 @@ char *arg_type_list[] =
   0,
 };
 
-static void
-make_enum_list (name, s)
-     char *name;
-     char **s;
-{
-  int i = 1;
-  printf ("typedef enum {\n");
-  while (*s)
-    {
-      printf ("\t%s,\n", *s);
-      s++;
-      i++;
-    }
-  printf ("} %s;\n", name);
-}
-
 static int
-qfunc (a, b)
-     op *a;
-     op *b;
+qfunc (const void *va, const void *vb)
 {
+  const op *a = va;
+  const op *b = vb;
   char bufa[9];
   char bufb[9];
   int diff;
@@ -2569,7 +2558,7 @@ qfunc (a, b)
 }
 
 static void
-sorttab ()
+sorttab (void)
 {
   op *p = tab;
   int len = 0;
@@ -2583,7 +2572,7 @@ sorttab ()
 }
 
 static void
-gengastab ()
+gengastab (void)
 {
   op *p;
   sorttab ();
@@ -2598,9 +2587,7 @@ static unsigned short table[1 << 16];
 static int warn_conflicts = 0;
 
 static void
-conflict_warn (val, i)
-     int val;
-     int i;
+conflict_warn (int val, int i)
 {
   int ix, key;
   int j = table[val];
@@ -2651,10 +2638,7 @@ conflict_warn (val, i)
    right entries in 'table' with the opcode index.  */
 
 static void
-expand_opcode (val, i, s)
-     int val;
-     int i;
-     char *s;
+expand_opcode (int val, int i, const char *s)
 {
   if (*s == 0)
     {
@@ -2779,10 +2763,7 @@ expand_opcode (val, i, s)
    statement entry.  */
 
 static void
-dumptable (name, size, start)
-     char *name;
-     int size;
-     int start;
+dumptable (const char *name, int size, int start)
 {
   int lump = 256;
   int online = 16;
@@ -2817,8 +2798,7 @@ dumptable (name, size, start)
 
 
 static void
-filltable (p)
-     op *p;
+filltable (op *p)
 {
   static int index = 1;
 
@@ -2835,7 +2815,7 @@ filltable (p)
    processing insns (ppi) for code 0xf800 (ppi nopx nopy).  Copy the
    latter tag to represent all combinations of ppi with ddt.  */
 static void
-expand_ppi_movxy ()
+expand_ppi_movxy (void)
 {
   int i;
 
@@ -2845,8 +2825,7 @@ expand_ppi_movxy ()
 }
 
 static void
-gensim_caselist (p)
-     op *p;
+gensim_caselist (op *p)
 {
   for (; p->name; p++)
     {
@@ -2854,8 +2833,7 @@ gensim_caselist (p)
       int sextbit = -1;
       int needm = 0;
       int needn = 0;
-      
-      char *s = p->code;
+      const char *s = p->code;
 
       printf ("  /* %s %s */\n", p->name, p->code);
       printf ("  case %d:      \n", p->index);
@@ -3038,7 +3016,7 @@ gensim_caselist (p)
 
       {
        /* Do the refs.  */
-       char *r;
+       const char *r;
        for (r = p->refs; *r; r++)
          {
            if (*r == 'f') printf ("      CREF (15);\n");
@@ -3080,7 +3058,7 @@ gensim_caselist (p)
 
       {
        /* Do the defs.  */
-       char *r;
+       const char *r;
        for (r = p->defs; *r; r++) 
          {
            if (*r == 'f') printf ("      CDEF (15);\n");
@@ -3114,7 +3092,7 @@ gensim_caselist (p)
 }
 
 static void
-gensim ()
+gensim (void)
 {
   printf ("{\n");
   printf ("/* REG_xy = [r4, r5, r0, r1].  */\n");
@@ -3143,19 +3121,17 @@ gensim ()
 }
 
 static void
-gendefines ()
+gendefines (void)
 {
   op *p;
   filltable (tab);
   for (p = tab; p->name; p++)
     {
-      char *s = p->name;
+      const char *s = p->name;
       printf ("#define OPC_");
       while (*s) {
-       if (isupper (*s)) 
-         *s = tolower (*s);
        if (isalpha (*s))
-         printf ("%c", *s);
+         printf ("%c", tolower (*s));
        if (*s == ' ')
          printf ("_");
        if (*s == '@')
@@ -3175,10 +3151,7 @@ static int ppi_index;
    NOTE: tail recursion optimization removed for simplicity.  */
 
 static void
-expand_ppi_code (val, i, s)
-     int val;
-     int i;
-     char *s;
+expand_ppi_code (int val, int i, const char *s)
 {
   int j;
 
@@ -3223,7 +3196,7 @@ expand_ppi_code (val, i, s)
 }
 
 static void
-ppi_filltable ()
+ppi_filltable (void)
 {
   op *p;
   ppi_index = 1;
@@ -3236,7 +3209,7 @@ ppi_filltable ()
 }
 
 static void
-ppi_gensim ()
+ppi_gensim (void)
 {
   op *p = ppi_tab;
 
@@ -3294,8 +3267,7 @@ ppi_gensim ()
       int shift, j;
       int cond = 0;
       int havedecl = 0;
-      
-      char *s = p->code;
+      const char *s = p->code;
 
       printf ("  /* %s %s */\n", p->name, p->code);
       printf ("  case %d:      \n", p->index);
@@ -3406,9 +3378,7 @@ ppi_gensim ()
 }
 
 int
-main (ac, av)
-     int ac;
-     char **av;
+main (int ac, char *av[])
 {
   /* Verify the table before anything else.  */
   {
@@ -3418,7 +3388,7 @@ main (ac, av)
        /* Check that the code field contains 16 bits.  */
        if (strlen (p->code) != 16)
          {
-           fprintf (stderr, "Code `%s' length wrong (%d) for `%s'\n",
+           fprintf (stderr, "Code `%s' length wrong (%zu) for `%s'\n",
                     p->code, strlen (p->code), p->name);
            abort ();
          }
This page took 0.031127 seconds and 4 git commands to generate.