home *** CD-ROM | disk | FTP | other *** search
- /*
- * 68K/386 32-bit C compiler.
- *
- * copyright (c) 1996, David Lindauer
- *
- * This compiler is intended for educational use. It may not be used
- * for profit without the express written consent of the author.
- *
- * It may be freely redistributed, as long as this notice remains intact
- * and sources are distributed along with any executables derived from them.
- *
- * The author is not responsible for damages, either direct or consequential,
- * that may arise from use of this software.
- *
- * v1.5 August 1996
- * David Lindauer, gclind01@starbase.spd.louisville.edu
- *
- * Credits to Mathew Brandt for original K&R C compiler
- *
- */
-
- /* compiler header file */
-
- #define TRUE 1
- #define FALSE 0
-
- /* Codegen config */
- #ifdef i386
- #define FREEDATA 3
- #define FREEADDRESS 1
- #define FREEFLOAT 3
- #define MAXDATA 4
- #define MAXADDRESS 12
- #else
- #define MAXDATA 8
- #define MAXADDRESS 13
- #define LINKREG 6
- #define BASEREG 5
- #define FREEDATA 3
- #define FREEADDRESS 2
- #define FREEFLOAT 3
- #endif
-
- /* declaration flags */
- #define DF_INT 1
- #define DF_ABS 2
- #define DF_CONST 4
- #define DF_VOL 8
- #define DF_FUNCPARMS 16
- #define DF_GLOBAL 32
- #define DF_AUTOREG 64
-
- #define UF_DEFINED 1
- #define UF_USED 2
- #define UF_ASSIGNED 4
- #define UF_CANASSIGN 8
-
- #define GF_ASSIGN 1
- #define GF_CONTINUABLE 2
- #define GF_CONTINUE 4
- #define GF_GOTO 8
- #define GF_DEF 16
- #define GF_BREAK 32
- #define GF_RETURN 64
- #define GF_UNREACH 128
- #define GF_NOPROTO 256
- #define GF_AND 512
- #define GF_SUPERAND 1024
- #define GF_INLOOP 2048
- #define GF_INFUNCPARMS 4096
-
- #define PF_PRIVATE 0
- #define PF_PROTECTED 1
- #define PF_PUBLIC 2
- #define PF_VIRTUAL 4
- #define PF_PURE 8
- #define PF_INLINE 16
- #define PF_STATIC 32
- #define PF_CLASSDEF 64
- #define PF_CLASSFUNC 128
- #define PF_CLASSHEAD 256
-
- #ifdef i386
- #define LDBLSIZE 10
- #else
- #define LDBLSIZE 12
- #endif
- /* keywords and symbols */
- enum e_sym {
- id, cconst, iconst, lconst, sconst, rconst, plus, minus,
- star, divide, lshift, rshift, modop, eq, neq, lt, leq, gt,
- geq, assign, asplus, asminus, astimes, asdivide, asmodop,
- aslshift, asrshift, asand, asor, autoinc, autodec, hook, compl,
- comma, colon, semicolon, uparrow, openbr, closebr, begin, end,
- openpa, closepa, pointsto, dot, lor, land, not, or, and, ellipse,
- classsel, pointstar, dotstar, kw_int,
- kw_void, kw_char, kw_float, kw_double, kw_struct, kw_union,
- kw_long, kw_short, kw_unsigned, kw_signed, kw_auto, kw_extern,
- kw_register, kw_typedef, kw_static, kw_goto, kw_return,
- kw_sizeof, kw_break, kw_continue, kw_if, kw_else, kw_for,
- kw_do, kw_while, kw_switch, kw_case, kw_default, kw_enum, kw_volatile,
- kw_const, kw_phitext, kw__trap, kw__interrupt, kw__abs, kw__genword,
- kw_public, kw_private, kw_protected, kw_class, kw_friend, kw_new,
- kw_delete, kw_this, kw_operator, kw_inline,
- kw_try,kw_throw,kw_catch, kw_template,
- #ifdef i386
- kw__EAX,kw__ECX,kw__EDX,kw__EBX,kw__ESP,kw__EBP,kw__ESI,kw__EDI,
- #else
- kw__D0,kw__D1,kw__D2,kw__D3,kw__D4,kw__D5,kw__D6,kw__D7,
- kw__A0,kw__A1,kw__A2,kw__A3,kw__A4,kw__A5,kw__A6,kw__A7,
- kw__FP0,kw__FP1,kw__FP2,kw__FP3,kw__FP4,kw__FP5,kw__FP6,kw__FP7,
- #endif
- eof };
-
- /* storage classes */
- enum e_sc {
- sc_static, sc_auto, sc_global, sc_external, sc_type, sc_defunc, sc_const,
- sc_member, sc_label, sc_ulabel, sc_argument, sc_memberreg, sc_autoreg,
- sc_externalfunc,sc_abs };
-
- /* basic types */
- enum e_bt {
- /* This first two lines MUST be ordered for the
- * lostconv stuff to work
- */
- bt_char, bt_unsignedchar, bt_enum,bt_short, bt_unsignedshort,
- bt_long, bt_unsigned, bt_float, bt_double, bt_longdouble, bt_untyped,
- bt_pointer,bt_ref,bt_void,bt_struct, bt_union, bt_func, bt_class, bt_iclass,
- bt_ifunc, bt_ptrfunc,bt_matchall, bt_ellipse, bt_bitfield };
-
- struct slit {
- struct slit *next;
- int label;
- char *str;
- };
-
- /* symbols */
- struct sym {
- struct sym *next; /* next symbol (local tabs only) */
- char *name; /* symbol name */
- char storage_class; /* storage class */
- char extflag:1; /* if external, was it used */
- char absflag:1; /* the _abs keyword was used */
- char intflag:1; /* the _interrupt keyword was used */
- // char pflags;
- // struct sym *parent; /* Parent class */
- long addr; /* address */
- ENODE * defalt; /* Default for function params */
- /* Also name for CPP overload lists */
- /* these fields depend on storage_class */
- union {
- long i; /* int val */
- unsigned u; /* nsigned val */
- double f; /* float val */
- struct stab {
- struct sym *head, *tail; /* Overload table*/
- } overlist;
- char *s; /* string val */
- }
- value;
- /* Type declarations */
- struct typ {
- char type; /* the type */
- char val_flag; /* set if is an array */
- char uflags; /* Track usage */
- char cflags; /* const & vol flags */
- char classflags; /* Public, protected, private */
- char bits; /* -1 for not a bit val, else bit field len */
- char startbit; /* start of bit field */
- long size; /* total size of type */
- /* local symbol tables */
- struct stab lst; /* Symbol table for structs & functions */
- struct typ *btp; /* pointer to next type (pointers & arrays */
- char *sname; /* structure name ? */
- struct sym *tdef; /* Pointer to a typedef entry */
- }
- *tp;
- };
-
- #define SYM struct sym
- #define TYP struct typ
- #define TABLE struct stab
-
- #define MAX_STRLEN 120
- #define MAX_STLP1 121
-
- /* struct for preprocessor if tracking */
- typedef struct ifstruct {
- struct ifstruct *link; /* link */
- short iflevel;
- short elsetaken;
- } IFSTRUCT;
-
- /* #define tracking */
- typedef struct {
- char *string;
- short argcount;
- char **args;
- } DEFSTRUCT;
-
- /* error list */
- struct errl {
- struct errl *link;
- short errno;
- void *data;
- };
-
- /* used for error skimming */
- #define BALANCE struct balance
- #define BAL_PAREN 0
- #define BAL_BRACKET 0
- #define ERRORS struct errl
-
- struct balance {
- struct balance *back;
- short type;
- short count;
- };
-
- /* Global symbol table is a hash table */
- #define HASHTABLESIZE 1023
-
- typedef struct _hashrec_ {
- struct _hashrec_ *link; /* Link to next element in list */
- char *key; /* Full key */
- } HASHREC;
-
- /* known errors */
-
- #define ERR_ILLCHAR 1
- #define ERR_NEEDCHAR 2
- #define ERR_NEEDCONST 3
- #define ERR_FPCON 4
- #define ERR_IDEXPECT 5
- #define ERR_IDENTEXPECT 6
- #define ERR_UNEXPECT 7
- #define ERR_PUNCT 8
- #define ERR_INSERT 9
- #define ERR_UNDEFINED 10
- #define ERR_DUPSYM 11
- #define ERR_NOINIT 12
- #define ERR_INITSIZE 13
- #define ERR_NOCASE 14
- #define ERR_DUPCASE 15
- #define ERR_LABEL 16
- #define ERR_ELSE 17
- #define ERR_EXPREXPECT 18
- #define ERR_ILLCLASS 19
- #define ERR_ILLCLASS2 20
- #define ERR_NOPOINTER 21
- #define ERR_NOFUNC 22
- #define ERR_LVALUE 23
- #define ERR_DEREF 24
- #define ERR_ILLCAST 25
- #define ERR_PREPROCID 26
- #define ERR_INCLFILE 27
- #define ERR_CANTOPEN 28
- #define ERR_PREPROCMATCH 29
- #define ERR_MACROSUBS 30
- #define ERR_ARGMISMATCH 31
- #define ERR_ARGLENSHORT 32
- #define ERR_ARGLENLONG 33
- #define ERR_CALLMISMATCH 34
- #define ERR_CALLLENSHORT 35
- #define ERR_CALLLENLONG 36
- #define ERR_FUNCMISMATCH 37
- #define ERR_RETMISMATCH 38
- #define ERR_MISMATCH 39
- #define ERR_ARRAYMISMATCH 40
- #define ERR_ILLTYPE 41
- #define ERR_DECLEXPECT 42
- #define ERR_INVFLOAT 43
- #define ERR_INVTRAP 44
- #define ERR_BFILLEGAL 45
- #define ERR_BFTOOBIG 46
- #define ERR_ERROR 47 /* User error */
- #define ERR_BFTYPE 48 /* Bit field non-scalar */
- #define ERR_INTERP 49
- #define ERR_BFADDR 50
- #define ERR_MODCONS 51
- #define ERR_SZTYPE 52
- #define ERR_FUNCRETVAL 53
- #define ERR_SYMUNUSED 54
- #define ERR_SYMUNDEF 55
- #define ERR_SYMASSIGNED 56
- #define ERR_NONPORT 57
- #define ERR_UNREACHABLE 58
- #define ERR_FUNCUNUSED 59
- #define ERR_CODENONE 60
- #define ERR_BADEQUATE 61
- #define ERR_NOANDREG 62
- #define ERR_NOCONTINUE 63
- #define ERR_DUPLABEL 64
- #define ERR_NOFUNCARRAY 65
- #define ERR_NOVOIDRET 66
- #define ERR_ZEROSTORAGE 67
- #define ERR_SHORTPOINTER 68
- #define ERR_NOSTATICFUNC 69
- #define ERR_UNUSEDLABEL 70
- #define ERR_NOPROTO 71
- #define ERR_LOSTCONV 72
- #define ERR_UNDEFLABEL 73
- #define ERR_ILLREGISTER 74
- #define ERR_SUPERAND 75
- #define ERR_STATICSYMUNUSED 76
- #define ERR_NODECLARE 77
- #define ERR_ZEROPTR 78
- #define ERR_NOMAIN 79
- #define ERR_NOREF 80
- #define ERR_CANTREF 81
- #define ERR_TEMPUSED 82
- #define ERR_REFMUSTINIT 83
- #define ERR_TEMPINIT 84
- #define ERR_REFLVALUE 85
- #define ERR_REFNOCONS 86
- #define ERR_MISSINGDEFAULT 87
- #define ERR_AMBIGFUNC 88
- #define ERR_NOLOCALDEFAULT 89
- #define ERR_CPPMISMATCH 90
- #define ERR_NOOVERMAIN 91
- #define ERR_SWITCHINT 92
- #define ERR_NOFUNCMATCH 93
- #define ERR_PREDEFSTRUCT 94
- #define ERR_LOCALCLASS 95
- #define ERR_PUREDECL 96
- #define ERR_BADESTRUCT 97
- #define ERR_TYPECONSTRUCT 98
- #define ERR_NOTYPEQUAL 99
- #define ERR_NOTACLASS 100
- #define ERR_MAX 101
-
- /* alignment sizes */
-
- #ifdef i386
- #define AL_CHAR 1
- #define AL_SHORT 2
- #define AL_LONG 4
- #define AL_POINTER 4
- #define AL_FLOAT 4
- #define AL_DOUBLE 4
- #define AL_STRUCT 4
- #define AL_LONGDOUBLE 4
- #else
- #define AL_CHAR 1
- #define AL_SHORT 2
- #define AL_LONG 4
- #define AL_POINTER 4
- #define AL_FLOAT 4
- #define AL_DOUBLE 4
- #define AL_STRUCT 4
- #define AL_LONGDOUBLE 4
- #endif