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