📄 cmdargs.c
字号:
/* * Command line argument stuff for Dinero IV. * Written by Jan Edler * * Copyright (C) 1997 NEC Research Institute, Inc. and Mark D. Hill. * All rights reserved. * Copyright (C) 1985, 1989 Mark D. Hill. All rights reserved. * * Permission to use, copy, modify, and distribute this software and * its associated documentation for non-commercial purposes is hereby * granted (for commercial purposes see below), provided that the above * copyright notice appears in all copies, derivative works or modified * versions of the software and any portions thereof, and that both the * copyright notice and this permission notice appear in the documentation. * NEC Research Institute Inc. and Mark D. Hill shall be given a copy of * any such derivative work or modified version of the software and NEC * Research Institute Inc. and any of its affiliated companies (collectively * referred to as NECI) and Mark D. Hill shall be granted permission to use, * copy, modify, and distribute the software for internal use and research. * The name of NEC Research Institute Inc. and its affiliated companies * shall not be used in advertising or publicity related to the distribution * of the software, without the prior written consent of NECI. All copies, * derivative works, or modified versions of the software shall be exported * or reexported in accordance with applicable laws and regulations relating * to export control. This software is experimental. NECI and Mark D. Hill * make no representations regarding the suitability of this software for * any purpose and neither NECI nor Mark D. Hill will support the software. * * Use of this software for commercial purposes is also possible, but only * if, in addition to the above requirements for non-commercial use, written * permission for such use is obtained by the commercial user from NECI or * Mark D. Hill prior to the fabrication and distribution of the software. * * THE SOFTWARE IS PROVIDED AS IS. NECI AND MARK D. HILL DO NOT MAKE * ANY WARRANTEES EITHER EXPRESS OR IMPLIED WITH REGARD TO THE SOFTWARE. * NECI AND MARK D. HILL ALSO DISCLAIM ANY WARRANTY THAT THE SOFTWARE IS * FREE OF INFRINGEMENT OF ANY INTELLECTUAL PROPERTY RIGHTS OF OTHERS. * NO OTHER LICENSE EXPRESS OR IMPLIED IS HEREBY GRANTED. NECI AND MARK * D. HILL SHALL NOT BE LIABLE FOR ANY DAMAGES, INCLUDING GENERAL, SPECIAL, * INCIDENTAL, OR CONSEQUENTIAL DAMAGES, ARISING OUT OF THE USE OR INABILITY * TO USE THE SOFTWARE. * * $Header: /home/edler/dinero/d4/RCS/cmdargs.c,v 1.11 1997/12/12 20:36:39 edler Exp $ */#include <stddef.h>#include <stdlib.h>#include <limits.h>#include <stdio.h>#include "d4.h"#include "cmdd4.h"#include "cmdargs.h"#include "tracein.h"/* * The idea is to confine as much argument knowledge as possible to this file. * Generic argument handling functions are in cmdmain.c *//* * Define the variables and arrays to receive command line argument values. * Those coresponding to arguments with -ln-idu prefixes are actually * 2-d arrays; for the 1st index 0=unified, 1=instruction, and 2=data. * The 2nd index is the level - 1. * * The basic strategy is to process all the command line args, fill in these * variables and arrays, check them for consistency, and then * allocate and initialize all necessary cache structures for simulation. * * For those options subject to customization, the customized version * of the array is defined elsewhere. */#if D4CUSTOM#define D4_EXT extern#else#define D4_EXT#endifD4_EXT int maxlevel; /* the highest level actually used */D4_EXT unsigned int level_blocksize[3][MAX_LEV];D4_EXT unsigned int level_subblocksize[3][MAX_LEV];D4_EXT unsigned int level_size[3][MAX_LEV];D4_EXT unsigned int level_assoc[3][MAX_LEV];D4_EXT int level_doccc[3][MAX_LEV];D4_EXT int level_replacement[3][MAX_LEV];D4_EXT int level_fetch[3][MAX_LEV];D4_EXT int level_walloc[3][MAX_LEV];D4_EXT int level_wback[3][MAX_LEV];D4_EXT int level_prefetch_abortpercent[3][MAX_LEV];int level_prefetch_distance[3][MAX_LEV];/* * command line defaults. * Make sure the DEFVAL and DEFSTR versions match * We don't really have to use fancy macro stuff for this do we? */#define DEFVAL_assoc 1#define DEFSTR_assoc "1"#define DEFVAL_repl 'l'#define DEFSTR_repl "l"#define DEFVAL_fetch 'd'#define DEFSTR_fetch "d"#define DEFVAL_walloc 'a'#define DEFSTR_walloc "a"#define DEFVAL_wback 'a'#define DEFSTR_wback "a"#define DEFVAL_informat 'D'#define DEFSTR_informat "D"double skipcount;double flushcount;double maxcount;double stat_interval;int informat = DEFVAL_informat;long on_trigger;long off_trigger;int stat_idcombine;/* * Other declarations local to this file */extern void help_informat (const struct arglist *);extern void phelp_replacement (const struct arglist *);extern void phelp_fetch (const struct arglist *);extern void phelp_walloc (const struct arglist *);extern void phelp_wback (const struct arglist *);extern void unspec (int, int, char *, void *, char *);#if D4CUSTOM#define CUST_MATCH(x) match_bogus#define CUST_X(x) NULL#else#define CUST_MATCH(x) x#define CUST_X(x) x#endif/* Initialize argument table to specify acceptable arguments */struct arglist args[] = { { "-help", 0, NULL, NULL, NULL, "Print this help message", match_0arg, val_help, NULL, NULL, help_0arg }, { "-copyright", 0, NULL, NULL, NULL, "Give details on copyright and lack of warranty", match_0arg, val_helpcr, NULL, NULL, help_0arg }, { "-contact", 0, NULL, NULL, NULL, "Where to get the latest version or contact the authors", match_0arg, val_helpw, NULL, NULL, help_0arg },#if !D4CUSTOM { "-dineroIII", 0, NULL, NULL, NULL, "Explain replacements for Dinero III options", match_0arg, val_helpd3, NULL, NULL, help_0arg }, { "-custom", 2, &customname, NULL, NULL, "Generate and run custom simulator named F", match_1arg, val_string, custom_custom, NULL, help_string },#endif { "size", 7, &level_size[0][0], NULL, "level_size", "Size", CUST_MATCH(pmatch_1arg), pval_scale_pow2, CUST_X(pcustom_uint), psummary_luint, CUST_X(phelp_scale_pow2) }, { "bsize", 7, &level_blocksize[0][0], NULL, "level_blocksize", "Block size", CUST_MATCH(pmatch_1arg), pval_scale_pow2, CUST_X(pcustom_uint), psummary_luint, CUST_X(phelp_scale_pow2) }, { "sbsize", 7, &level_subblocksize[0][0], "same as block size", "level_subblocksize", "Sub-block size", CUST_MATCH(pmatch_1arg), pval_scale_pow2, CUST_X(pcustom_uint), psummary_luint, CUST_X(phelp_scale_pow2) }, { "assoc", 7, &level_assoc[0][0], DEFSTR_assoc, "level_assoc", "Associativity", CUST_MATCH(pmatch_1arg), pval_uint, CUST_X(pcustom_uint), psummary_uint, CUST_X(phelp_uint) }, { "repl", 7, &level_replacement[0][0], DEFSTR_repl, "level_replacement", "Replacement policy", CUST_MATCH(pmatch_1arg), pval_char, CUST_X(pcustom_char), psummary_char, CUST_X(phelp_replacement) }, { "fetch", 7, &level_fetch[0][0], DEFSTR_fetch, "level_fetch", "Fetch policy", CUST_MATCH(pmatch_1arg), pval_char, CUST_X(pcustom_char), psummary_char, CUST_X(phelp_fetch) }, { "pfdist", 7, &level_prefetch_distance[0][0], "1", NULL, "Prefetch distance (in sub-blocks)", pmatch_1arg, pval_uint, NULL, psummary_uint, CUST_X(phelp_uint) }, { "pfabort", 7, &level_prefetch_abortpercent[0][0], "0", "level_prefetch_abortpercent", "Prefetch abort percentage (0-100)", CUST_MATCH(pmatch_1arg), pval_uint, CUST_X(pcustom_uint), psummary_uint, CUST_X(phelp_uint) }, { "walloc", 7, &level_walloc[0][0], DEFSTR_walloc, "level_walloc", "Write allocate policy", CUST_MATCH(pmatch_1arg), pval_char, CUST_X(pcustom_char), psummary_char, CUST_X(phelp_walloc) }, { "wback", 7, &level_wback[0][0], DEFSTR_wback, "level_wback", "Write back policy", CUST_MATCH(pmatch_1arg), pval_char, CUST_X(pcustom_char), psummary_char, CUST_X(phelp_wback) }, { "ccc", 5, &level_doccc[0][0], NULL, "level_doccc", "Compulsory/Capacity/Conflict miss statistics", CUST_MATCH(pmatch_0arg), pval_0arg, CUST_X(pcustom_0arg), psummary_0arg, CUST_X(phelp_0arg) }, { "-skipcount", 2, &skipcount, NULL, NULL, "Skip initial U references", match_1arg, val_scale_uintd, NULL, summary_uintd, help_scale_uintd }, { "-flushcount", 2, &flushcount, NULL, NULL, "Flush cache every U references", match_1arg, val_scale_uintd, NULL, summary_uintd, help_scale_uintd }, { "-maxcount", 2, &maxcount, NULL, NULL, "Stop simulation after U references", match_1arg, val_scale_uintd, NULL, summary_uintd, help_scale_uintd }, { "-stat-interval", 2, &stat_interval, NULL, NULL, "Show statistics after every U references", match_1arg, val_scale_uintd, NULL, summary_uintd, help_scale_uintd }, { "-informat", 2, &informat, DEFSTR_informat, NULL, "Input trace format", match_1arg, val_char, NULL, summary_char, help_informat }, { "-on-trigger", 2, &on_trigger, NULL, NULL, "Trigger address to start simulation", match_1arg, val_addr, NULL, summary_addr, help_addr }, { "-off-trigger", 2, &off_trigger, NULL, NULL, "Trigger address to stop simulation", match_1arg, val_addr, NULL, summary_addr, help_addr }, { "-stat-idcombine", 2, &stat_idcombine, NULL, NULL, "Combine I&D cache stats", match_0arg, val_0arg, NULL, summary_0arg, help_0arg }, { NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }};int nargs = sizeof(args) / sizeof(args[0]);/* * Special help routine for -informat. * List the choices on subsequent lines. */voidhelp_informat (const struct arglist *adesc){ help_char (adesc); help_trace_format (optstringmax); /* look for this in tracein.c */}/* * Special help routine for -lN-Treplacement. * List the choices on subsequent lines. */voidphelp_replacement (const struct arglist *adesc){ phelp_char (adesc); printf ("\n %*s (l=LRU, f=FIFO, r=random)", optstringmax, " ");}/* * Special help routine for -lN-Tfetch. * List the choices on subsequent lines. */voidphelp_fetch (const struct arglist *adesc){ phelp_char (adesc); printf ("\n %*s (d=demand, a=always, m=miss, t=tagged,\n" " %*s l=load forward, s=subblock)", optstringmax, " ", optstringmax, " ");}/* * Special help routine for -lN-Twalloc. * List the choices on subsequent lines. */voidphelp_walloc (const struct arglist *adesc){ phelp_char (adesc); printf ("\n %*s (a=always, n=never, f=nofetch)", optstringmax, " ");}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -