⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chdr.h

📁 一款拥有一定历史的C语言编译器
💻 H
📖 第 1 页 / 共 2 页
字号:
/*
 * C compiler
 * ==========
 *
 * Copyright 1989, 1990, 1991 Christoph van Wuellen.
 * Credits to Matthew Brandt.
 * All commercial rights reserved.
 *
 * This compiler may be redistributed as long there is no
 * commercial interest. The compiler must not be redistributed
 * without its full sources. This notice must stay intact.
 *
 * History:
 *
 * 1989   starting an 68000 C compiler, starting with material
 *        originally by M. Brandt
 * 1990   68000 C compiler further bug fixes
 *        started i386 port (December)
 * 1991   i386 port finished (January)
 *        further corrections in the front end and in the 68000
 *        code generator.
 *        The next port will be a SPARC port
 */


#ifndef _CHDR_H
#define	_CHDR_H

#ifndef _CONFIG_H
#include "config.h"
#endif /* _CONFIG_H */

#include <stddef.h>
#include <string.h>
#include <stdlib.h>
/*lint -emacro( {1776}, assert )*/
#include <assert.h>

#ifdef VERBOSE
#include <time.h>
#define	STARTTIME(t)	clock_t t; (t = clock())
#define	DOTIME(t1, t2)	t1 += clock()-t2; t2 = clock()
#else
#define	STARTTIME(t)
#define	DOTIME(t1, t2)
#endif /* VERBOSE */


/*
 *   Definitions used for I/O portability
 */
#ifdef EPOC
#include <plib.h>
#define	FHANDLE		void *
#undef	EXIT_FAILURE
#define	EXIT_FAILURE	1
#else /* not EPOC */
#include <stdio.h>
#define	FHANDLE		FILE *
#endif /* EPOC */

#ifdef HAS_STDARG
#include <stdarg.h>
#else
#include <varargs.h>
#endif /* HAS_STDARG */

/*
 *   For NON-ANSI systems.....
 */
#ifndef EXIT_SUCCESS
#define	EXIT_SUCCESS	0
#endif /* EXIT_SUCCESS */

#ifndef EXIT_FAILURE
#define	EXIT_FAILURE	1
#endif /* EXIT_FAILURE */

#ifndef FILENAME_MAX
#define	FILENAME_MAX	127
#endif /* FILENAME_MAX */

#ifndef __STDC__
#define	const			/* nothing */
#endif /* __STDC__ */

/*
 *   Definition to allow ANSI and K&R function declaration to exist
 *   on the same declaration.
 */
#if defined(__STDC__) || defined(__cplusplus)
#define P_(s) s
#else
#define P_(s) ()
#endif

#define	UNUSEDARG(x)	(x = x)

/*
 * documents paths which it should be impossible to reach
 */

/*lint -emacro((1776), CANNOT_REACH_HERE) */
#define	CANNOT_REACH_HERE()	assert(0)

/*
 * the tokens returned from lexical analysis
 */

enum e_sym
{
    /* Constants */
    tk_fconst,		/* Float Constant */
    tk_iconst,		/* Integer Constant */
    tk_lconst,		/* Long Integer Constant */
    tk_llconst,		/* Long Long Integer Constant */
    tk_lrconst,		/* Long Double Constant */
    tk_rconst,		/* Double Constant */
    tk_wconst,		/* Wide Character Constant */
    tk_sconst,		/* String Constant */
    tk_wsconst,		/* Wide String Constant */
    tk_uconst,		/* Unsigned Integer Constant */
    tk_ulconst,		/* Unsigned Long Constant */
    tk_ullconst,	/* Unsigned Long Long Constant */

    /* Arithmetic Operators */
    tk_plus,		/* + symbol */
    tk_minus,		/* - symbol */
    tk_divide,		/* / symbol */
    tk_mod,			/* % symbol */

    /* Shift Operators */
    tk_lshift,		/* << symbol */
    tk_rshift,		/* >> symbol */

    /* Equality Operators */
    tk_eq,			/* == symbol */
    tk_neq,			/* != symbol */
    tk_lt,			/* < symbol */
    tk_leq,			/* <= symbol */
    tk_gt,			/* > symbol */
    tk_geq,			/* >= symbol */

    /* Assignment Operators */
    tk_assign,		/* = symbol */
    tk_asplus,		/* += symbol */
    tk_asminus,		/* -= symbol */
    tk_astimes,		/* *= symbol */
    tk_asdivide,	/* /= symbol */
    tk_asmod,		/* %= symbol */
    tk_asuparrow,	/* ^= symbol */
    tk_aslshift,	/* <<= symbol */
    tk_asrshift,	/* >>= symbol */
    tk_asand,		/* &= symbol */
    tk_asor,		/* |= symbol */

