"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  

libexo.h

Go to the documentation of this file.
00001 /*
00002  * libexo.h - EXO library interfaces (NEVER write another scanf()!)
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: libexo.h,v 1.1.1.1 2000/05/26 15:21:53 taustin Exp $
00053  *
00054  * $Log: libexo.h,v $
00055  * Revision 1.1.1.1  2000/05/26 15:21:53  taustin
00056  * SimpleScalar Tool Set
00057  *
00058  *
00059  * Revision 1.1  1998/08/27 08:55:28  taustin
00060  * Initial revision
00061  *
00062  *
00063  */
00064 
00065 /*
00066  * EXO(-skeletal) definitions:
00067  *
00068  *   The EXO format is used to store and retrieve data structures from text
00069  *   files.  The following BNF definition defines the contents of an EXO file:
00070  *
00071  *      <exo_file>      := <exo_term>
00072  *
00073  *      <exo_term>      := <exo_term_list>
00074  *                         | INTEGER
00075  *                         | FLOAT
00076  *                         | CHAR
00077  *                         | STRING
00078  *
00079  *      <exo_term_list> := (<exo_term_list> ',' <exo_term>)
00080  *                         | <exo_term>
00081  */
00082 
00083 #ifndef EXO_H
00084 #define EXO_H
00085 
00086 #include "../host.h"
00087 #include "../misc.h"
00088 #include "../machine.h"
00089 
00090 /* EXO file format versions */
00091 #define EXO_FMT_MAJOR           1
00092 #define EXO_FMT_MINOR           0
00093 
00094 /* EXO term classes, keep this in sync with EXO_CLASS_STR */
00095 enum exo_class_t {
00096   ec_integer,                   /* EXO int value */
00097   ec_address,                   /* EXO address value */
00098   ec_float,                     /* EXO FP value */
00099   ec_char,                      /* EXO character value */
00100   ec_string,                    /* EXO string value */
00101   ec_list,                      /* EXO list */
00102   ec_array,                     /* EXO array */
00103   ec_token,                     /* EXO token value */
00104   ec_blob,                      /* EXO blob (Binary Large OBject) */
00105   ec_null,                      /* used internally */
00106   ec_NUM
00107 };
00108 
00109 /* EXO term classes print strings */
00110 extern char *exo_class_str[ec_NUM];
00111 
00112 /* EXO token table entry */
00113 struct exo_token_t {
00114   struct exo_token_t *next;     /* next element in a hash buck chain */
00115   char *str;                    /* token string */
00116   int token;                    /* token value */
00117 };
00118 
00119 struct exo_term_t {
00120   struct exo_term_t *next;      /* next element, when in a list */
00121   enum exo_class_t ec;          /* term node class */
00122   union {
00123     struct as_integer_t {
00124       exo_integer_t val;                /* integer value */
00125     } as_integer;
00126     struct as_address_t {
00127       exo_address_t val;                /* address value */
00128     } as_address;
00129     struct as_float_t {
00130       exo_float_t val;                  /* floating point value */
00131     } as_float;
00132     struct as_char_t {
00133       char val;                         /* character value */
00134     } as_char;
00135     struct as_string_t {
00136       unsigned char *str;               /* string value */
00137     } as_string;
00138     struct as_list_t {
00139       struct exo_term_t *head;          /* list head pointer */
00140     } as_list;
00141     struct as_array_t {
00142       int size;                         /* size of the array */
00143       struct exo_term_t **array;        /* list head pointer */
00144     } as_array;
00145     struct as_token_t {
00146       struct exo_token_t *ent;          /* token table entry */
00147     } as_token;
00148     struct as_blob_t {
00149       int size;                         /* byte size of object */
00150       unsigned char *data;              /* pointer to blob data */
00151     } as_blob;
00152   } variant;
00153 };
00154 /* short-cut accessors */
00155 #define as_integer      variant.as_integer
00156 #define as_address      variant.as_address
00157 #define as_float        variant.as_float
00158 #define as_char         variant.as_char
00159 #define as_string       variant.as_string
00160 #define as_list         variant.as_list
00161 #define as_array        variant.as_array
00162 #define as_token        variant.as_token
00163 #define as_blob         variant.as_blob
00164 
00165 /* EXO array accessor, may be used as an L-value or R-value */
00166 /* EXO array accessor, may be used as an L-value or R-value */
00167 #define EXO_ARR(E,N)                                                    \
00168   ((E)->ec != ec_array                                                  \
00169    ? (fatal("not an array"), *(struct exo_term_t **)(NULL))             \
00170    : ((N) >= (E)->as_array.size                                         \
00171       ? (fatal("array bounds error"), *(struct exo_term_t **)(NULL))    \
00172       : (E)->as_array.array[(N)]))
00173 #define SET_EXO_ARR(E,N,V)                                              \
00174   ((E)->ec != ec_array                                                  \
00175    ? (void)fatal("not an array")                                        \
00176    : ((N) >= (E)->as_array.size                                         \
00177       ? (void)fatal("array bounds error")                               \
00178       : (void)((E)->as_array.array[(N)] = (V))))
00179 
00180 /* intern token TOKEN_STR */
00181 struct exo_token_t *
00182 exo_intern(char *token_str);            /* string to intern */
00183 
00184 /* intern token TOKEN_STR as value TOKEN */
00185 struct exo_token_t *
00186 exo_intern_as(char *token_str,          /* string to intern */
00187               int token);               /* internment value */
00188 
00189 /*
00190  * create a new EXO term, usage:
00191  *
00192  *      exo_new(ec_integer, (exo_integer_t)<int>);
00193  *      exo_new(ec_address, (exo_address_t)<int>);
00194  *      exo_new(ec_float, (exo_float_t)<float>);
00195  *      exo_new(ec_char, (int)<char>);
00196  *      exo_new(ec_string, "<string>");
00197  *      exo_new(ec_list, <list_ent>..., NULL);
00198  *      exo_new(ec_array, <size>, <array_ent>..., NULL);
00199  *      exo_new(ec_token, "<token>");
00200  *      exo_new(ec_blob, <size>, <data_ptr>);
00201  */
00202 struct exo_term_t *
00203 exo_new(enum exo_class_t ec, ...);
00204 
00205 /* release an EXO term */
00206 void
00207 exo_delete(struct exo_term_t *exo);
00208 
00209 /* chain two EXO lists together, FORE is attached on the end of AFT */
00210 struct exo_term_t *
00211 exo_chain(struct exo_term_t *fore, struct exo_term_t *aft);
00212 
00213 /* copy an EXO node */
00214 struct exo_term_t *
00215 exo_copy(struct exo_term_t *exo);
00216 
00217 /* deep copy an EXO structure */
00218 struct exo_term_t *
00219 exo_deepcopy(struct exo_term_t *exo);
00220 
00221 /* print an EXO term */
00222 void
00223 exo_print(struct exo_term_t *exo, FILE *stream);
00224 
00225 /* read one EXO term from STREAM */
00226 struct exo_term_t *
00227 exo_read(FILE *stream);
00228 
00229 /* lexor components */
00230 enum lex_t {
00231   lex_integer = 256,
00232   lex_address,
00233   lex_float,
00234   lex_char,
00235   lex_string,
00236   lex_token,
00237   lex_byte,
00238   lex_eof
00239 };
00240 
00241 #endif /* EXO_H */


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