📄 options.c
字号:
/* * options.c - options package routines * * This file is a part of the SimpleScalar tool suite written by * Todd M. Austin as a part of the Multiscalar Research Project. * * The tool suite is currently maintained by Doug Burger and Todd M. Austin. * * Copyright (C) 1994, 1995, 1996, 1997 by Todd M. Austin * * This source file is distributed "as is" in the hope that it will be * useful. The tool set comes with no warranty, and no author or * distributor accepts any responsibility for the consequences of its * use. * * Everyone is granted permission to copy, modify and redistribute * this tool set under the following conditions: * * This source code is distributed for non-commercial use only. * Please contact the maintainer for restrictions applying to * commercial use. * * Permission is granted to anyone to make or distribute copies * of this source code, either as received or modified, in any * medium, provided that all copyright notices, permission and * nonwarranty notices are preserved, and that the distributor * grants the recipient permission for further redistribution as * permitted by this document. * * Permission is granted to distribute this file in compiled * or executable form under the same conditions that apply for * source code, provided that either: * * A. it is accompanied by the corresponding machine-readable * source code, * B. it is accompanied by a written offer, with no time limit, * to give anyone a machine-readable copy of the corresponding * source code in return for reimbursement of the cost of * distribution. This written offer must permit verbatim * duplication by anyone, or * C. it is distributed by someone who received only the * executable form, and is accompanied by a copy of the * written offer of source code that they received concurrently. * * In other words, you are welcome to use, share and improve this * source file. You are forbidden to forbid anyone else to use, share * and improve what you give them. * * INTERNET: dburger@cs.wisc.edu * US Mail: 1210 W. Dayton Street, Madison, WI 53706 * * $Id: options.c,v 1.1 1997/03/11 01:31:45 taustin Exp taustin $ * * $Log: options.c,v $ * Revision 1.1 1997/03/11 01:31:45 taustin * Initial revision * * */#include <stdio.h>#include <stdlib.h>#include <string.h>#include <float.h>#include "misc.h"#include "options.h"/* create a new option database */struct opt_odb_t *opt_new(orphan_fn_t orphan_fn) /* user-specified orphan parser */{ struct opt_odb_t *odb; odb = (struct opt_odb_t *)calloc(1, sizeof(struct opt_odb_t)); if (!odb) fatal("out of virtual memory"); odb->options = NULL; odb->orphan_fn = orphan_fn; odb->header = NULL; odb->notes = NULL; return odb;}/* free an option database */voidopt_delete(struct opt_odb_t *odb) /* option database */{ struct opt_opt_t *opt, *opt_next; struct opt_note_t *note, *note_next; /* free all options */ for (opt=odb->options; opt; opt=opt_next) { opt_next = opt->next; opt->next = NULL; free(opt); } /* free all notes */ for (note = odb->notes; note != NULL; note = note_next) { note_next = note->next; note->next = NULL; free(note); } odb->notes = NULL; free(odb);}/* add option OPT to option database ODB */static voidadd_option(struct opt_odb_t *odb, /* option database */ struct opt_opt_t *opt) /* option variable */{ struct opt_opt_t *elt, *prev; /* sanity checks on option name */ if (opt->name[0] != '-') panic("option `%s' must start with a `-'", opt->name); /* add to end of option list */ for (prev=NULL, elt=odb->options; elt != NULL; prev=elt, elt=elt->next) { /* sanity checks on option name */ if (elt->name[0] == opt->name[0] && !strcmp(elt->name, opt->name)) panic("option `%s' is multiply defined", opt->name); } if (prev != NULL) prev->next = opt; else /* prev == NULL */ odb->options = opt; opt->next = NULL;}/* register an integer option variable */voidopt_reg_int(struct opt_odb_t *odb, /* option data base */ char *name, /* option name */ char *desc, /* option description */ int *var, /* target variable */ int def_val, /* default variable value */ int print, /* print during `-dumpconfig'? */ char *format) /* optional value print format */{ struct opt_opt_t *opt; opt = (struct opt_opt_t *)calloc(1, sizeof(struct opt_opt_t)); if (!opt) fatal("out of virtual memory"); opt->name = name; opt->desc = desc; opt->nvars = 1; opt->nelt = NULL; opt->format = format ? format : "%12d"; opt->oc = oc_int; opt->variant.for_int.var = var; opt->print = print; opt->accrue = FALSE; /* place on ODB's option list */ opt->next = NULL; add_option(odb, opt); /* set default value */ *var = def_val;}/* register an integer option list */voidopt_reg_int_list(struct opt_odb_t *odb,/* option database */ char *name, /* option name */ char *desc, /* option description */ int *vars, /* pointer to option array */ int nvars, /* total entries in option array */ int *nelt, /* number of entries parsed */ int *def_val, /* default value of option array */ int print, /* print during `-dumpconfig'? */ char *format, /* optional user print format */ int accrue) /* accrue list across uses */{ int i; struct opt_opt_t *opt; opt = (struct opt_opt_t *)calloc(1, sizeof(struct opt_opt_t)); if (!opt) fatal("out of virtual memory"); opt->name = name; opt->desc = desc; opt->nvars = nvars; opt->nelt = nelt; opt->format = format ? format : "%d"; opt->oc = oc_int; opt->variant.for_int.var = vars; opt->print = print; opt->accrue = accrue; /* place on ODB's option list */ opt->next = NULL; add_option(odb, opt); /* set default value */ for (i=0; i < *nelt; i++) vars[i] = def_val[i];}/* register an unsigned integer option variable */voidopt_reg_uint(struct opt_odb_t *odb, /* option database */ char *name, /* option name */ char *desc, /* option description */ unsigned int *var, /* pointer to option variable */ unsigned int def_val, /* default value of option variable */ int print, /* print during `-dumpconfig'? */ char *format) /* optional user print format */{ struct opt_opt_t *opt; opt = (struct opt_opt_t *)calloc(1, sizeof(struct opt_opt_t)); if (!opt) fatal("out of virtual memory"); opt->name = name; opt->desc = desc; opt->nvars = 1; opt->nelt = NULL; opt->format = format ? format : "%12u"; opt->oc = oc_uint; opt->variant.for_uint.var = var; opt->print = print; opt->accrue = FALSE; /* place on ODB's option list */ opt->next = NULL; add_option(odb, opt); /* set default value */ *var = def_val;}/* register an unsigned integer option list */voidopt_reg_uint_list(struct opt_odb_t *odb,/* option database */ char *name, /* option name */ char *desc, /* option description */ unsigned int *vars, /* pointer to option array */ int nvars, /* total entries in option array */ int *nelt, /* number of elements parsed */ unsigned int *def_val,/* default value of option array */ int print, /* print opt during `-dumpconfig'? */ char *format, /* optional user print format */ int accrue) /* accrue list across uses */{ int i; struct opt_opt_t *opt; opt = (struct opt_opt_t *)calloc(1, sizeof(struct opt_opt_t)); if (!opt) fatal("out of virtual memory"); opt->name = name; opt->desc = desc; opt->nvars = nvars; opt->nelt = nelt; opt->format = format ? format : "%u"; opt->oc = oc_uint; opt->variant.for_uint.var = vars; opt->print = print; opt->accrue = accrue; /* place on ODB's option list */ opt->next = NULL; add_option(odb, opt); /* set default value */ for (i=0; i < *nelt; i++) vars[i] = def_val[i];}/* register a single-precision floating point option variable */voidopt_reg_float(struct opt_odb_t *odb, /* option data base */ char *name, /* option name */ char *desc, /* option description */ float *var, /* target option variable */ float def_val, /* default variable value */ int print, /* print during `-dumpconfig'? */ char *format) /* optional value print format */{ struct opt_opt_t *opt; opt = (struct opt_opt_t *)calloc(1, sizeof(struct opt_opt_t)); if (!opt) fatal("out of virtual memory"); opt->name = name; opt->desc = desc; opt->nvars = 1; opt->nelt = NULL; opt->format = format ? format : "%12.4f"; opt->oc = oc_float; opt->variant.for_float.var = var; opt->print = print; opt->accrue = FALSE; /* place on ODB's option list */ opt->next = NULL; add_option(odb, opt); /* set default value */ *var = def_val;}/* register a single-precision floating point option array */voidopt_reg_float_list(struct opt_odb_t *odb,/* option data base */ char *name, /* option name */ char *desc, /* option description */ float *vars, /* target array */ int nvars, /* target array size */ int *nelt, /* number of args parsed goes here */ float *def_val, /* default variable value */ int print, /* print during `-dumpconfig'? */ char *format, /* optional value print format */ int accrue) /* accrue list across uses */{ int i; struct opt_opt_t *opt; opt = (struct opt_opt_t *)calloc(1, sizeof(struct opt_opt_t)); if (!opt) fatal("out of virtual memory"); opt->name = name; opt->desc = desc; opt->nvars = nvars; opt->nelt = nelt; opt->format = format ? format : "%.4f"; opt->oc = oc_float; opt->variant.for_float.var = vars; opt->print = print; opt->accrue = accrue; /* place on ODB's option list */ opt->next = NULL; add_option(odb, opt); /* set default value */ for (i=0; i < *nelt; i++) vars[i] = def_val[i];}/* register a double-precision floating point option variable */voidopt_reg_double(struct opt_odb_t *odb, /* option data base */ char *name, /* option name */ char *desc, /* option description */ double *var, /* target variable */ double def_val, /* default variable value */ int print, /* print during `-dumpconfig'? */ char *format) /* option value print format */{ struct opt_opt_t *opt; opt = (struct opt_opt_t *)calloc(1, sizeof(struct opt_opt_t)); if (!opt) fatal("out of virtual memory"); opt->name = name; opt->desc = desc; opt->nvars = 1; opt->nelt = NULL; opt->format = format ? format : "%12.4f"; opt->oc = oc_double; opt->variant.for_double.var = var; opt->print = print; opt->accrue = FALSE; /* place on ODB's option list */ opt->next = NULL; add_option(odb, opt); /* set default value */ *var = def_val;}/* register a double-precision floating point option array */voidopt_reg_double_list(struct opt_odb_t *odb, /* option data base */ char *name, /* option name */ char *desc, /* option description */ double *vars, /* target array */ int nvars, /* target array size */ int *nelt, /* number of args parsed goes here */ double *def_val, /* default variable value */ int print, /* print during `-dumpconfig'? */ char *format, /* option value print format */ int accrue) /* accrue list across uses */{ int i; struct opt_opt_t *opt; opt = (struct opt_opt_t *)calloc(1, sizeof(struct opt_opt_t)); if (!opt) fatal("out of virtual memory"); opt->name = name; opt->desc = desc; opt->nvars = nvars; opt->nelt = nelt; opt->format = format ? format : "%.4f"; opt->oc = oc_double; opt->variant.for_double.var = vars; opt->print = print; opt->accrue = accrue; /* place on ODB's option list */ opt->next = NULL; add_option(odb, opt); /* set default value */ for (i=0; i < *nelt; i++) vars[i] = def_val[i];}/* bind an enumeration string to an enumeration value */static intbind_to_enum(char *str, /* string to bind to an enum */ char **emap, /* enumeration string map */ int *eval, /* enumeration value map, optional */ int emap_sz, /* size of maps */ int *res) /* enumeration string value result */{ int i; /* string enumeration string map */ for (i=0; i<emap_sz; i++) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -