📄 misc.h
字号:
/* * misc.h - miscellaneous interfaces * * 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: misc.h,v 1.4 1997/03/11 01:18:24 taustin Exp taustin $ * * $Log: misc.h,v $ * Revision 1.4 1997/03/11 01:18:24 taustin * updated copyright * supported added for non-GNU C compilers * ANSI C compiler check added * long/int tweaks made for ALPHA target support * hacks added to make SYMCAT() portable * * Revision 1.3 1997/01/06 16:02:01 taustin * comments updated * system prototypes deleted (-Wall flag no longer a clean compile) * * Revision 1.1 1996/12/05 18:50:23 taustin * Initial revision * * */#ifndef MISC_H#define MISC_H#include <stdio.h>#include <string.h>#include <sys/types.h>#ifndef __STDC__ /* an ansi C compiler is required */#error The SimpleScalar simulators must be compiled with an ANSI C compiler.#endif /* __STDC__ */#if 0 /* as of rel 2, the tool set should compile with any ansi C compiler *//* FIXME: SimpleScalar currently only compiles with GNU GCC, since I use GNU GCC extensions extensively throughout the simulation suite, one day I'll fix this problem... */#ifndef __GNUC__#error The SimpleScalar simulation suite must be compiled with GNU GCC.#endif /* __GNUC__ */#endif/* enable inlining here */#undef INLINE#if defined(__GNUC__)#define INLINE inline#else#define INLINE#endif/* boolean value defs */#ifndef TRUE#define TRUE 1#endif#ifndef FALSE#define FALSE 0#endif/* various useful macros */#ifndef MAX#define MAX(a, b) (((a) < (b)) ? (b) : (a))#endif#ifndef MIN#define MIN(a, b) (((a) < (b)) ? (a) : (b))#endif/* for printing out "long long" vars */#define LLHIGH(L) ((int)(((L)>>32) & 0xffffffff))#define LLLOW(L) ((int)((L) & 0xffffffff))/* bind together two symbols, at preprocess time */#ifdef __GNUC__/* this works on all GNU GCC targets (that I've seen...) */#define SYMCAT(X,Y) X##Y#else /* !__GNUC__ */#ifdef OLD_SYMCAT#define SYMCAT(X,Y) X/**/Y#else /* !OLD_SYMCAT */#define SYMCAT(X,Y) X##Y#endif /* OLD_SYMCAT */#endif /* __GNUC__ *//* size of an array, in elements */#define N_ELT(ARR) (sizeof(ARR)/sizeof((ARR)[0]))/* rounding macros, assumes ALIGN is a power of two */#define ROUND_UP(N,ALIGN) (((N) + ((ALIGN)-1)) & ~((ALIGN)-1))#define ROUND_DOWN(N,ALIGN) ((N) & ~((ALIGN)-1))/* verbose output flag */extern int verbose;#ifdef DEBUG/* active debug flag */extern int debugging;#endif /* DEBUG *//* register a function to be called when an error is detected */voidfatal_hook(void (*hook_fn)(FILE *stream)); /* fatal hook function */#ifdef __GNUC__/* declare a fatal run-time error, calls fatal hook function */#define fatal(fmt, args...) \ _fatal(__FILE__, __FUNCTION__, __LINE__, fmt, ## args)void_fatal(char *file, char *func, int line, char *fmt, ...)__attribute__ ((noreturn));#else /* !__GNUC__ */voidfatal(char *fmt, ...);#endif /* !__GNUC__ */#ifdef __GNUC__/* declare a panic situation, dumps core */#define panic(fmt, args...) \ _panic(__FILE__, __FUNCTION__, __LINE__, fmt, ## args)void_panic(char *file, char *func, int line, char *fmt, ...)__attribute__ ((noreturn));#else /* !__GNUC__ */voidpanic(char *fmt, ...);#endif /* !__GNUC__ */#ifdef __GNUC__/* declare a warning */#define warn(fmt, args...) \ _warn(__FILE__, __FUNCTION__, __LINE__, fmt, ## args)void_warn(char *file, char *func, int line, char *fmt, ...);#else /* !__GNUC__ */voidwarn(char *fmt, ...);#endif /* !__GNUC__ */#ifdef __GNUC__/* print general information */#define info(fmt, args...) \ _info(__FILE__, __FUNCTION__, __LINE__, fmt, ## args)void_info(char *file, char *func, int line, char *fmt, ...);#else /* !__GNUC__ */voidinfo(char *fmt, ...);#endif /* !__GNUC__ */#ifdef DEBUG#ifdef __GNUC__/* print a debugging message */#define debug(fmt, args...) \ do { \ if (debugging) \ _debug(__FILE__, __FUNCTION__, __LINE__, fmt, ## args); \ } while(0)void_debug(char *file, char *func, int line, char *fmt, ...);#else /* !__GNUC__ */voiddebug(char *fmt, ...);#endif /* !__GNUC__ */#else /* !DEBUG */#ifdef __GNUC__#define debug(fmt, args...)#else /* !__GNUC__ *//* the optimizer should eliminate this call! */static void debug(char *fmt, ...) {}#endif /* !__GNUC__ */#endif /* !DEBUG *//* copy a string to a new storage allocation (NOTE: many machines are missing this trivial function, so I funcdup() it here...) */char * /* duplicated string */mystrdup(char *s); /* string to duplicate to heap storage *//* find the last occurrence of a character in a string */char *mystrrchr(char *s, char c);/* case insensitive string compare (NOTE: many machines are missing this trivial function, so I funcdup() it here...) */int /* compare result, see strcmp() */mystricmp(char *s1, char *s2); /* strings to compare, case insensitive *//* allocate some core, this memory has overhead no larger than a page in size and it cannot be released. the storage is returned cleared */void *getcore(int nbytes);/* return log of a number to the base 2 */int log_base2(int n);/* return string describing elapsed time, passed in SEC in seconds */char *elapsed_time(long sec);/* assume bit positions numbered 31 to 0 (31 high order bit), extract num bits from word starting at position pos (with pos as the high order bit of those to be extracted), result is right justified and zero filled to high order bit, for example, extractl(word, 6, 3) w/ 8 bit word = 01101011 returns 00000110 */unsigned intextractl(int word, /* the word from which to extract */ int pos, /* bit positions 31 to 0 */ int num); /* number of bits to extract */#if defined(sparc) && !defined(__svr4__)#define strtoul strtol#endif/* same semantics as fopen()/fclose() except that filenames ending with a ".gz" or ".Z" will be automagically get compressed */typedef struct { enum { ft_file, ft_prog } ft; FILE *fd;} ZFILE;ZFILE *zfopen(char *fname, char *type);intzfclose(ZFILE *zfd);#endif /* MISC_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -