"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  

options.h

Go to the documentation of this file.
00001 /*
00002  * options.h - options package interfaces
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) 1994, 1995, 1996, 1997, 1998 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: options.h,v 1.1.1.1 2000/05/26 15:18:57 taustin Exp $
00053  *
00054  * $Log: options.h,v $
00055  * Revision 1.1.1.1  2000/05/26 15:18:57  taustin
00056  * SimpleScalar Tool Set
00057  *
00058  *
00059  * Revision 1.2  1998/08/27 15:48:03  taustin
00060  * implemented host interface description in host.h
00061  *
00062  * Revision 1.1  1997/03/11  01:31:53  taustin
00063  * Initial revision
00064  *
00065  *
00066  */
00067 
00068 #ifndef OPTIONS_H
00069 #define OPTIONS_H
00070 
00071 /*
00072  * This options package allows the user to specify the name, description,
00073  * location, and default values of program option variables.  In addition,
00074  * two builtin options are supported:
00075  *
00076  *   -config <filename>         # load options from <filename>
00077  *   -dumpconfig <filename>     # save current option into <filename>
00078  *
00079  * NOTE: all user-installed option names must begin with a `-', e.g., `-debug'
00080  */
00081 
00082 /* option variable classes */
00083 enum opt_class_t {
00084   oc_int = 0,           /* integer option */
00085   oc_uint,              /* unsigned integer option */
00086   oc_float,             /* float option */
00087   oc_double,            /* double option */
00088   oc_enum,              /* enumeration option */
00089   oc_flag,              /* boolean option */
00090   oc_string,            /* string option */
00091   oc_NUM
00092 };
00093 
00094 /* user-specified option definition */
00095 struct opt_opt_t {
00096   struct opt_opt_t *next;       /* next option */
00097   char *name;                   /* option name, e.g., "-foo:bar" */
00098   char *desc;                   /* option description */
00099   int nvars;                    /* > 1 if var for list options */
00100   int *nelt;                    /* number of elements parsed */
00101   char *format;                 /* option value print format */
00102   int print;                    /* print option during `-dumpconfig'? */
00103   int accrue;                   /* accrue list across uses */
00104   enum opt_class_t oc;          /* class of this option */
00105   union opt_variant_t {
00106     /* oc == oc_int */
00107     struct opt_for_int_t {
00108       int *var;                 /* pointer to integer option */
00109     } for_int;
00110     /* oc == oc_uint */
00111     struct opt_for_uint_t {
00112       unsigned int *var;        /* pointer to unsigned integer option */
00113     } for_uint;
00114     /* oc == oc_float */
00115     struct opt_for_float_t {
00116       float *var;               /* pointer to float option */
00117     } for_float;
00118     /* oc == oc_double */
00119     struct opt_for_double_t {
00120       double *var;              /* pointer to double option */
00121     } for_double;
00122     /* oc == oc_enum, oc_flag */
00123     struct opt_for_enum_t {
00124       int *var;                 /* ptr to *int* enum option, NOTE: AN INT */
00125       char **emap;              /* array of enum strings */
00126       int *eval;                /* optional array of enum values */
00127       int emap_sz;              /* number of enum's in arrays */
00128     } for_enum;
00129     /* oc == oc_string */
00130     struct opt_for_string_t {
00131       char **var;               /* pointer to string pointer option */
00132     } for_string;
00133   } variant;
00134 };
00135 
00136 /* user-specified argument orphan parser, called when an argument is
00137    encountered that is not claimed by a user-installed option */
00138 typedef int
00139 (*orphan_fn_t)(int i,           /* index of the orphan'ed argument */
00140                int argc,        /* number of program arguments */
00141                char **argv);    /* program arguments */
00142 
00143 /* an option note, these trail the option list when help or option state
00144    is printed */
00145 struct opt_note_t {
00146   struct opt_note_t *next;      /* next option note */
00147   char *note;                   /* option note */
00148 };
00149 
00150 /* option database definition */
00151 struct opt_odb_t {
00152   struct opt_opt_t *options;    /* user-installed options in option database */
00153   orphan_fn_t orphan_fn;        /* user-specified orphan parser */
00154   char *header;                 /* options header */
00155   struct opt_note_t *notes;     /* option notes */
00156 };
00157 
00158 /* create a new option database */
00159 struct opt_odb_t *
00160 opt_new(orphan_fn_t orphan_fn);         /* user-specified orphan parser */
00161 
00162 /* free an option database */
00163 void
00164 opt_delete(struct opt_odb_t *odb);      /* option database */
00165 
00166 /* register an integer option variable */
00167 void
00168 opt_reg_int(struct opt_odb_t *odb,      /* option database */
00169             char *name,                 /* option name */
00170             char *desc,                 /* option description */
00171             int *var,                   /* pointer to option variable */
00172             int def_val,                /* default value of option variable */
00173             int print,                  /* print during `-dumpconfig' */
00174             char *format);              /* optional user print format */
00175 
00176 /* register an integer option list */
00177 void
00178 opt_reg_int_list(struct opt_odb_t *odb, /* option database */
00179                  char *name,            /* option name */
00180                  char *desc,            /* option description */
00181                  int *vars,             /* pointer to option array */
00182                  int nvars,             /* total entries in option array */
00183                  int *nelt,             /* number of entries parsed */
00184                  int *def_val,          /* default value of option array */
00185                  int print,             /* print during `-dumpconfig'? */
00186                  char *format,          /* optional user print format */
00187                  int accrue);           /* accrue list across uses */
00188 
00189 /* register an unsigned integer option variable */
00190 void
00191 opt_reg_uint(struct opt_odb_t *odb,     /* option database */
00192              char *name,                /* option name */
00193              char *desc,                /* option description */
00194              unsigned int *var,         /* pointer to option variable */
00195              unsigned int def_val,      /* default value of option variable */
00196              int print,                 /* print during `-dumpconfig'? */
00197              char *format);             /* optional user print format */
00198 
00199 /* register an unsigned integer option list */
00200 void
00201 opt_reg_uint_list(struct opt_odb_t *odb,/* option database */
00202                   char *name,           /* option name */
00203                   char *desc,           /* option description */
00204                   unsigned int *vars,   /* pointer to option array */
00205                   int nvars,            /* total entries in option array */
00206                   int *nelt,            /* number of elements parsed */
00207                   unsigned int *def_val,/* default value of option array */
00208                   int print,            /* print during `-dumpconfig'? */
00209                   char *format,         /* optional user print format */
00210                   int accrue);          /* accrue list across uses */
00211 
00212 /* register a single-precision floating point option variable */
00213 void
00214 opt_reg_float(struct opt_odb_t *odb,    /* option data base */
00215               char *name,               /* option name */
00216               char *desc,               /* option description */
00217               float *var,               /* target option variable */
00218               float def_val,            /* default variable value */
00219               int print,                /* print during `-dumpconfig'? */
00220               char *format);            /* optional value print format */
00221 
00222 /* register a single-precision floating point option array */
00223 void
00224 opt_reg_float_list(struct opt_odb_t *odb,/* option data base */
00225                    char *name,          /* option name */
00226                    char *desc,          /* option description */
00227                    float *vars,         /* target array */
00228                    int nvars,           /* target array size */
00229                    int *nelt,           /* number of args parsed goes here */
00230                    float *def_val,      /* default variable value */
00231                    int print,           /* print during `-dumpconfig'? */
00232                    char *format,        /* optional value print format */
00233                    int accrue);         /* accrue list across uses */
00234 
00235 /* register a double-precision floating point option variable */
00236 void
00237 opt_reg_double(struct opt_odb_t *odb,   /* option data base */
00238                char *name,              /* option name */
00239                char *desc,              /* option description */
00240                double *var,             /* target variable */
00241                double def_val,          /* default variable value */
00242                int print,               /* print during `-dumpconfig'? */
00243                char *format);           /* optional value print format */
00244 
00245 /* register a double-precision floating point option array */
00246 void
00247 opt_reg_double_list(struct opt_odb_t *odb,/* option data base */
00248                     char *name,         /* option name */
00249                     char *desc,         /* option description */
00250                     double *vars,       /* target array */
00251                     int nvars,          /* target array size */
00252                     int *nelt,          /* number of args parsed goes here */
00253                     double *def_val,    /* default variable value */
00254                     int print,          /* print during `-dumpconfig'? */
00255                     char *format,       /* optional value print format */
00256                     int accrue);        /* accrue list across uses */
00257 
00258 /* register an enumeration option variable, NOTE: all enumeration option
00259    variables must be of type `int', since true enum variables may be allocated
00260    with variable sizes by some compilers */
00261 void
00262 opt_reg_enum(struct opt_odb_t *odb,     /* option data base */
00263              char *name,                /* option name */
00264              char *desc,                /* option description */
00265              int *var,                  /* target variable */
00266              char *def_val,             /* default variable value */
00267              char **emap,               /* enumeration string map */
00268              int *eval,                 /* enumeration value map, optional */
00269              int emap_sz,               /* size of maps */
00270              int print,                 /* print during `-dumpconfig'? */
00271              char *format);             /* optional value print format */
00272 
00273 /* register an enumeration option array, NOTE: all enumeration option variables
00274    must be of type `int', since true enum variables may be allocated with
00275    variable sizes by some compilers */
00276 void
00277 opt_reg_enum_list(struct opt_odb_t *odb,/* option data base */
00278                   char *name,           /* option name */
00279                   char *desc,           /* option description */
00280                   int *vars,            /* target array */
00281                   int nvars,            /* target array size */
00282                   int *nelt,            /* number of args parsed goes here */
00283                   char *def_val,        /* default variable value */
00284                   char **emap,          /* enumeration string map */
00285                   int *eval,            /* enumeration value map, optional */
00286                   int emap_sz,          /* size of maps */
00287                   int print,            /* print during `-dumpconfig'? */
00288                   char *format,         /* optional value print format */
00289                   int accrue);          /* accrue list across uses */
00290 
00291 /* register a boolean flag option variable */
00292 void
00293 opt_reg_flag(struct opt_odb_t *odb,     /* option data base */
00294              char *name,                /* option name */
00295              char *desc,                /* option description */
00296              int *var,                  /* target variable */
00297              int def_val,               /* default variable value */
00298              int print,                 /* print during `-dumpconfig'? */
00299              char *format);             /* optional value print format */
00300 
00301 /* register a boolean flag option array */
00302 void
00303 opt_reg_flag_list(struct opt_odb_t *odb,/* option database */
00304                   char *name,           /* option name */
00305                   char *desc,           /* option description */
00306                   int *vars,            /* pointer to option array */
00307                   int nvars,            /* total entries in option array */
00308                   int *nelt,            /* number of elements parsed */
00309                   int *def_val,         /* default array value */
00310                   int print,            /* print during `-dumpconfig'? */
00311                   char *format,         /* optional value print format */
00312                   int accrue);          /* accrue list across uses */
00313 
00314 /* register a string option variable */
00315 void
00316 opt_reg_string(struct opt_odb_t *odb,   /* option data base */
00317                char *name,              /* option name */
00318                char *desc,              /* option description */
00319                char **var,              /* pointer to string option variable */
00320                char *def_val,           /* default variable value */
00321                int print,               /* print during `-dumpconfig'? */
00322                char *format);           /* optional value print format */
00323 
00324 /* register a string option array */
00325 void
00326 opt_reg_string_list(struct opt_odb_t *odb,/* option data base */
00327                     char *name,         /* option name */
00328                     char *desc,         /* option description */
00329                     char **vars,        /* pointer to option string array */
00330                     int nvars,          /* target array size */
00331                     int *nelt,          /* number of args parsed goes here */
00332                     char **def_val,     /* default variable value */
00333                     int print,          /* print during `-dumpconfig'? */
00334                     char *format,       /* optional value print format */
00335                     int accrue);        /* accrue list across uses */
00336 
00337 /* process command line arguments */
00338 void
00339 opt_process_options(struct opt_odb_t *odb,      /* option data base */
00340                     int argc,                   /* number of arguments */
00341                     char **argv);               /* argument array */
00342 
00343 /* print the value of an option */
00344 void
00345 opt_print_option(struct opt_opt_t *opt, /* option variable */
00346                  FILE *fd);             /* output stream */
00347 
00348 /* print all options and current values */
00349 void
00350 opt_print_options(struct opt_odb_t *odb,/* option data base */
00351                   FILE *fd,             /* output stream */
00352                   int terse,            /* print terse options? */
00353                   int notes);           /* include notes? */
00354 
00355 /* print option help page with default values */
00356 void
00357 opt_print_help(struct opt_odb_t *odb,   /* option data base */
00358                FILE *fd);               /* output stream */
00359 
00360 /* find an option by name in the option database, returns NULL if not found */
00361 struct opt_opt_t *
00362 opt_find_option(struct opt_odb_t *odb,  /* option database */
00363                 char *opt_name);        /* option name */
00364 
00365 /* register an options header, the header is printed before the option list */
00366 void
00367 opt_reg_header(struct opt_odb_t *odb,   /* option database */
00368                char *header);           /* options header string */
00369 
00370 /* register an option note, notes are printed after the list of options */
00371 void
00372 opt_reg_note(struct opt_odb_t *odb,     /* option database */
00373              char *note);               /* option note */
00374 
00375 #endif /* OPTIONS_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