    /* Unary Operators */
    tk_autoinc,		/* ++ symbol */
    tk_autodec,		/* -- symbol */
    tk_not,			/* ! symbol */
    tk_compl,		/* ~ symbol */

    tk_hook,		/* ? symbol */
    tk_uparrow,		/* ^ symbol */
    tk_pointsto,	/* -> symbol */
    tk_dot,			/* . symbol */
    tk_lor,			/* || symbol */
    tk_land,		/* && symbol */
    tk_or,			/* | symbol */
    tk_and,			/* & symbol */

    tk_semicolon,	/* ; symbol */
    tk_closebr,		/* ] symbol */
    tk_end,			/* } symbol */
    tk_closepa,		/* ) symbol */

    tk_openbr,		/* [ symbol */
    tk_begin,		/* { symbol */
    tk_comma,		/* , symbol */
    tk_openpa,		/* ( */
    tk_star,		/* * symbol */
    tk_colon,		/* : symbol */
    tk_ellipsis,	/* ... */

    tk_id,			/* identifier */

    kw_char,		/* char */
    kw_double,		/* double */
    kw_enum,		/* enum */
    kw_float,		/* float */
    kw_int,			/* int */
    kw_long,		/* long */
    kw_short,		/* short */
    kw_signed,		/* signed */
    kw_struct,		/* struct */
    kw_union,		/* union */
    kw_unsigned,	/* unsigned */
    kw_void,		/* void */

    kw_auto,		/* auto */
    kw_extern,		/* extern */
    kw_register,	/* register */
    kw_static,		/* static */
    kw_typedef,		/* typedef */

    kw_const,		/* const */
    kw_volatile,	/* volatile */

#ifdef ASM
    kw_asm,			/* asm */
#endif				/* ASM */
    kw_break,		/* break */
    kw_case,		/* case */
    kw_continue,	/* continue */
    kw_default,		/* default */
    kw_do,			/* do */
    kw_else,		/* else */
    kw_for,			/* for */
    kw_goto,		/* goto */
    kw_if,			/* if */
    kw_return,		/* return */
    kw_sizeof,		/* sizeof */
    kw_switch,		/* switch */
    kw_while,		/* while */

#ifdef TOPSPEED
    kw_cdecl,		/* cdecl */
#endif				/* TOPSPEED */

    /* ISO C99 additions */
    kw_bool,		/* _Bool */
    kw_complex,		/* _Complex */
    kw_imaginary,	/* _Imaginary */
    kw_inline,		/* inline */
    kw_restrict,	/* restrict */

#ifdef FACIST
    kw_id,			/* c++ symbol */
#endif				/* FACIST */

#ifdef TYPEOF
    kw_typeof,		/* __typeof__ */
#endif

    kw_pragma,		/* _Pragma */
    tk_eof			/* End-Of-File */
};

/*
 * storage classes
 */

enum e_sc
{
    /* Storage classes defined in the ANSI C Specification */
    sc_static,			/* Symbol is static */
    sc_auto,			/* Symbol is automatic */
    sc_global,			/* Symbol is global */
    sc_external,		/* Symbol is external */
    sc_typedef,			/* Symbol is a typedef */
    sc_register,		/* Symbol is a register */

    /* Pseudo storage classes - these classes exist in the symbol table */
    sc_parms,			/* Symbol is a parameter to a function */
    sc_tag,				/* Symbol is a struct/union/enum tag */
    sc_const,			/* Symbol is an enumeration constant */
    sc_member,			/* Symbol is a member of a struct/union */
    sc_label			/* Symbol is a label */
};

/*
 * function specifier
 */

enum e_fs
{
    fs_none,
    fs_inline			/* function in declared inline */
};

/*
 * basic data types
 */

enum e_bt
{
    bt_void,			/* void type */
    bt_bool,			/* _Bool type */
    bt_char,			/* char type (signed) */
    bt_charu,			/* char type (unsigned) */
    bt_uchar,			/* unsigned char type */
    bt_schar,			/* signed char type */
    bt_short,			/* short type */
    bt_ushort,			/* unsigned short type */
    bt_int16,			/* int type (16 bits) */
    bt_uint16,			/* unsigned int type (16 bits) */
    bt_int32,			/* int type (32 bits) */
    bt_uint32,			/* unsigned int type (32 bits) */
    bt_long,			/* long type */
    bt_ulong,			/* unsigned long type */
    bt_longlong,		/* long long type */
    bt_ulonglong,		/* unsigned long long type */
    bt_float,			/* float type */
    bt_double,			/* double type */
    bt_longdouble,		/* long double type */
    bt_floatcomplex,		/* float _Complex type */
    bt_doublecomplex,		/* double _Complex type */
    bt_longdoublecomplex,	/* long double _Complex type */
    bt_floatimaginary,		/* float _Imaginary type */
    bt_doubleimaginary,		/* double _Imaginary type */
    bt_longdoubleimaginary,	/* long double _Imaginary type */
    bt_pointer16,		/* pointer type (16 bits) */
    bt_pointer32,		/* pointer type (32 bits) */
    bt_struct,			/* struct type */
    bt_union,			/* union type */
    bt_func,			/* function type */
    bt_bitfield,		/* Pseudo type - bitfield type */
    bt_ubitfield,		/* Pseudo type - unsigned bitfield type */
    bt_bbitfield,		/* Pseudo type - _Bool bitfield type */
    bt_ellipsis			/* Pseudo type - parameter list ... */
};

typedef unsigned BOOL;			/* true/false value */
typedef unsigned char BITSIZE;	/* size of a bitfield */
typedef struct sblock BLOCK;	/* scope table */
typedef enum e_bt BTYPE;		/* basic type */
typedef unsigned char CHAR;		/* input character */
typedef enum e_fs FSPECIFIER;	/* function specifier */
typedef unsigned int LABEL;		/* internal label */
typedef unsigned int LEVEL;		/* scope level */
typedef unsigned char QUALIFIER;/* type qualifiers */
typedef struct range RANGE;		/* value range */
typedef long SIZE;				/* size of object */
typedef unsigned long USIZE;	/* unsigned size of object */
typedef unsigned char STATE;	/* type state */
typedef unsigned char STATUS;	/* status of symbol */
typedef enum e_sc STORAGE;		/* symbol storage class */
typedef struct slit STRING;		/* string literal */
typedef struct swtab SWITCH;	/* switch table */
typedef struct sym SYM;			/* symbol entry */
typedef struct stab TABLE;		/* symbol table */
typedef enum e_sym TOKEN;		/* scanner token */
typedef struct typ TYP;			/* type entry */
typedef struct func FUNC;		/* function entry */
typedef struct structure STRUCT;/* struct/union entry */
typedef struct reg_use REGUSAGE;/* register usage on function calls */
typedef struct snode STMT;

#ifdef LONGLONG

#ifdef _WIN32
typedef __int64 IVAL;			/* signed integral value */
typedef unsigned __int64 UVAL;	/* unsigned integral value */
#else
typedef long long IVAL;			/* signed integral value */
typedef unsigned long long UVAL;/* unsigned integral value */
#endif /* __WIN32 */

#else

typedef long IVAL;			/* signed integral value */
typedef unsigned long UVAL;	/* unsigned integral value */

#endif /* LONGLONG */

#ifdef LONGDOUBLE
    typedef long double RVAL;	/* floating point value */


#else	/* 
 */
    typedef double RVAL;	/* floating point value */


#endif	/* LONGDOUBLE */
#ifdef SEQUENCE
    typedef unsigned int SEQNUM;	/* sequence number */

#endif

#ifndef TRUE
#define	TRUE			((BOOL)1)
#define	FALSE			((BOOL)0)
#endif /* TRUE */

#define	GLOBAL_SCOPE	((LEVEL)1)
#define	NIL_BLOCK		((BLOCK *)0)
#define	NIL_CHAR		((CHAR *)0)
#define	NIL_RANGE		((RANGE *)0)
#define	NIL_REGUSAGE	((REGUSAGE *)0)
#define	NIL_STRING		((STRING *)0)
#define	NIL_SWITCH		((SWITCH *)0)
#define	NIL_SYM			((SYM *)0)
#define	NIL_TABLE		((TABLE *)0)
#define	NIL_TYP			((TYP *)0)
#define	UNDEF_LABEL		((LABEL)0)


/*
 * these form the string literal pool
 */

struct slit
{
    STRING		*next;	/* next literal */
    const CHAR	*str;	/* pointer to the literal string */
    LABEL		label;	/* label to use when referencing a literal */
    size_t		len;	/* length of the literal */
};

/*
 *   Symbol Table Entry
 */
struct stab
{
    SYM    *head;		/* pointer to symbol at start of table */
    SYM    *tail;		/* pointer to symbol at end of table */
};

/*
 *   Scope Table
 */
struct sblock
{
    TABLE   symbols;	/* variable/functions etc */
    TABLE   tags;		/* struct/union/enum tags */
    BLOCK	*prev;		/* previous scope block */
    SIZE    offset;		/* stack offset for temporary variables */
};

#define	symbolsof(b)	((b)->symbols.head)

/*
 *   Symbol Table
 */
struct scopetbl
{
    BLOCK  *global;		/* pointer to global scope table */
    BLOCK  *local;		/* pointer to current scope table */
};

/*
 *   Range of a basic integral type
 */
struct range
{
    IVAL    low;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -