"I am a person who works hard and plays hard."

Yuan Wei
Second Year Graduate Student Department of Computer Science
University of Virginia Charlottesville, VA 22903
Email: yw3f@cs.virginia.edu


Source Code Analysis

Main Page   Compound List   File List   Compound Members   File Members  

exo-test.c

Go to the documentation of this file.
00001 /*
00002  * exo-test.c - EXO library test driver
00003  *
00004  * This file is a part of the SimpleScalar tool suite written by
00005  * Todd M. Austin as a part of the Multiscalar Research Project.
00006  *
00007  * The tool suite is currently maintained by Doug Burger and Todd M. Austin.
00008  *
00009  * Copyright (C) 1997 by Todd M. Austin
00010  *
00011  * This source file is distributed "as is" in the hope that it will be
00012  * useful.  The tool set comes with no warranty, and no author or
00013  * distributor accepts any responsibility for the consequences of its
00014  * use. 
00015  *
00016  * Everyone is granted permission to copy, modify and redistribute
00017  * this tool set under the following conditions:
00018  *
00019  *    This source code is distributed for non-commercial use only. 
00020  *    Please contact the maintainer for restrictions applying to 
00021  *    commercial use.
00022  *
00023  *    Permission is granted to anyone to make or distribute copies
00024  *    of this source code, either as received or modified, in any
00025  *    medium, provided that all copyright notices, permission and
00026  *    nonwarranty notices are preserved, and that the distributor
00027  *    grants the recipient permission for further redistribution as
00028  *    permitted by this document.
00029  *
00030  *    Permission is granted to distribute this file in compiled
00031  *    or executable form under the same conditions that apply for
00032  *    source code, provided that either:
00033  *
00034  *    A. it is accompanied by the corresponding machine-readable
00035  *       source code,
00036  *    B. it is accompanied by a written offer, with no time limit,
00037  *       to give anyone a machine-readable copy of the corresponding
00038  *       source code in return for reimbursement of the cost of
00039  *       distribution.  This written offer must permit verbatim
00040  *       duplication by anyone, or
00041  *    C. it is distributed by someone who received only the
00042  *       executable form, and is accompanied by a copy of the
00043  *       written offer of source code that they received concurrently.
00044  *
00045  * In other words, you are welcome to use, share and improve this
00046  * source file.  You are forbidden to forbid anyone else to use, share
00047  * and improve what you give them.
00048  *
00049  * INTERNET: dburger@cs.wisc.edu
00050  * US Mail:  1210 W. Dayton Street, Madison, WI 53706
00051  *
00052  * $Id: exo-test.c,v 1.1.1.1 2000/05/26 15:21:53 taustin Exp $
00053  *
00054  * $Log: exo-test.c,v $
00055  * Revision 1.1.1.1  2000/05/26 15:21:53  taustin
00056  * SimpleScalar Tool Set
00057  *
00058  *
00059  *
00060  */
00061 
00062 #include <stdio.h>
00063 #include <stdlib.h>
00064 #include "misc.h"
00065 #include "options.h"
00066 #include "libexo.h"
00067 
00068 /* options database */
00069 static struct opt_odb_t *odb;
00070 
00071 /* dump help information */
00072 static int help_me;
00073 
00074 /* make internal defs */
00075 static int make_defs;
00076 
00077 /* EXO file to load */
00078 static char *load_file;
00079 
00080 /* EXO file to save */
00081 static char *save_file;
00082 
00083 /* print the EXO DB to stdout */
00084 static int print_db;
00085 
00086 /* EXO definition data base */
00087 static struct exo_term_t *exo_db = NULL;
00088 
00089 static void
00090 usage(FILE *stream, int argc, char **argv)
00091 {
00092   fprintf(stream, "Usage: %s {-options}\n", argv[0]);
00093   opt_print_help(odb, stream);
00094 }
00095 
00096 void
00097 main(int argc, char **argv)
00098 {
00099   /* build the command line options database */
00100   odb = opt_new(/* no orphan fn */NULL);
00101   opt_reg_flag(odb, "-h", "print help message",
00102                &help_me, /* default */FALSE, /* !print */FALSE, NULL);
00103   opt_reg_flag(odb, "-defs", "make internal defs",
00104                &make_defs, /* default */FALSE, /* print */TRUE, NULL);
00105   opt_reg_string(odb, "-load", "load an EXO file",
00106                  &load_file, /* default */NULL,
00107                  /* print */TRUE, /* format */NULL);
00108   opt_reg_string(odb, "-save", "save an EXO file",
00109                  &save_file, /* default */NULL,
00110                  /* print */TRUE, /* format */NULL);
00111   opt_reg_flag(odb, "-print", "print the EXO DB to stdout",
00112                &print_db, /* default */FALSE,
00113                /* print */TRUE, /* format */NULL);
00114 
00115   /* process the command line options */
00116   opt_process_options(odb, argc, argv);
00117 
00118   if (help_me)
00119     {
00120       /* print help message and exit */
00121       usage(stderr, argc, argv);
00122       exit(1);
00123     }
00124 
00125   /* print options used */
00126   opt_print_options(odb, stderr, /* short */TRUE, /* notes */TRUE);
00127 
00128   if (load_file)
00129     {
00130       ZFILE *exo_stream;
00131       struct exo_term_t *exo;
00132 
00133       exo_stream = myzfopen(load_file, "r");
00134       if (!exo_stream)
00135         fatal("could not open EXO file `%s'", load_file);
00136 
00137       while ((exo = exo_read(exo_stream->fd)) != NULL)
00138         exo_db = exo_chain(exo_db, exo);
00139 
00140       myzfclose(exo_stream);
00141     }
00142 
00143   if (make_defs)
00144     {
00145       struct exo_term_t *list, *array, *a, *b, *c, *d, *e, *f, *g, *h, *i;
00146       char *data = "This is a test to see if blobs really work...";
00147       char *data1 = "This is a test to see if blobs really work..."
00148         "This is a test to see if blobs really work..."
00149           "This is a test to see if blobs really work..."
00150             "This is a test to see if blobs really work..."
00151               "This is a test to see if blobs really work..."
00152                 "This is a test to see if blobs really work..."
00153                   "This is a test to see if blobs really work..."
00154                     "This is a test to see if blobs really work...";
00155       unsigned char data2[16] =
00156         { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
00157 
00158       exo_db =
00159         exo_chain(exo_db, exo_new(ec_string, "** basic types tests **"));
00160       exo_db = exo_chain(exo_db, a = exo_new(ec_integer, (exo_integer_t)42));
00161       exo_db = exo_chain(b = exo_new(ec_float, (exo_float_t)42.0), exo_db);
00162       exo_db = exo_chain(exo_db, c = exo_new(ec_char, (int)'x'));
00163       exo_db = exo_chain(exo_db, exo_new(ec_char, (int)'\n'));
00164       exo_db = exo_chain(exo_db, exo_new(ec_char, (int)'\b'));
00165       exo_db = exo_chain(exo_db, exo_new(ec_char, (int)'\x02'));
00166       exo_db = exo_chain(exo_db, exo_new(ec_char, (int)'\xab'));
00167       exo_db = exo_chain(exo_db, exo_new(ec_string, "this is a test..."));
00168       exo_db =
00169         exo_chain(exo_db, d = exo_new(ec_string, "this is\na test...\n"));
00170       exo_db = exo_chain(exo_db, exo_new(ec_string, "a test... <<\\\b>>\n"));
00171 
00172       exo_db = exo_chain(exo_db, exo_new(ec_string, "** deep copy tests **"));
00173       exo_db = exo_chain(exo_db, exo_deepcopy(d));
00174       exo_db = exo_chain(exo_db, exo_deepcopy(c));
00175       exo_db = exo_chain(exo_db, exo_deepcopy(b));
00176       exo_db = exo_chain(exo_db, exo_deepcopy(a));
00177 
00178       exo_db = exo_chain(exo_db, exo_new(ec_string, "** list tests **"));
00179       exo_db =
00180         exo_chain(exo_db, exo_new(ec_list,
00181                                   exo_deepcopy(d), exo_deepcopy(c),
00182                                   exo_deepcopy(b), exo_deepcopy(a), NULL));
00183       exo_db = exo_chain(exo_db, exo_new(ec_list, NULL));
00184       exo_db =
00185         exo_chain(exo_db, exo_new(ec_list,
00186                                   exo_new(ec_list, NULL),
00187                                   exo_new(ec_list, NULL),
00188                                   exo_new(ec_list, exo_deepcopy(a), NULL),
00189                                   NULL));
00190       list = exo_deepcopy(a);
00191       list = exo_chain(list, exo_deepcopy(b));
00192       list = exo_chain(list, exo_deepcopy(a));
00193       list = exo_chain(list, exo_deepcopy(b));
00194       list = exo_chain(exo_deepcopy(c), list);
00195       exo_db = exo_chain(exo_db, e = exo_new(ec_list, list, NULL));
00196       exo_db = exo_chain(exo_db, exo_new(ec_list,
00197                                          exo_deepcopy(e),
00198                                          exo_new(ec_list, NULL),
00199                                          exo_deepcopy(e),
00200                                          exo_deepcopy(a), NULL));
00201 
00202       exo_db = exo_chain(exo_db, exo_new(ec_string, "** array tests **"));
00203       exo_db = exo_chain(exo_db, exo_new(ec_array, 16, NULL));
00204       f = array = exo_new(ec_array, 16, NULL);
00205       EXO_ARR(array, 2) = exo_deepcopy(e);
00206       EXO_ARR(array, 3) = exo_deepcopy(a);
00207       EXO_ARR(array, 4) = exo_deepcopy(c);
00208       EXO_ARR(array, 6) = exo_deepcopy(EXO_ARR(array, 2));
00209       EXO_ARR(array, 7) = exo_deepcopy(EXO_ARR(array, 1));
00210       exo_db = exo_chain(exo_db, array);
00211       exo_db =
00212         exo_chain(exo_db, exo_new(ec_array, 4,
00213                                   exo_deepcopy(a),
00214                                   exo_deepcopy(e),
00215                                   exo_deepcopy(c),
00216                                   exo_deepcopy(f),
00217                                   NULL));
00218 
00219       exo_db = exo_chain(exo_db, exo_new(ec_string, "** token tests **"));
00220 #define SYM1            1
00221 #define SYM2            2
00222       exo_intern_as("sym1", SYM1);
00223       exo_intern_as("sym2", SYM2);
00224       g = exo_new(ec_token, "sym1"),
00225       exo_db = exo_chain(exo_db,
00226                          exo_new(ec_list,
00227                                  g,
00228                                  exo_new(ec_integer,
00229                                          (exo_integer_t)
00230                                          g->as_token.ent->token),
00231                                  NULL));
00232       h = exo_new(ec_token, "sym2"),
00233       exo_db = exo_chain(exo_db,
00234                          exo_new(ec_list,
00235                                  h,
00236                                  exo_new(ec_integer,
00237                                          (exo_integer_t)
00238                                          h->as_token.ent->token),
00239                                  NULL));
00240       i = exo_new(ec_token, "sym3"),
00241       exo_db = exo_chain(exo_db,
00242                          exo_new(ec_list,
00243                                  i,
00244                                  exo_new(ec_integer,
00245                                          (exo_integer_t)
00246                                          i->as_token.ent->token),
00247                                  NULL));
00248 
00249       /* das blobs */
00250       exo_db = exo_chain(exo_db, exo_new(ec_blob, strlen(data), data));
00251       exo_db = exo_chain(exo_db, exo_new(ec_blob, strlen(data1), data1));
00252       exo_db = exo_chain(exo_db, exo_new(ec_blob, sizeof(data2), data2));
00253     }
00254 
00255   if (print_db)
00256     {
00257       struct exo_term_t *exo;
00258 
00259       /* emit header comment */
00260       fprintf(stdout, "\n/* EXO DB */\n\n");
00261       fprintf(stdout,
00262               "/* EXO save file, file format version %d.%d */\n\n",
00263               EXO_FMT_MAJOR, EXO_FMT_MINOR);
00264 
00265       /* emit all defs */
00266       for (exo=exo_db; exo != NULL; exo=exo->next)
00267         {
00268           exo_print(exo, stdout);
00269           fprintf(stdout, "\n\n");
00270         }
00271     }
00272 
00273   if (save_file)
00274     {
00275       ZFILE *exo_stream;
00276       struct exo_term_t *exo;
00277 
00278       exo_stream = myzfopen(save_file, "w");
00279       if (!exo_stream)
00280         fatal("could not open EXO file `%s'", save_file);
00281 
00282       /* emit header comment */
00283       fprintf(exo_stream->fd,
00284               "/* EXO save file, file format version %d.%d */\n\n",
00285               EXO_FMT_MAJOR, EXO_FMT_MINOR);
00286 
00287       /* emit all defs */
00288       for (exo=exo_db; exo != NULL; exo=exo->next)
00289         {
00290           exo_print(exo, exo_stream->fd);
00291           fprintf(exo_stream->fd, "\n\n");
00292         }
00293       myzfclose(exo_stream);
00294     }
00295 }


UVa CS Department of Computer Science
School of Engineering, University of Virginia
151 Engineer's Way, P.O. Box 400740
Charlottesville, Virginia 22904-4740

(434) 982-2200  Fax: (434) 982-2214