📄 host.h
字号:
/*
* C compiler file host.h
* Copyright (C) Codemist Ltd., 1988
* Copyright (C) Acorn Computers Ltd., 1988.
* Copyright (C) ARM Ltd., 1996-1999.
*/
/*
* RCS $Revision: 1.95.4.6.18.2 $ Codemist 11
* Checkin $Date: 2003/07/09 10:22:26 $
* Revising $Author: dsinclai $
*/
/* AM memo, July 1990: in principle there should be no tests of */
/* COMPILING_ON_<machine>, but only COMPILING_ON_<operating system> or */
/* COMPILING_ON_<manufacturer> (for special features). */
/* Accordingly COMPILING_ON_<machine> is deprecated. */
/*
* This file deals with peculiarities of the host system under which the
* compiler is compiled AND peculiarities of the host system under which
* the compiler will run (hence it might need further explication in the
* unlikely event that we wish to cross-compile the compiler (repeatedly
* as opposed to once-off bootstrap)). It is now loaded first and can
* therefore not depend on TARGET_xxx parameterisations, these are now
* done in target.h or, if systematic, in mip/defaults.h.
* The correct mechanism for host->target dependencies (e.g. if compiling
* on unix then make a unix compiler, else a homebrew object file version)
* is via the options.h file, along the lines of:
* #ifdef COMPILING_ON_UNIX
* # define TARGET_IS_UNIX
* #endif
* The intent is that most of the pecularities should be linked to
* COMPILING_ON_machine and/or COMPILING_ON_system. Further NO OTHER FILE
* should refer to magic names like 'unix', '__arm' etc., but go via
* the COMPILING_xxx flags defined here in terms of these.
* The aim is that this file should suffice for all host dependencies
* and thus all COMPILING_ON_xxx tests outwith are suspect. However,
* the #include file munger clearly needs to so depend.
*/
/* The bool problem:
* In both C and C++ we want to be able to use to use a type 'bool' and
* constants 'true' and 'false' (and the obsolete versions 'TRUE', 'FALSE',
* 'YES' and 'NO'). Also, when in C++ we'd like 'bool' to mean 'bool' and
* 'true' and 'false' to be constants of type bool.
* The problem is that we need to find a typedef for C that is compatible,
* with, i.e. that has same size and alignment as, C++'s 'bool'. This is
* compilcated somewhat by some of the C++ compilers we use not supporting
* 'bool' (Sparcworks 4.1 & 4.2?).
* We also have cases (what cases?) of published C interfaces where
* sizeof(bool) == sizeof(int) so we can't really make use of
* IMPLEMENT_BOOL_AS_{ENUM,CHAR}_IN_C. Instead we have to as
* IMPLEMENT_BOOL_AS_INT in C++ (which breaks overloading, etc.).
*/
#ifndef host_h_LOADED
#define host_h_LOADED 1
/* The easiest way to ensure that host.h and angel.h cannot clash is
* to ensure that if angel.h has been included that host.h itself
* checks this flag and pretends it has already been included.
* But we're careful to make sure that the '#ifndef host_h_LOADED' still
* works as, and looks like guard.
*/
#ifndef DO_NOT_INCLUDE_HOST_H
#include <stdio.h>
#include <stddef.h> /* for xsyn.c (and more?) and offsetof test below */
#include <stdlib.h> /* for EXIT_FAILURE test below */
#include <time.h>
#if defined(__cplusplus) && !defined(CLX_CPP_LINKAGE)
extern "C" {
#endif
#ifndef SEEK_SET
#define SEEK_SET 0
#endif
#ifndef SEEK_CUR
#define SEEK_CUR 1
#endif
#ifndef SEEK_END
#define SEEK_END 2
#endif
#if defined(__STDC__) || defined(__cplusplus)
#define BELL '\a'
typedef void /* newline to fool the topcc tool */
*VoidStar;
typedef const void
*ConstVoidStar;
#else /* ! __STDC__ */
#define BELL '\007'
typedef char *VoidStar;
#define ConstVoidStar VoidStar
/* @@@ # define const *//*nothing */
#endif /* ! __STDC__ */
/* The following for the benefit of compiling on SunOS */
#ifndef offsetof
#define offsetof(T, member) ((char *)&(((T *)0)->member) - (char *)0)
#endif
/* Set CLOCKS_PER_SEC for non-ANSI compilers */
#ifndef CLOCKS_PER_SEC
#ifndef CLK_TCK
/* sunos */
#define CLK_TCK 1000000
#endif
#define CLOCKS_PER_SEC CLK_TCK
#endif
#ifdef unix /* A temporary sop to older compilers */
#ifndef __unix /* (good for long-term portability?) */
#define __unix 1
#endif
#endif
#ifdef __unix
/* Generic unix -- hopefully a split into other variants will not be */
/* needed. However, beware the 'bsd' test above and safe_toupper etc. */
/* which cope with backwards (pre-posix/X/open) unix compatibility. */
#define COMPILING_ON_UNIX 1
#endif
#ifdef __helios
/* start improving parameterisation. Maybe we should also set */
/* COMPILING_ON_UNIX and use HELIOS as a special subcase? */
#define COMPILING_ON_HELIOS 1
#endif
#ifdef __acorn
#define COMPILING_ON_ACORN_KIT 1
#endif
#ifdef __riscos
#define COMPILING_ON_RISC_OS 1
#endif
#ifdef __arm
#define COMPILING_ON_ARM 1
#endif
#ifdef __ibm370
#ifndef COMPILING_ON_UNIX
#define __mvs 1
#endif
#endif
#ifdef __mvs
#define COMPILING_ON_MVS 1
#endif
#if defined(_WIN32)
#define COMPILING_ON_WIN32 1
#define COMPILING_ON_WINDOWS 1
#endif
#if defined(_CONSOLE)
#define COMPILING_ON_WINDOWS_CONSOLE 1
#define COMPILING_ON_WINDOWS 1
#endif
#ifdef _MSDOS
#define COMPILING_ON_MSDOS 1
#endif
#ifdef __WATCOMC__
#define COMPILING_ON_MSDOS 1
#endif
#ifdef _MSC_VER
#define COMPILING_ON_MSDOS 1
#define COMPILING_ON_WINDOWS 1
/* with VC++ 6 sizeof([real C++] bool) == 1; sizeof(enum clx_bool) == 4 */
#define IMPLEMENT_BOOL_AS_UCHAR_IN_C 1
#elif defined(macintosh)
#define COMPILING_ON_MACINTOSH 1 /* for dependencies on how Macintosh handles filenames, etc. */
#define COMPILING_ON_MPW 1 /* for dependencies on how MPW handles arguments, i/o, etc. */
#elif defined(__SUNOS__)
#define COMPILING_ON_SUNOS 1
#elif defined(__svr4__) || defined(__SVR4)
#define COMPILING_ON_SVR4 1
#define COMPILING_ON_SOLARIS 1
#if defined(__cplusplus) && defined(__SUNPRO_CC)
#if __SUNPRO_CC <= 0x420 /* SparcWorks C++ 4.2 doesn't have 'bool' */
#define NO_CPP_BOOL 1
#ifdef IMPLEMENT_BOOL_AS_BOOL /* well, we can't, so... */
#undef IMPLEMENT_BOOL_AS_BOOL
#define IMPLEMENT_BOOL_AS_ENUM 1 /* at least this is a unique type */
#define _WINDU_NATIVEBOOL /* make sure windu doesn't define its own */
#else
#define IMPLEMENT_BOOL_AS_INT 1
#endif
#endif
#elif defined(__GNUC__)
#if __GNUC__ == 2
/* with g++ 2.95.2 sizeof(bool) == 4; sizeof(enum clx_bool) == 4 (unless -fshort-enums) */
/* @@@ maybe should use IMPLEMENT_BOOL_AS_ENUM_IN_C */
#define IMPLEMENT_BOOL_AS_INT_IN_C 1
#elif __GNUC__ == 3
/* with g++ 3.x sizeof(bool) == 1 */
/* thus use IMPLEMENT_BOOL_AS_UCHAR_IN_C */
#define IMPLEMENT_BOOL_AS_UCHAR_IN_C 1
#else
/* No idea what is going on so generate an error */
#error I do not know what sizeof(bool) is for this g++ __GNUC__
#endif
#endif
#elif defined(__hppa)
#define COMPILING_ON_HPUX 1
#ifdef __GNUC__
#if __GNUC__ == 2
/* with g++ 2.95.2 sizeof(bool) == 4; sizeof(enum clx_bool) == 4 (unless -fshort-enums) */
/* @@@ maybe should use IMPLEMENT_BOOL_AS_ENUM_IN_C */
#define IMPLEMENT_BOOL_AS_INT_IN_C 1 /* defaulted to this below in C anyway */
#elif __GNUC__ == 3
/* with g++ 3.x sizeof(bool) == 1 */
/* thus use IMPLEMENT_BOOL_AS_UCHAR_IN_C */
#define IMPLEMENT_BOOL_AS_UCHAR_IN_C 1
#else
/* No idea what is going on so generate an error */
#error I do not know what sizeof(bool) is for this g++ __GNUC__
#endif
#else
/* with aCC A.01.23 sizeof(bool) == 1; sizeof(enum clx_bool) == 4 */
#define IMPLEMENT_BOOL_AS_UCHAR_IN_C 1*/ /* avoid darn bool problem */
#endif
#elif defined(__ARMCC_VERSION) && 200000 <= __ARMCC_VERSION
#define IMPLEMENT_BOOL_AS_ENUM_IN_C 1 /* ADS post 1.2 sizeof(bool) == 1 */
#endif
#ifdef __linux__
#define COMPILING_ON_LINUX 1
#if (defined(__GNUC__) || defined(__EDG__)) && defined(__i386__)
/* with g++ 2.95.1 sizeof(bool) == 1; sizeof(enum clx_bool) == 4 (unless -fshort-enums) */
#define IMPLEMENT_BOOL_AS_UCHAR_IN_C 1 /* avoid darn bool problem */
#endif
#endif
/* By default, the following code defines the 'bool' type to be 'int'
* in C and real 'bool' under C++. It also avoids warnings such as
* (in C) "C++ keyword 'bool' used as identifier". It can be overridden
* by defining IMPLEMENT_BOOL_AS_ENUM, IMPLEMENT_BOOL_AS_UCHAR or
* IMPLEMENT_BOOL_AS_INT.
*/
#undef clx_bool
#undef clx_bool_defined
typedef int bool_int; /* an int used as a bool -- the same in C and C++. may be
* useful for backward compatibility
*/
#if defined(__cplusplus)
#if !defined(NO_CPP_BOOL)
typedef bool cpp_bool; /* Have a real bool type in case being overridden */
#else
typedef int cpp_bool; /* there is no real C++ bool for this compiler */
#endif
#endif
#if !defined(IMPLEMENT_BOOL_AS_ENUM_IN_C) && \
!defined(IMPLEMENT_BOOL_AS_UCHAR_IN_C) && \
!defined(IMPLEMENT_BOOL_AS_INT_IN_C)
#define IMPLEMENT_BOOL_AS_INT_IN_C 1
#endif
#ifndef __cplusplus
#if defined(IMPLEMENT_BOOL_AS_ENUM_IN_C)
#define IMPLEMENT_BOOL_AS_ENUM 1
#elif defined(IMPLEMENT_BOOL_AS_UCHAR_IN_C)
#define IMPLEMENT_BOOL_AS_UCHAR 1
#elif defined(IMPLEMENT_BOOL_AS_INT_IN_C)
#define IMPLEMENT_BOOL_AS_INT 1
#else
#error do not know how to implement bool in C
#endif
#endif
#if defined(IMPLEMENT_BOOL_AS_ENUM)
#if defined(true) || defined(false)
#error implement bool as enum but true or false already defined
#endif
enum clx_bool { clx_false, clx_true };
#define clx_bool enum clx_bool
#define clx_bool_defined 1
#elif defined(IMPLEMENT_BOOL_AS_UCHAR)
/* we use 'unsigned char' instead of plain 'char' to avoid
* inadvertent "'char' used as subscript" warnings from gcc
*/
typedef unsigned char clx_bool;
#define clx_false 0 /* '((bool)0)' would give correct type in C++ but makes '#if false' fail */
#define clx_true 1 /* '((bool)1)' would give correct type in C++ but makes '#if true' fail */
/* But note that in C++ '#if true' doesn't do what you think it does anyway */
#define clx_bool_defined 1
#elif defined(IMPLEMENT_BOOL_AS_INT) || !defined(__cplusplus)
typedef int clx_bool;
#define clx_false 0
#define clx_true 1
#define clx_bool_defined 1
#endif
#ifdef clx_bool_defined
#if (defined(__cplusplus) && !defined(NO_CPP_BOOL)) || defined(__CC_ARM)
/* avoids "'bool' is reserved word in C++" warning in C and problems in C++
* when the compiler has a native 'bool' but we don't use it (because it's
* not the right size).
*/
#define bool clx_bool
#else
/* a real typedef may be better for debugging */
typedef clx_bool bool;
#endif
/* if true and false are already defined assume they will work */
#if !defined(true) && !defined(false)
#define true clx_true
#define false clx_false
#elif !(defined(true) && defined(false))
#error only one of true and false defined
#endif
#endif
#ifdef __cplusplus
/* here we check (as best we can from C++) that bool we're using in C++ is the
* same size as the bool we use in C
*/
#if defined(IMPLEMENT_BOOL_AS_ENUM_IN_C)
enum clx_bool_for_assertion { clx_false, clx_true };
typedef int bool_size_assertion[1/(int)(sizeof(bool) == sizeof(clx_bool_for_assertion))];
#elif defined(IMPLEMENT_BOOL_AS_UCHAR_IN_C)
typedef int bool_size_assertion[1/(int)(sizeof(bool) == sizeof(unsigned char))];
#elif defined(IMPLEMENT_BOOL_AS_INT_IN_C)
typedef int bool_size_assertion[1/(int)(sizeof(bool) == sizeof(int))];
#else
#error do not know how bool is implemented in C
#endif
#endif
/* The following converts a scalar type to a bool without using a cast (which could hide a bug)
and without provoking a warning in VC++ 6 (C mode with warnings are errors is the problem).
*/
#ifdef __cplusplus
#define BOOLIFY(b) ((b) != 0)
#elif defined(_MSC_VER)
#if _MSC_VER <= 1200
/* VC++ 6 (or lower) */
extern __inline bool clx_convert_int_to_bool(int i) { if (i != 0) return clx_true; else return clx_false; }
#define BOOLIFY(b) (clx_convert_int_to_bool((b) != 0))
#else
/* VS 7 (.Net) */
#define BOOLIFY(b) ((b) ? clx_true : clx_false) /* ((b) != 0) still produces a /W4 warning: conversion from 'int' to 'bool', possible loss of data */
#endif
#else
#define BOOLIFY(b) ((b) != 0)
#endif
/*
* The following typedefs may need alteration for obscure host machines.
*/
#if defined(__alpha) && defined(__osf__) /* =========================== */
/* Under OSF the alpha has 64-bit pointers and 64-bit longs. */
typedef int int32;
typedef unsigned int unsigned32;
/* IPtr and UPtr are 'ints of same size as pointer'. Do not use in */
/* new code. Currently only used within 'ncc'. */
typedef long int IPtr;
typedef unsigned long int UPtr;
#else /* all hosts except alpha under OSF ============================= */
typedef long int int32;
typedef unsigned long int unsigned32;
/* IPtr and UPtr are 'ints of same size as pointer'. Do not use in */
/* new code. Currently only used within 'ncc'. */
#define IPtr int32
#define UPtr unsigned32
#endif /* ============================================================= */
typedef short int int16;
typedef unsigned short int unsigned16;
typedef signed char int8;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -