Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/gspa/gspa provide initialized C array output direct...



details:   https://anonhg.NetBSD.org/src/rev/588cc5d4e608
branches:  trunk
changeset: 473941:588cc5d4e608
user:      is <is%NetBSD.org@localhost>
date:      Tue Jun 22 20:27:21 1999 +0000

description:
provide initialized C array output directly, rather than through postprocessor

diffstat:

 usr.sbin/gspa/gspa/gsp_ass.h |   2 +-
 usr.sbin/gspa/gspa/gsp_out.c |  74 ++++++++++++++++++++++++++++++++++++-------
 usr.sbin/gspa/gspa/gspa.c    |  30 +++++++++++++++--
 3 files changed, 89 insertions(+), 17 deletions(-)

diffs (223 lines):

diff -r 079e767d933f -r 588cc5d4e608 usr.sbin/gspa/gspa/gsp_ass.h
--- a/usr.sbin/gspa/gspa/gsp_ass.h      Tue Jun 22 20:00:47 1999 +0000
+++ b/usr.sbin/gspa/gspa/gsp_ass.h      Tue Jun 22 20:27:21 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: gsp_ass.h,v 1.4 1999/06/22 20:00:47 is Exp $   */
+/*     $NetBSD: gsp_ass.h,v 1.5 1999/06/22 20:27:21 is Exp $   */
 /*
  * GSP assembler - definitions
  *
diff -r 079e767d933f -r 588cc5d4e608 usr.sbin/gspa/gspa/gsp_out.c
--- a/usr.sbin/gspa/gspa/gsp_out.c      Tue Jun 22 20:00:47 1999 +0000
+++ b/usr.sbin/gspa/gspa/gsp_out.c      Tue Jun 22 20:27:21 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: gsp_out.c,v 1.4 1999/06/22 20:00:47 is Exp $   */
+/*     $NetBSD: gsp_out.c,v 1.5 1999/06/22 20:27:21 is Exp $   */
 /*
  * GSP assembler - binary & listing output
  *
@@ -33,7 +33,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: gsp_out.c,v 1.4 1999/06/22 20:00:47 is Exp $");
+__RCSID("$NetBSD: gsp_out.c,v 1.5 1999/06/22 20:27:21 is Exp $");
 #endif
 
 #include <stdio.h>
@@ -54,6 +54,13 @@
 extern FILE *objfile, *listfile;
 extern char line[];
 
+extern char *c_name;
+u_int16_t c_buf[4096];
+u_int32_t c_bufptr, c_binads;
+
+void c_checkbuf(void);
+void c_dumpbuf(void);
+
 struct error {
        struct error *next;
        char    string[1];
@@ -82,18 +89,29 @@
        codes[code_idx] = v;
        if( objfile != NULL ){
                if( pc != obj_addr ){
-                       /* expect this only when ncode == 0 */
-                       if( ncode % 8 != 0 )
-                               fprintf(objfile, "\n");
-                       fprintf(objfile, "@%x\n", pc);
+                       if (c_name) {
+                               if (c_bufptr > 0)
+                                       c_dumpbuf();
+                               c_binads = pc;
+                               c_bufptr = 0;
+                       } else {
+                               /* expect this only when ncode == 0 */
+                               if (ncode % 8 != 0)
+                                       fprintf(objfile, "\n");
+                               fprintf(objfile, "@%x\n", pc);
+                       }
                        obj_addr = pc;
                } else {
-                       if( ncode % 8 != 0 )
+                       if((ncode % 8 != 0) && !c_name)
                                fprintf(objfile, " ");
                }
-               fprintf(objfile, "%.4X", v & 0xFFFF);
+               if (c_name) {
+                       c_checkbuf();
+                       c_buf[c_bufptr++] = v;
+               } else
+                       fprintf(objfile, "%.4X", v & 0xFFFF);
                obj_addr += 0x10;
-               if( ncode % 8 == 7 )
+               if((ncode % 8 == 7) && !c_name)
                        fprintf(objfile, "\n");
        }
        ++ncode;
@@ -103,10 +121,42 @@
 }
 
 void
+c_checkbuf() 
+{
+       if (c_bufptr > (sizeof(c_buf)/sizeof(*c_buf)))
+               c_dumpbuf();
+}
+
+void
+c_dumpbuf()
+{
+       int i;
+
+       printf("\n\n\t%d, 0x%04x, 0x%04x, /* new block */",
+           c_bufptr, (int)(c_binads >> 16), (int)(c_binads & 0xffff));
+
+       for (i=0; i < c_bufptr; ++i) {
+               if (i%8 == 0)
+                       printf("\n\t");
+               printf("0x%04x, ", c_buf[i]);
+       }
+       c_binads += c_bufptr;
+       c_bufptr = 0;
+}
+
+void
 start_at(u_int32_t val)
 {
-       if( objfile != NULL )
-               fprintf(objfile, ":%lX\n", (long)val);
+       if( objfile != NULL ) {
+               if (c_name) {
+                       c_checkbuf();
+                       fprintf(objfile,
+                           "\n\n\t2, 0xffff, 0xfee0, 0x%04x, 0x%04x,"
+                             "\n\t2, 0xffff, 0xffe0, 0x%04x, 0x%04x,\n",
+                           val & 0xffff, val >> 16, val & 0xffff, val >> 16);
+               } else
+                       fprintf(objfile, ":%lX\n", (long)val);
+       }
 }
 
 void
@@ -162,7 +212,7 @@
 void
 listing()
 {
-       if( objfile != NULL && ncode % 8 != 0 )
+       if( objfile != NULL && ncode % 8 != 0 && !c_name)
                fprintf(objfile, "\n");
        listing_line();
        show_errors();
diff -r 079e767d933f -r 588cc5d4e608 usr.sbin/gspa/gspa/gspa.c
--- a/usr.sbin/gspa/gspa/gspa.c Tue Jun 22 20:00:47 1999 +0000
+++ b/usr.sbin/gspa/gspa/gspa.c Tue Jun 22 20:27:21 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: gspa.c,v 1.4 1998/04/09 00:32:40 tv Exp $      */
+/*     $NetBSD: gspa.c,v 1.5 1999/06/22 20:27:21 is Exp $      */
 /*
  * GSP assembler main program
  *
@@ -33,7 +33,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: gspa.c,v 1.4 1998/04/09 00:32:40 tv Exp $");
+__RCSID("$NetBSD: gspa.c,v 1.5 1999/06/22 20:27:21 is Exp $");
 #endif
 
 #include <sys/param.h>
@@ -69,6 +69,7 @@
 FILE *objfile;
 FILE *listfile;
 
+char *c_name;
 char in_name[PATH_MAX + 1];
 
 struct input {
@@ -84,6 +85,8 @@
 void   usage(void);
 int    yyparse(void);
 
+void   c_dumpbuf(void);
+
 int
 main(int argc, char **argv)
 {
@@ -98,13 +101,18 @@
        hex_name = list_name = 0;
 
        /* parse options */
-       while ((c = getopt(argc, argv, "o:l:")) != -1) {
+       while ((c = getopt(argc, argv, "o:l:c:")) != -1) {
                switch (c) {
                case 'o':
                        if (hex_name)
                                usage();
                        hex_name = optarg;
                        break;
+               case 'c':
+                       if (c_name)
+                               usage();
+                       c_name = optarg;
+                       break;
                case 'l':
                        if (list_name)
                                usage();
@@ -151,6 +159,15 @@
                objfile = stdout;
        else if ((objfile = fopen(hex_name, "w")) == NULL)
                err(1, "fopen");
+       if (c_name) {
+               fprintf(objfile, "/*\n"
+                   " * This file was automatically created from\n"
+                   " * a TMS34010 assembler output file.\n"
+                   " * Do not edit manually.\n"
+                   " */\n"
+                   "#include <sys/types.h>\n"
+                   "u_int16_t %s[] = {\n\t", c_name);
+       }
        if (list_name)
                if ((listfile = fopen(list_name, "w")) == NULL)
                        err(1, "fopen");
@@ -171,6 +188,11 @@
                listing();
        }
 
+       if (c_name) {
+               c_dumpbuf();
+               fprintf(objfile, "\n\t0\n};\n");
+       }
+
        exit(err_count != 0);
 }
 
@@ -285,6 +307,6 @@
 usage()
 {
        fprintf(stderr,
-               "Usage: gspa [infile] [+o|-o hex_file] [+l|-l list_file]\n");
+               "Usage: gspa [infile] [-c c_array_name|+o|-o hex_file] [+l|-l list_file]\n");
        exit(1);
 }



Home | Main Index | Thread Index | Old Index