📄 options.c
字号:
/* options.c - options package routines *//* SimpleScalar(TM) Tool Suite * Copyright (C) 1994-2003 by Todd M. Austin, Ph.D. and SimpleScalar, LLC. * All Rights Reserved. * * THIS IS A LEGAL DOCUMENT, BY USING SIMPLESCALAR, * YOU ARE AGREEING TO THESE TERMS AND CONDITIONS. * * No portion of this work may be used by any commercial entity, or for any * commercial purpose, without the prior, written permission of SimpleScalar, * LLC (info@simplescalar.com). Nonprofit and noncommercial use is permitted * as described below. * * 1. SimpleScalar is provided AS IS, with no warranty of any kind, express * or implied. The user of the program accepts full responsibility for the * application of the program and the use of any results. * * 2. Nonprofit and noncommercial use is encouraged. SimpleScalar may be * downloaded, compiled, executed, copied, and modified solely for nonprofit, * educational, noncommercial research, and noncommercial scholarship * purposes provided that this notice in its entirety accompanies all copies. * Copies of the modified software can be delivered to persons who use it * solely for nonprofit, educational, noncommercial research, and * noncommercial scholarship purposes provided that this notice in its * entirety accompanies all copies. * * 3. ALL COMMERCIAL USE, AND ALL USE BY FOR PROFIT ENTITIES, IS EXPRESSLY * PROHIBITED WITHOUT A LICENSE FROM SIMPLESCALAR, LLC (info@simplescalar.com). * * 4. No nonprofit user may place any restrictions on the use of this software, * including as modified by the user, by any other authorized user. * * 5. Noncommercial and nonprofit users may distribute copies of SimpleScalar * in compiled or executable form as set forth in Section 2, provided that * either: (A) it is accompanied by the corresponding machine-readable source * code, or (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. * * 6. SimpleScalar was developed by Todd M. Austin, Ph.D. The tool suite is * currently maintained by SimpleScalar LLC (info@simplescalar.com). US Mail: * 2395 Timbercrest Court, Ann Arbor, MI 48105. * * Copyright (C) 1994-2003 by Todd M. Austin, Ph.D. and SimpleScalar, LLC. */#include <stdio.h>#include <stdlib.h>#ifndef _MSC_VER#include <unistd.h>#else /* _MSC_VER */#define chdir _chdir#define getcwd _getcwd#endif#include <string.h>#include <ctype.h>#include <float.h>#include "host.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++) { if (!strcmp(str, emap[i])) { if (eval) { /* bind to eval value */ *res = eval[i]; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -