From db7346cb8dfec558c713f36978e2b11742bea958 Mon Sep 17 00:00:00 2001 From: Lars Brinkhoff Date: Wed, 24 Oct 2018 10:42:08 +0200 Subject: [PATCH] Original files for GT, from PCC20. --- src/c/cmac.gt | 115 ++++++ src/c/g0.c | 85 ++++ src/c/g1.c | 505 +++++++++++++++++++++++ src/c/g2.c | 153 +++++++ src/c/g3.c | 1045 +++++++++++++++++++++++++++++++++++++++++++++++ src/c/g4.c | 308 ++++++++++++++ src/c/g5.c | 276 +++++++++++++ src/c/gt.h | 152 +++++++ src/c/gt.stinkr | Bin 0 -> 75 bytes src/c/h6000.gt | 282 +++++++++++++ src/c/pdp10.gt | 234 +++++++++++ src/c/pdp11.gt | 285 +++++++++++++ src/c/pdp20.gt | 234 +++++++++++ src/c/unix.gt | 340 +++++++++++++++ src/c/yparse.c | 535 ++++++++++++++++++++++++ 15 files changed, 4549 insertions(+) create mode 100644 src/c/cmac.gt create mode 100644 src/c/g0.c create mode 100644 src/c/g1.c create mode 100644 src/c/g2.c create mode 100644 src/c/g3.c create mode 100644 src/c/g4.c create mode 100644 src/c/g5.c create mode 100644 src/c/gt.h create mode 100644 src/c/gt.stinkr create mode 100644 src/c/h6000.gt create mode 100644 src/c/pdp10.gt create mode 100644 src/c/pdp11.gt create mode 100644 src/c/pdp20.gt create mode 100644 src/c/unix.gt create mode 100644 src/c/yparse.c diff --git a/src/c/cmac.gt b/src/c/cmac.gt new file mode 100644 index 00000000..8599f6bf --- /dev/null +++ b/src/c/cmac.gt @@ -0,0 +1,115 @@ +typenames (char, int, float, double); +regnames (a, b); +memnames (reg, auto, ext, stat, param, label, intlit, floatlit, + stringlit, ia, ib); +size 1 (char, int, float, double); +align 1 (char, int, float, double); +class r (a, b); +saveareasize 8; +pointer p0 (1); +offsetrange p0 (0, 0); +returnreg a (int, double, p0); +type char(r), int(r), float(r), double(r), p0(r); + +.sw: a,,1; + ++i: -i: *i: /i: %: <<: >>: +&: .OR: ^: +p0: -p0: -p0p0: a,b,a; + +.BNOT: -ui: r,,1; + +&u0: M,,r; + +.ic: .ci: .ip0: .p0i: r,,1; + +==p0: !=p0: p0: <=p0: >=p0: +==i: !=i: i: <=i: >=i: a,b,label; + +==0p0: !=0p0: a,,label; + + +macros + ++i: " CADD" +-i: " CSUB" +*i: " CMUL" +/i: " CDIV" +%: " CMOD" +<<: " CLS" +>>: " CRS" +&: " CAND" +.OR: " COR" +^: " CXOR" ++p0: " PINC" +-p0: " PDEC" +-p0p0: " PSUB" +-ui: " CMINUS #R" +.BNOT: " CNOT #R" + +&u0: + (auto,,): " LAAUTO #R,#F" + (ext,,): " LAEXTN #R,#F" + (stat,,): " LASTAT #R,#F" + (param,,): " LAPARM #R,#F" + (stringlit,,): " LASTRG #R,#F" + +==i: ==p0: " JEQ #R" +!=i: !=p0: " JNE #R" +i: >p0: " JGT #R" +<=i: <=p0: " JLE #R" +>=i: >=p0: " JGE #R" + +==0p0: " JNULL #R" +!=0p0: " JNNULL #R" + +.cc: .ii: .p0p0: + (r,,r): " LREG #R,#F" + (auto,,): " LAUTO #R,#F" + (ext,,): " LEXTRN #R,#F" + (stat,,): " LSTAT #R,#F" + (param,,): " LPARM #R,#F" + (ia|ib,,): " LVPTR #R,#F" + (intlit,,): " LLIT #R,#F" + (,,auto): " STAUTO #F,#R" + (,,ext): " STEXTN #F,#R" + (,,stat): " STSTAT #F,#R" + (,,param): " STPARM #F,#R" + (,,ia|ib): " STVPTR #F,#R" + +.ic: .ci: +.ip0: .p0i: "\" + +hd: " HEAD" +end: " CEND" +en: " CENTRY #0" +ex: " CEXTRN #0" + +eq: " CEQU #0" +l: " LABDEF #0" +st: " STATIC #0" +ln: " LINNUM #0" + +ad0: + (,,ext): " ADCON #R" + (,,stat): " SADCON #R" +in: c: " INTCON #0" +lc: " LABCON #0" +sc: " STRCON #0" +z: " CZERO #0" + +p: " PROLOG #0,%i(#1)" +ep: " EPILOG #0,#1" +ca: + (ext,,): " CCALL #0,#1,#F" + (ia|ib,,): " CALREG #0,#1,#F" +rt: " CRETRN" +go: " CGOTO #R" +ts: " TSWITCH #0,#5,#2" +ets: " ETSWIT #0,#5,#2" +ls: " LSWITCH #0,#2" +els: " ELSWIT #0,#2" + +pu: pd: " PURE" +im: da: " IMPURE" +al: "\" diff --git a/src/c/g0.c b/src/c/g0.c new file mode 100644 index 00000000..73353e17 --- /dev/null +++ b/src/c/g0.c @@ -0,0 +1,85 @@ +# include "gt.h" + +/* + + GT Compiler + Section 0: Command Routine + +*/ + +/********************************************************************** + + Command Usage: GT {-options} source.file + + Output is written on the file "source.gtout". + + Options: + d - print parser debugging info + t - print tokens + +**********************************************************************/ + + +/********************************************************************** + + External Routines used by GT compiler: + + copen open file for input/output + cgetc read character + cputc write character + ceof test for end-of-file + cclose close file + cexit terminate process + apfname append suffix to file name + + plus C24.C (parser) and C96.C (cprint) + +**********************************************************************/ + +char *fn_source, + *fn_out, + fnbuff[40]; + +main (argc, argv) int argc; char *argv[]; + + {int f, i, c; + extern int debug, tflag; + char *s; + + /* check for options */ + + if (argc > 1 && (s = argv[1])[0] == '-') i = 2; + else {i = 1; s = 0;} + + /* check for file name */ + + if (argc <= i) + {cprint ("Usage: GT description.file\n"); + cexit (100); + } + + /* process options */ + + if (s) while (c = *++s) switch (c) { + case 'd': debug = TRUE; break; + case 't': tflag = TRUE; break; + default: cprint ("unrecognized option: '%c'\n", c); + } + + /* check that source file exists */ + + fn_source = argv[i]; + if ((f = copen (fn_source, MREAD, TEXT)) == OPENLOSS) + {cprint ("Can't Find '%s'.\n", fn_source); + cexit (100); + } + cclose (f); + + apfname (fnbuff, fn_source, "gtout"); + fn_out = fnbuff; + + pinit (); + parse (); + cleanup (0); + } + diff --git a/src/c/g1.c b/src/c/g1.c new file mode 100644 index 00000000..d6c4ec4d --- /dev/null +++ b/src/c/g1.c @@ -0,0 +1,505 @@ +# include "gt.h" + +/* + + GT Compiler + Section 1: Lexical Analyzer + +*/ + +/********************************************************************** + + A token consists of a TAG and an INDEX. + The valid token TAGs are listed in the include file. + The interpretation of the INDEX is dependent upon the TAG: + + T_AMOP the number of the abstract_machine_operator + TIDN index of identifier name in CSTORE + TINTCON value of integer constant + TSTRING index of source representation in CSTORE + others the line number upon which the token appeared + +**********************************************************************/ + +char *keyn[] { + "typenames", + "align", + "pointer", + "class", + "conflict", + "type", + "memnames", + "macros", + "size", + "indirect", + "regnames", + "returnreg", + "saveareasize", + "offsetrange", + "m", + 0}; + +int keyv[] { + _TYPENAMES, + _ALIGN, + _POINTER, + _CLASS, + _CONFLICT, + _TYPE, + _MEMNAMES, + _MACROS, + _SIZE, + _INDIRECT, + _REGNAMES, + _RETURNREG, + _SAVEAREASIZE, + _OFFSETRANGE, + _M}; + +/* character type array */ + +# define _ALPHA 50 /* identifier or keyword */ +# define _DIGIT 51 /* constant or identifier */ +# define _QUOTE 52 /* character string indicator */ +# define _AMOP 53 /* character beginning an abstract_machine_operation */ +# define _EOL 54 /* newline */ +# define _BLANK 55 /* blank, tab, VT, FF, CR */ +# define _BAD 56 /* invalid character */ +# define _MINUS 57 /* minus sign: integer or AMOP */ +# define _NAME (typ[t]==_ALPHA || typ[t]==_DIGIT) + +int typ[] { +_BAD, _BAD, _BAD, _BAD, _BAD, _BAD, _BAD, _BAD, +_BAD, _BLANK, _EOL, _BLANK, _BLANK, _BLANK, _BAD, _BAD, +_BAD, _BAD, _BAD, _BAD, _BAD, _BAD, _BAD, _BAD, +_BAD, _BAD, _BAD, _BAD, _BAD, _BAD, _BAD, _BAD, +_BLANK, _AMOP, _QUOTE, _BAD, _BAD, _AMOP, _AMOP, _BAD, +_LPARN, _RPARN, _AMOP, _AMOP, _COMMA, _MINUS, _AMOP, _AMOP, +_DIGIT, _DIGIT, _DIGIT, _DIGIT, _DIGIT, _DIGIT, _DIGIT, _DIGIT, +_DIGIT, _DIGIT, _COLON, _SEMI, _AMOP, _AMOP, _AMOP, _AMOP, +_BAD, _ALPHA, _ALPHA, _ALPHA, _ALPHA, _ALPHA, _ALPHA, _ALPHA, +_ALPHA, _ALPHA, _ALPHA, _ALPHA, _ALPHA, _ALPHA, _ALPHA, _ALPHA, +_ALPHA, _ALPHA, _ALPHA, _ALPHA, _ALPHA, _ALPHA, _ALPHA, _ALPHA, +_ALPHA, _ALPHA, _ALPHA, _LBRAK, _BAD, _RBRAK, _AMOP, _ALPHA, +_BAD, _ALPHA, _ALPHA, _ALPHA, _ALPHA, _ALPHA, _ALPHA, _ALPHA, +_ALPHA, _ALPHA, _ALPHA, _ALPHA, _ALPHA, _ALPHA, _ALPHA, _ALPHA, +_ALPHA, _ALPHA, _ALPHA, _ALPHA, _ALPHA, _ALPHA, _ALPHA, _ALPHA, +_ALPHA, _ALPHA, _ALPHA, _BAD, _OR, _BAD, _NOT, _BAD}; + +/* translation table */ + +int trt[] { +000,001,002,003,004,005,006,007,010,' ','\n',' ',' ',' ',016,017, +020,021,022,023,024,025,026,027,030,031,032,033,034,035,036,037, +' ','!','"','#','$','%','&','\'','(',')','*','+',',','-','.','/', +'0','1','2','3','4','5','6','7','8','9',':',';','<','=','>','?', +0100,'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o', +'p','q','r','s','t','u','v','w','x','y','z','[','\\',']','^','_', +0140,'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o', +'p','q','r','s','t','u','v','w','x','y','z','{','|','}','~',0177 }; + +/* hash table, holds keywords and identifiers */ + +# define hentry struct _hentry +hentry + {char *hnp; /* pointer to string in cstore */ + int hclass; /* 1 - identifier, >1 - keyword type, + <=0 - manifest constant, index in mcdef */ + }; + +/* identifier classes */ + +# define h_idn 1 + +hentry hshtab[hshsize], *lookup(), *lookx(); +int hshused 0; /* number of entries used */ + +/* character store: holds keywords and identifiers */ + +char cstore[cssiz]; +char *cscsp -1; /* current string pointer: points to first + unused character in cstore */ +char *cscnp -1; /* current name pointer: points to last unused + character in cstore */ +char *cp; /* pointer to working string */ + +/* communication between lexical routines */ + +extern int lextag, lexindex, lexline; + +int ccard, /* indicates that current + tokens should be interpreted + by the lexical phase */ + lccard, /* lgetc local ccard */ + c, /* current untranslated input char */ + t, /* current translated input char */ + peekt, /* lookahead translated character */ + truncate; /* indicates that cstore is full */ + +/* FILES */ + +int f_source -1; /* source file */ + +extern char *fn_source; + +int i_line, /* current line number */ + i_eof, /* indicates end-of-file */ + i_nlflag; /* indicates first char of line */ + +/* manifest constants */ + +int jdefine, /* index of "DEFINE" in hashtab */ + mcdef[mcdsz], /* storage of manifest constant + definitions */ + *cmcdp {mcdef}; /* pointer to next free word in mcdef */ + +char *eopch[] { + "-ui", "-ud", "++bi", "++ai", "--bi", "--ai", ".bnot", "!", + ".lseq", "", ".sw", "++bc", "++ac", "--bc", "--ac", "&u0", + "&u1", "&u2", "&u3", "*u", "==0p0", "==0p1", "==0p2", "==0p3", + "!=0p0", "!=0p1", "!=0p2", "!=0p3", "", "", "", "", + ".ci", ".cf", ".cd", ".ic", ".if", ".id", ".ip0", ".ip1", + ".ip2", ".ip3", ".fc", ".fi", ".fd", ".dc", ".di", ".df", + ".p0i", ".p0p1", ".p0p2", ".p0p3", ".p1i", ".p1p0", ".p1p2", ".p1p3", + ".p2i", ".p2p0", ".p2p1", ".p2p3", ".p3i", ".p3p0", ".p3p1", ".p3p2", + "+i", "=+i", "+d", "=+d", "-i", "=-i", "-d", "=-d", + "*i", "=*i", "*d", "=*d", "/i", "=/i", "/d", "=/d", + "%", "=%", "<<", "=<<", ">>", "=>>", "&", "=&", + "^", "=^", ".or", "=or", "&&", ".tvor", "-p0p0", "=", + ".argi", ".argd", ".arg0", ".arg1", ".arg2", ".arg3", "+p0", "+p1", + "+p2", "+p3", "-p0", "-p1", "-p2", "-p3", "", "", + ".cc", ".ii", ".ff", ".dd", ".p0p0", ".p1p1", ".p2p2", ".p3p3", + "", "?", ".", "call", "float", "string", "int", "idn", + "==i", "!=i", "i", "<=i", ">=i", "==d", "!=d", + "d", "<=d", ">=d", "==p0", "!=p0", "p0", + "<=p0", ">=p0", "==p1", "!=p1", "p1", "<=p1", ">=p1", + "==p2", "!=p2", "p2", "<=p2", ">=p2", "==p3", "!=p3", + "p3", "<=p3", ">=p3", "", "", "", "", + "++bf", "++af", "--bf", "--af", "++bd", "++ad", "--bd", "--ad", + "++bp0", "++ap0", "--bp0", "--ap0", "++bp1", "++ap1", "--bp1", "--ap1", + "++bp2", "++ap2", "--bp2", "--ap2", "++bp3", "++ap3", "--bp3", "--ap3"}; + +/********************************************************************** + + GETTOK - Get Next Token + + Sets variables LEXTAG, LEXINDEX, LEXLINE. This routine + implements compiler control lines. + +**********************************************************************/ + +gettok () + + {while (TRUE) + {tokget(); + if (ccard) + {if (lextag==TIDN && lexindex==jdefine) + defccl (); + else {error (1004, lexline); + while (lextag) tokget(); + } + continue; + } + return; + } + } + +/********************************************************************** + + DEFCCL - Handle DEFINE Compiler Control Line + +**********************************************************************/ + +defccl () + + {hentry *hp; + int k; + + tokget (); + if (lextag != TIDN) + {error (1003, lexline); + while (lextag) tokget (); + } + else + {hp = lookx (); + k = -(cmcdp-mcdef); + do + {tokget(); + if(cmcdp >= &mcdef[mcdsz-1]) + error(4004, lexline); + *cmcdp++ = lextag; + if (lextaghclass = k; + } + } + +/********************************************************************** + + TOKGET - Internal Get Token Routine + +**********************************************************************/ + +tokget () + + {static int *mcp, mcflag; + int sum, flag, i; + char buf[40]; + hentry *hp; + +while (TRUE) + {if (mcflag) + {lextag= *mcp++; + lexindex= *mcp++; + if (lexindex==UNDEF) lexindex=lexline; + if (lextag) return; + mcflag=FALSE; + } + if (peekt) t=peekt; + else t=trt[lgetc()]; + if (!t) break; + peekt=NULL; + flag = truncate = FALSE; + cp = cscsp; /* character stack pointer */ + lexline = i_line; /* lgetc current line */ + ccard =| lccard; /* set control card indicator */ + + switch (typ[t]) { + +case _ALPHA: do move(t); while (_NAME); + *cp = 0; + hp = lookup (cscsp); + peekt = t; + if (hp->hclass > 1) /* keyword */ + {lextag = hp->hclass; + lexindex = lexline; + } + else if (hp->hclass <= 0) /* manifest constant */ + {mcflag = TRUE; + mcp = mcdef + -hp->hclass; + continue; + } + else /* identifier */ + {lextag = TIDN; + lexindex = hp->hnp - cstore; + if (truncate) error (4001,lexline); + } + return; + +case _MINUS: move(0); /* look at next char */ + if (typ[t] != _DIGIT) + {peekt = '-'; + goto l_amop; + } + flag = TRUE; + +case _DIGIT: /* fall through */ + + sum = 0; + do + {sum = sum*10 + t-'0'; + move (0); + } while (typ[t] == _DIGIT); + + lextag = TINTCON; + lexindex = (flag ? -sum : sum); + peekt = t; + return; + +case _AMOP: /* abstract machine operator */ + +l_amop: i = 0; + if (peekt) buf[i++]=peekt; + do {buf[i++]=t; move(0);} + while(typ[t]==_AMOP || typ[t]==_ALPHA + || typ[t]==_DIGIT || typ[t]==_MINUS ); + peekt = t; + buf[i]=0; + for (i=0;i=hshsize) i=0; + + /* not found, so enter */ + + if (++hshused >= hshsize) error (4000,lexline); + while (--p >= np) *cscnp-- = *p; /* move name */ + hp = &hshtab[i]; + hp->hnp = cscnp+1; + hp->hclass = h_idn; + return (hp); + } + +/********************************************************************** + + LOOKX - lookup current identifier + +**********************************************************************/ + +hentry *lookx () + {return (lookup (&cstore[lexindex]));} + +/********************************************************************** + + LXINIT - Lexical Phase Initializaton Routine + +**********************************************************************/ + +lxinit() + + {int i; + char *s; + + f_source = xopen (fn_source, MREAD, TEXT); + cscsp = cstore; + cscnp = &cstore[cssiz-1]; + lexline = i_line = 1; + i_eof = FALSE; + i_nlflag = TRUE; + + i = 0; + while (s = keyn[i]) keyword (s, keyv[i++]); + + jdefine=lookup("define")->hnp-cstore; + } + +/********************************************************************** + + KEYWORD - Define a Reserved Word + +**********************************************************************/ + +int keyword (s, type) int type; char *s; + + {lookup(s)->hclass = type;} + +/********************************************************************** + + LGETC - Character Input Routine + +**********************************************************************/ + +int lgetc() + + {int ch; + + if (i_eof) return (LEXEOF); + + while (TRUE) + {ch = cgetc (f_source); + if (ceof (f_source)) + {i_eof=TRUE; + return (LEXEOF); + } + if (trt[ch]=='\n') + {++i_line; + lccard=FALSE; + i_nlflag=TRUE; + } + else if (i_nlflag) + {i_nlflag=FALSE; + if (trt[ch]=='#') + {lccard=TRUE; + continue; + } + } + return (ch); + } + } + +/********************************************************************** + + STCMP - Compare Strings + +**********************************************************************/ + +int stcmp (s1, s2) char *s1,*s2; + + {int u; + + while ((u = *s1++) == *s2++) if (!u) return (TRUE); + return (FALSE); + } + \ No newline at end of file diff --git a/src/c/g2.c b/src/c/g2.c new file mode 100644 index 00000000..d1d8d807 --- /dev/null +++ b/src/c/g2.c @@ -0,0 +1,153 @@ +# include "gt.h" + +/* + + GT Compiler + Section 2: Parser Interface + +*/ + +extern int lineno; +extern char cstore[], *fn_out; + +int f_out -1; + +/********************************************************************** + + Parser Error Message Routines + +**********************************************************************/ + +synerr (line) {error (2007, line);} +giveup (line) {error (4012, line);} +stkovf (line) {error (4003, line);} +delmsg (line) {error (2012, line);} +skpmsg (line) {error (2013, line);} + +qprint (q) {error (2008, -1, q);} +tprint (tp) token *tp; {error (2011, -1, tp->type, tp->index);} +pcursor () {error (2010, -1);} + +stkunf (line) {error (6006, line);} +tkbovf (line) {error (6002, line);} +badtwp (line) {error (6005, line);} +badtok (line, i) {error (6000, line, i);} + +/********************************************************************** + + PTOKEN - Print Token Routine + +**********************************************************************/ + +ptoken (tp, f) token *tp; + + {int type, index; + extern char *sterm[], *eopch[]; + + type = tp->type; + index = tp->index; + switch (type) { + case TIDN: cprint (f, "%s", &cstore[index]); + return; + case TINTCON: cprint (f, "%d", index); + return; + case TSTRING: cprint (f, "\"\""); + return; + case T_AMOP: cprint (f, "%s", eopch[index]); + return; + default: cprint (f, "%s", sterm[type]); + } + } + +/********************************************************************** + + PINIT - Parser Initialization Routine + +**********************************************************************/ + +pinit () + + {extern int prm(); + lxinit (); + f_out = xopen (fn_out, MWRITE, TEXT); + deffmt ('m', prm, 1); + } + +/********************************************************************** + + CLEANUP - Parser CleanUp Routine + +**********************************************************************/ + +cleanup (rcode) + + {cclose (f_out); + cexit (rcode); + } + +/********************************************************************** + + STACK FOR ACTION ROUTINES + +**********************************************************************/ + +int stack[pssize]; +int *sp {stack}; + +int *push (i) + + {if (++sp >= &stack[pssize]) error (4007, lineno); + *sp = i; + return (sp); + } + +int pop () + + {int i; + + i = *sp--; + if (sp < stack) error (6001, lineno); + return (i); + } + +int *setsp (nsp) int *nsp; /* set stack pointer */ + + {if (nsp < stack) error (6003, lineno); + if (nsp >= &stack[pssize]) error (6004, lineno); + return (sp = nsp); + } + +int *top () /* get stack pointer */ + + {return (sp); + } + +int *get_top (nsp) int *nsp; /* get list from top of stack */ + + {int *ot; + + ot = top(); + setsp (nsp-1); + return (ot); + } + +/********************************************************************** + + GPRINT - Formatted Print Routine + +**********************************************************************/ + +gprint (fmt,x1,x2,x3) char fmt[]; + + {cprint (f_out, fmt, x1, x2, x3);} + +/********************************************************************** + + PRM - Print String in Cstore + +**********************************************************************/ + +prm (i, f) + + {cprint (f, "%s", &cstore[i]);} + \ No newline at end of file diff --git a/src/c/g3.c b/src/c/g3.c new file mode 100644 index 00000000..099dacca --- /dev/null +++ b/src/c/g3.c @@ -0,0 +1,1045 @@ +# include "gt.h" + +/* + + GT Compiler + Section 3: Action Routines + +*/ + +/* The maximum number of registers is really limited by the number + of bits in a word on the machine running this program and + on the machine running the C compiler since the set of all + registers is represented by the bits in a single word. + Also, the maximum number of indirect classes is even further + limited because the set of all memory reference classes, which + includes indirection via registers, is also represented by the + bits in a single word. */ + +# define maxregs 16 /* maximum number of registers */ +# define maxtypes 8 /* maximum number of data types */ +# define maxmem 16 /* maximum number of memory refs */ +# define maxnmacs 100 /* maximum number of named macros */ +# define retregsz 18 /* 2 + maxtypes*2 */ +# define namop 0300 /* number of abstract machine operators */ +# define mdfsz 2000 /* size of macro definition list table */ + +# define find_reg fndrg +# define find_pc fndpc +# define find_type fndty + +extern char cstore[], *cscsp; +extern int lineno, f_out, *get_top(); + +int ntype 0, /* number of data types */ + typname[maxtypes], /* names of data types */ + nmem 0, /* current number of memory refs */ + memname[maxmem], /* names of memory refs */ + nreg 0, /* current number of registers */ + regname[maxregs], /* index to name of register */ + rcname[maxregs], /* index to name of register classes */ + rcp[maxregs], /* descriptions of register classes */ + nrc 0, /* number of register classes */ + pcname[maxtypes], /* index to name of pointer classes */ + npc 0, /* current number of pointer classes */ + pcor[maxtypes], /* pointer class offset range function no. */ + norr 0, /* number of offset range functions emitted */ + trdt[maxtypes], /* registers holding a given type */ + prdt[maxtypes], /* registers holding a given pointer */ + cfp[maxregs], /* descriptions of conflicts */ + nac 0, /* number of alignment classes */ + calign[maxtypes], /* align. factors of align. classes */ + tsize[maxtypes], /* sizes of each type */ + talign[maxtypes], /* align. classes of each type */ + tpoint[maxtypes], /* pointer classes of each type */ + pc_align[maxtypes], /* resolution of pointer class in characters */ + retreg[retregsz], /* the registers in which values + of a given type are returned + in a function call - this array is + indexed by the value returned by a + routine CTYPE in the code generator */ + cfactor 0, /* current alignment factor */ + save_area_size -1, + opreg[namop], /* registers for result of op */ + opmem[namop], /* memory refs for result of op */ + oplist[namop], /* used to construct opreg, opmem */ + coplist 0, /* index into oplist */ + amopp[namop], /* indices to lists in amopl */ + c_oploc 0, /* current index in oploc table */ + amopl[500], /* lists of indices to oplocs */ + c_amopl 0, /* current entry in amopl */ + copflag l_unknown, /* current flag */ + allmem -1, /* this name represents all mem_refs */ + mactab[namop], /* names of macro calls */ + macdef[namop], /* index in mdeflist to beginning of macro */ + nnmacs 0, /* current number of named macros */ + nmacname[maxnmacs], /* names of named macros */ + nmacdef[maxnmacs], /* index in mdeflist to beginning of macro */ + mdeflist[mdfsz], /* list of macro definitons, each a list of + integers: + + flag(operand 1) + word(operand 1) + flag(operand 2) + word(operand 2) + flag(result) + word(result) + + ... + + -1 + + */ + cmacro 1, /* current macro number */ + cmdf 0; /* current entry in mdeflist */ + +struct oploc { + int flag[3], /* flag for opnd 1, opnd 2, result: + 1 - memory ref type + 2 - registers + 3 - result left in opnd 1 + 4 - result left in opnd 2 + */ + word[3], /* word for opnd1, opnd2, result: + bits represent memory ref + types or register numbers + according to the flag + */ + clobber;} /* bits indicate registers which + are clobbered as a result of this + operation + */ + doploc; + +/********************************************************************** + + PRCOM - Print Comment + +**********************************************************************/ + +prcom (name, narray, varray, count) + int name, narray[], varray[], count; + + {int i; + + for (i=0; i>i) & 1) + '0'); + } + +/********************************************************************** + + GENERIC TABLE ROUTINES + + TFIND - find name in table, return -1 if not there + TENTER - find name in table, enter if not there + TEFIND - find name in table, emit error message if not there + +**********************************************************************/ + +int tfind (name, table, size) + int name, *table, size; + + {int i; + + for (i=0;i= 0) return (i); + if (size >= maxsize) error (errno, lineno); + table[size] = name; + return ((*psize)++); + } + +int tefind (name, table, size, errno) + int name, *table, size, errno; + + {int i; + + i = tfind (name, table, size); + if (i<0) error (errno, lineno, TIDN, name); + return (i); + } + +/********************************************************************** + + SPECIFIC TABLE ROUTINES + +**********************************************************************/ + +int typ_find (n) {return (tfind (n, typname, ntype));} +int typ_enter (n) {return (tenter (n, typname, &ntype, maxtypes, 4019));} +int find_type (n) {return (tefind (n, typname, ntype, 2028));} + +int mem_find (n) {return (tfind (n, memname, nmem));} +int mem_enter (n) {return (tenter (n, memname, &nmem, maxmem, 4020));} +int find_mem (n) {return (tefind (n, memname, nmem, 2029));} + +int reg_find (n) {return (tfind (n, regname, nreg));} +int reg_enter (n) {return (tenter (n, regname, &nreg, maxregs, 4017));} +int find_reg (n) {return (tefind (n, regname, nreg, 2027));} + +int rc_find (n) {return (tfind (n, rcname, nrc));} +int rc_enter (n) {return (tenter (n, rcname, &nrc, maxregs, 4018));} + +int pc_find (n) {return (tfind (n, pcname, npc));} +int pc_enter (n) {return (tenter (n, pcname, &npc, maxtypes, 4016));} +int find_pc (n) {return (tefind (n, pcname, npc, 2026));} + +/********************************************************************** + + GETREG - return bit set for register named N + if undefined, emit message and return empty set + +**********************************************************************/ + +int getreg (n) + + {int r; + + if ((r = find_reg (n)) < 0) return (0); + return (1 << r); + } + +/********************************************************************** + + GETRC - same as GETREG but N can name register class + +**********************************************************************/ + +int getrc (n) + + {int c; + + if ((c = rc_find (n)) >= 0) return (rcp[c]); + return (getreg (n)); + } + +/********************************************************************** + + ATNAMES - define names of data types + +**********************************************************************/ + +atnames (sp) int *sp; + + {int *ot; + + ot = get_top (sp); + if (ntype != 0) error (2002, lineno); + else while (sp<=ot) typ_enter (*sp++); + } + +/********************************************************************** + + ARNAMES - define names of registers + +**********************************************************************/ + +arnames (sp) int *sp; + + {int *ot; + + ot = get_top (sp); + if (nreg != 0) error (2003, lineno); + else while (sp <= ot) reg_enter (*sp++); + } + +/********************************************************************** + + AMNAMES - define names of memory references + +**********************************************************************/ + +amnames (sp) int *sp; + + {int *ot; + + ot = get_top (sp); + if (nmem != 0) error (2004, lineno); + else while (sp <= ot) mem_enter (*sp++); + } + +/********************************************************************** + + FS1 - finished with TYPENAMES,REGNAMES, and MEMNAMES statements + +**********************************************************************/ + +fs1() + + {int t; + + if (ntype == 0) error (4013,lineno); + if (nreg == 0) error (4014,lineno); + if (nmem == 0) error (4015,lineno); + + for (t=0; t=0;--c) if ((a%pc_align[c])==0) break; + if (c<0) error(2022,lineno,TIDN,typname[t]); + else tpoint[t]=c; + } + } + +/********************************************************************** + + ASIZE - define size of basic types + + SIZE - the size in characters + SP - a pointer to a list of the types with the given size + +**********************************************************************/ + +asize (size, sp) int size, *sp; + + {int *ot, t; + + ot = get_top (sp); + while (sp<=ot) + {if ((t = find_type (*sp++)) >= 0) + if (tsize[t] >= 0) + error(2015,lineno,TIDN,typname[t]); + else tsize[t]=size; + } + } + +/********************************************************************** + + AALIGN - define alignment class + + factor - alignment factor + sp - pointer to list of types in this alignment class + +**********************************************************************/ + +aalign (factor, sp) int factor, *sp; + + {int *ot, t; + + ot = get_top (sp); + if (factor <= cfactor) + {error (2009, lineno); + return; + } + cfactor = calign[nac] = factor; + while (sp <= ot) + {if ((t = find_type (*sp++)) >= 0) + if (talign[t]>=0) + error (2020,lineno,TIDN,typname[t]); + else talign[t] = nac; + } + nac++; + } + +/********************************************************************** + + APOINT - define pointer class + + name - the name of the pointer class + resolution - the resolution in characters of a pointer + in the pointer class + +**********************************************************************/ + +apoint (name, resolution) int name,resolution; + + {static int current_resolution; + + if (npc==0) current_resolution=0; + if (resolution<0 || resolution<=current_resolution) + {error(2009,lineno); + return; + } + current_resolution=pc_align[pc_enter(name)]=resolution; + } + +/********************************************************************** + + ACLASS - define register class + + idn - name of register class + sp - pointer to list of names of members of the class + +**********************************************************************/ + +aclass (idn ,sp) int idn, *sp; + + {int *ot, rc; + + ot = get_top (sp); + rc = rc_enter (idn); + while (sp <= ot) rcp[rc] =| getreg (*sp++); + } + +/********************************************************************** + + ASAVE - define save area size (in characters) + +**********************************************************************/ + +asave (i) + + {save_area_size = i; + } + +/********************************************************************** + + AOR1 - Handle Offset_Range of Form (lo,hi) + +**********************************************************************/ + +aor1 (idn, lo, hi) + + {int pc; + + if ((pc = find_pc (idn)) >= 0) + {gprint ("int ofok%d (i) {return (i>=%d && i<=%d);}\n", + ++norr, lo, hi); + pcor[pc] = norr; + } + } + +/********************************************************************** + + AOR2 - Handle Offset_Range of Form (lo,) + +**********************************************************************/ + +aor2 (idn, lo) + + {int pc; + + if ((pc = find_pc (idn)) >= 0) + {gprint ("int ofok%d(i) {return (i>=%d);}\n", + ++norr, lo); + pcor[pc] = norr; + } + } + +/********************************************************************** + + AOR3 - Handle Offset_Range of Form (,hi) + +**********************************************************************/ + +aor3 (idn, hi) + + {int pc; + + if ((pc = find_pc (idn)) >= 0) + {gprint ("int ofok%d(i) {return (i<=%d);}\n", + ++norr, hi); + pcor[pc] = norr; + } + } + +/********************************************************************** + + AOR4 - Handle Offset_Range of Form (,) + +**********************************************************************/ + +aor4 (idn) + + {int pc; + + if ((pc = find_pc (idn)) >= 0) + {gprint ("int ofok%d(i) {return (1);}\n", ++norr); + pcor[pc] = norr; + } + } + +/********************************************************************** + + ARETREG - define the types which are returned in a given register + + REG_NAME - the name of the register + SP - a pointer to a list of type or pointer_class names + +**********************************************************************/ + +aretreg (reg_name, sp) int *sp; + + {int *ot, type_name, type, pc, reg, i; + + ot = get_top (sp); + + if ((reg = find_reg (reg_name)) >= 0) + while (sp<=ot) + {i = 0; + type_name = *sp++; + if ((type=typ_find(type_name)) >= 0) i=type+2; + else if ((pc=pc_find(type_name)) >= 0) i=pc+ntype+2; + if (i==0) error(2028,lineno,TIDN,type_name); + else if (retreg[i]>=0) error(2005,lineno,TIDN,type_name); + else retreg[i]=reg; + } + } + +/********************************************************************** + + ATYPE - define register types + + type - C type + sp - pointer to list of register names of that type + +**********************************************************************/ + +atype (type_name, sp) int type_name, *sp; + + {int *ot, type; + + if ((type = typ_find (type_name)) < 0) + {aptype (type_name, sp); + return; + } + ot = get_top (sp); + while (sp<=ot) trdt[type] =| getrc (*sp++); + } + +/********************************************************************** + + FTYPE - finished with TYPE statement + +**********************************************************************/ + +ftype() + + {int i, r, flt_hack; + + prcom ("\ttype", typname, trdt, ntype); + prcom ("pointer class", pcname, prdt, npc); + + if (save_area_size <0) + {error (2014, lineno); + save_area_size=0; + } + + flt_hack = 1; + if (tsize[tdouble]==tsize[tint] && tsize[tfloat]==tsize[tint] + && talign[tdouble]<=talign[tint] && talign[tfloat]<=talign[tint]) + flt_hack = 0; + + /* output OFF_OK array */ + + gprint ("\nint (*off_ok[])() {"); + i = 0; + for (r=0;r= 0) + while (sp <= ot) prdt[pc] =| getrc (*sp++); + } + +/********************************************************************** + + ACONF - define a conflicting pair of registers + + n1 - name of one register + n2 - name of the other register + +**********************************************************************/ + +aconf (n1, n2) int n1, n2; + + {int r1, r2; + + r1 = find_reg (n1); + r2 = find_reg (n2); + if (r1>=0 && r2>=0 && r1!=r2) + {cfp[r1] =| 1<= 0) + {copflag = l_register; + return (1 << j); + } + else if ((c = rc_find(n)) >= 0) + {copflag = l_register; + return (rcp[c]); + } + else if (copflag == l_register) + {error (2027, lineno, TIDN, n); + return (0); + } + } + if ((j = find_mem (n)) >= 0) + {copflag = l_memory; + return (1 << j); + } + return (0); + } + +/********************************************************************** + + ACLOBBER - determine the clobber field + +**********************************************************************/ + +aclobber (sp) int *sp; + + {int *ot, i; + + ot = get_top (sp); + i = 0; + while (sp<=ot) i =| getrc (*sp++); + return (i); + } + +/********************************************************************** + + FOPLOC - finished with OPLOCs + +**********************************************************************/ + +foploc() + + {int i; + + gprint ("\t0};\n"); + + /* set predefined values of OPREG and OPMEM */ + + i = trdt[1]; + opreg[e_not] = opreg[e_and] = opreg[e_or] = opreg[e_qmark] = i; + opmem[e_not] = opmem[e_and] = opmem[e_or] = opmem[e_qmark] = 0; + opreg[e_int] = opreg[e_float] = opreg[e_string] = 0; + opmem[e_int] = 1 << c_integer; + opmem[e_float] = 1 << c_float; + opmem[e_string] = 1 << c_string; + outarray ("rtopp",amopp,namop); + outarray ("rtopl",amopl,c_amopl); + outarray ("opreg",opreg,namop); + outarray ("opmem",opmem,namop); + } + +/********************************************************************** + + MPUSH - push an integer onto DEFLIST + +**********************************************************************/ + +int mpush (a1) + + {int j; + + mdeflist[j = cmdf++] = a1; + if (cmdf>=mdfsz) error(4002,lineno); + return (j); + } + +/********************************************************************** + + MPSH2 - push two integers onto DEFLIST + +**********************************************************************/ + +int mpsh2 (a1, a2) + + {int j; + + j = mpush (a1); + mpush (a2); + return (j); + } + +/********************************************************************** + + FMACRO - finished with MACRO specifications + +**********************************************************************/ + +int col; + +fmacro() + + {int c, f, lc, *ip, *ep, flag; + char *p; + + outarray ("mactab",mactab,namop); + outint ("ntype",ntype); + outint ("nmem",nmem); + outint ("nac",nac); + outint ("npc",npc); + outint ("sv_area_sz",save_area_size); + outint ("nreg",nreg); + + /* gprint out MCSTORE */ + + lc=col=0; + flag=TRUE; + ip=mdeflist; + ep= &mdeflist[cmdf]; + + p = cstore; + gprint ("char mcstuff[] {\n"); + + while (TRUE) + {c = *p++; + if (p >= cscsp) break; + if (flag) while (ip < ep) if (*++ip == -3) + {*ip = lc; + flag = FALSE; + break; + } + +again: switch(c) { + +case '\\': switch (c = *p++) { + + case 't': mputc ('\t'); ++lc; continue; + case 'n': mputc ('\n'); ++lc; continue; + case '#': mputs ("\\#"); lc=+2; continue; + case '\\': mputs ("\\\\"); lc=+2; continue; + case '\n': continue; + } + + mputc ('\\'); + ++lc; + goto again; + +case 0: flag=TRUE; + mputc (0); + ++lc; + continue; + +case '\"': mputc ('\"'); + ++lc; + continue; + +case '\t': mputc ('\t'); + ++lc; + continue; + +case '\n': mputc ('\n'); + ++lc; + continue; + +case '#': c = *p++; + if (c == '\'') + {switch (c = *p++) { + case 'F': + mputs("#3,#4"); + lc =+ 5; + break; + case 'S': + mputs("#5,#6"); + lc =+ 5; + break; + case 'R': + mputs("#1,#2"); + lc =+ 5; + break; + case 'O': + mputs("#0"); + lc =+ 2; + } + continue; + } + mputc ('#'); + mputc (c); + lc =+ 2; + continue; + +default: mputc (c & 0177); + ++lc; + } + } + + gprint ("};\n"); + gprint ("char *mcstore {mcstuff};\n"); + outarray ("macdef",macdef,cmacro); + gprint ("char *nmacname[] {\n"); + for (f=0;f= 12) + {cputc ('\n', f_out); + col=0; + } + else cputc (' ', f_out); + } + +/********************************************************************** + + OUTINT - write out an integer in C definition format + +**********************************************************************/ + +outint (n,i) char n[]; int i; + + {gprint ("int %s { %d };\n", n, i); + } + +/********************************************************************** + + OUTARRAY - write out integer array in C definition format + +**********************************************************************/ + +outarray (n,v,s) char n[]; int v[],s; + + {int i; + + gprint ("int %s[%d] {\n",n,s); + for(i=0;i= maxnmacs) error(4006,lineno); + nmacname[nnmacs] = idn; + nmacdef[nnmacs] = def; + ++nnmacs; + } + +/********************************************************************** + + XOPEN - Open File with Error Detection + + open file given + + file - name of file + mode - mode of file + opt - string of system-dependent options + + If unable to open print a message and exit. + Otherwise, return the file number. + +**********************************************************************/ + +xopen (file, mode, opt) char *file, *opt; int mode; + + {int i; + + i = copen (file, mode, opt); + if (i == OPENLOSS) + {cprint ("Unable to open '%s'.\n", file); + cexit (100); + } + return (i); + } + + \ No newline at end of file diff --git a/src/c/g4.c b/src/c/g4.c new file mode 100644 index 00000000..69f8eb8f --- /dev/null +++ b/src/c/g4.c @@ -0,0 +1,308 @@ +# include "gt.h" + +/* + + GT Compiler + Section 4: Parsing Tables + +*/ + +extern int copflag, amopl[], c_amopl, coplist; +extern int mactab[], macdef[], cmacro, lineno; + +extern int val, line, *pv, *pl; + +ar3 () + {fs1();} + +ar4 () + {fs2();} + +ar21 () + {error(4025,lineno);} + +ar22 () + {ftype();} + +ar23 () + {error(4022,lineno);} + +ar24 () + {foploc();} + +ar25 () + {error(4023,lineno);} + +ar26 () + {fmacro();} + +ar27 () + {error(4024,lineno);} + +ar56 () + {amopl[c_amopl++]= -1;coplist=0;} + +ar57 () + {asave(pv[2]);} + +ar58 () + {asize(pv[1],pv[3]);} + +ar59 () + {aalign(pv[1],pv[3]);} + +ar60 () + {apoint(pv[1],pv[3]);} + +ar61 () + {aclass(pv[1],pv[3]);} + +ar62 () + {aretreg(pv[1],pv[3]);} + +ar63 () + {atype(pv[1],pv[3]);} + +ar64 () + {aconf(pv[2],pv[4]);} + +ar65 () + {push(pv[3]);} + +ar66 () + {val=push(pv[1]);} + +ar67 () + {push(pv[3]);} + +ar68 () + {val=push(pv[1]);} + +ar69 () + {atnames(pv[3]);} + +ar70 () + {amnames(pv[3]);} + +ar71 () + {arnames(pv[3]);} + +ar72 () + {aor1(pv[1],pv[3],pv[5]);} + +ar73 () + {aor2(pv[1],pv[3]);} + +ar74 () + {aor3(pv[1],pv[4]);} + +ar75 () + {aor4(pv[1]);} + +ar78 () + {aoploc(pv[6]);} + +ar79 () + {aamop(pv[1]);} + +ar80 () + {aamop(pv[1]);} + +ar81 () + {aopl(0,copflag,pv[1]);} + +ar82 () + {aopl(1,copflag,pv[1]);} + +ar83 () + {aopl(1,0,0);} + +ar84 () + {aopl(2,copflag,pv[1]);} + +ar86 () + {copflag=pv[1]+2;val=0;} + +ar87 () + {val=pv[1] | pv[3];} + +ar88 () + {val= ~pv[2];} + +ar89 () + {val=pv[2];} + +ar90 () + {val=aope(-1);} + +ar91 () + {val=aope(-2);} + +ar92 () + {val=aope(pv[1]);} + +ar93 () + {val=aclobber(pv[2]);} + +ar94 () + {val=0;} + +ar95 () + {macdef[cmacro++]=pv[2];mpush(-1);} + +ar100 () + {mpush(-3);val=pv[2];} + +ar101 () + {val=mpsh2(3,-3);} + +ar102 () + {val=mpsh2(copflag,pv[1]);copflag=0;} + +ar103 () + {val=mpsh2(0,0);} + +ar104 () + {mactab[pv[1]]=cmacro;} + +ar105 () + {nmac(pv[1],cmacro);} + +ar106 () + {push(pv[3]);} + +ar107 () + {val=push(pv[1]);} + +int (*act[])() { + 0, 0, 0, ar3, ar4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, ar21, ar22, ar23, ar24, ar25, ar26, ar27, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, ar56, ar57, ar58, ar59, ar60, ar61, + ar62, ar63, ar64, ar65, ar66, ar67, ar68, ar69, ar70, ar71, + ar72, ar73, ar74, ar75, 0, 0, ar78, ar79, ar80, ar81, ar82, + ar83, ar84, 0, ar86, ar87, ar88, ar89, ar90, ar91, ar92, + ar93, ar94, ar95, 0, 0, 0, 0, ar100, ar101, ar102, ar103, + ar104, ar105, ar106, ar107, -1}; + + + +int r1[] { + 0, 1, 2, 3, 4, 5, 5, 6, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 9, + 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, + 17, 17, 18, 19, 19, 20, 21, 21, 22, 23, 23, 24, 25, 25, + 26, 27, 27, 28, 29, 29, 30, 31, 31, 32, 33, 34, 35, 36, + 37, 38, 39, 40, 41, 41, 42, 42, 43, 44, 45, 46, 46, 46, + 46, 47, 47, 48, 49, 49, 50, 51, 51, 52, 53, 53, 54, 54, + 54, 54, 54, 54, 55, 55, 56, 57, 57, 58, 58, 59, 59, 60, + 60, 61, 61, 62, 62, -1}; + +int r2[] { + 0, 2, 8, 1, 1, 2, 0, 1, 1, 1, 2, 0, 1, 1, 1, 1, 1, 1, 1, + 0, 1, 0, 1, 0, 1, 0, 1, 0, 2, 1, 2, 1, 3, 3, 1, 3, 3, 1, + 3, 3, 1, 3, 3, 1, 3, 3, 1, 3, 3, 1, 3, 3, 1, 3, 3, 1, 2, + 3, 4, 4, 4, 4, 4, 4, 5, 3, 1, 3, 1, 5, 5, 5, 6, 5, 5, 4, + 2, 1, 7, 3, 2, 1, 1, 0, 1, 1, 1, 3, 2, 3, 1, 1, 1, 3, 0, + 2, 3, 2, 2, 1, 9, 1, 1, 0, 1, 1, 3, 1, -1}; + +int g[] { + 0, 0, 2, 0, 3, 0, 5, 0, 4, 0, 10, 0, 6, 0, 23, 0, 15, 0, + 37, 0, 66, 0, 98, 0, 152, 0, 99, 0, 153, 0, 24, 0, 52, + 0, 25, 0, 40, 0, 26, 0, 43, 0, 27, 0, 46, 0, 16, 0, 34, + 0, 38, 0, 63, 0, 67, 0, 95, 0, 28, 0, 49, 99, 126, 0, 100, + 0, 29, 82, 111, 0, 53, 70, 103, 0, 41, 73, 105, 0, 44, + 76, 107, 0, 47, 93, 120, 0, 64, 123, 148, 0, 96, 79, 109, + 0, 50, 0, 50, 31, 57, 32, 58, 68, 102, 74, 106, 80, 110, + 91, 119, 121, 147, 185, 188, 0, 56, 0, 11, 0, 12, 0, 13, + 61, 90, 0, 35, 0, 133, 133, 159, 0, 134, 124, 149, 0, 101, + 0, 135, 0, 173, 0, 182, 160, 174, 180, 183, 0, 136, 127, + 157, 128, 158, 161, 175, 166, 176, 181, 176, 187, 176, + 0, 137, 0, 186, 153, 165, 0, 154, 0, 155, 0, 168, 168, + 178, 0, 169, 181, 184, 187, 190, 0, 177, 155, 170, 0, 156, + 0, 156, -1}; + +int pg[] { + 0, 0, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, + 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, + 57, 59, 61, 65, 67, 71, 75, 79, 83, 87, 91, 95, 97, 115, + 117, 119, 121, 125, 127, 131, 135, 137, 139, 141, 147, + 161, 163, 167, 169, 171, 175, 181, 185, -1}; + +int nbpw {16}; + +int nwpbt {2}; + +int a[] { + 0, 0, 0, 60, 30, 85, 185, 191, 124, 61, 161, 128, 97, 7, + 17, 18, 19, 20, 65, 8, 125, 21, 129, 9, 36, 22, 14, 130, + 33, 39, 167, 12294, 4097, 16384, 0, 12299, 20481, 8192, + 136, 12291, 4122, 8206, 12307, 20481, 49152, 547, 12292, + 4100, 8222, 0, 4100, 8223, 0, 4100, 8224, 0, 12293, 12295, + 12297, 12296, 4124, 8225, 0, 4120, 8228, 12309, 12306, + 4125, 8231, 0, 4124, 8234, 0, 4124, 8237, 0, 4100, 8240, + 0, 4125, 8243, 0, 4125, 8246, 0, 12298, 12300, 12301, 12304, + 12302, 12303, 12305, 4124, 8247, 0, 4100, 8251, 0, 4099, + 8252, 4105, 8253, 0, 12334, 4124, 8254, 0, 4114, 8257, + 12311, 12308, 4100, 8260, 0, 4099, 8261, 4105, 8262, 0, + 12325, 4100, 8263, 0, 4099, 8264, 4105, 8265, 0, 12328, + 4100, 8266, 0, 4099, 8267, 4105, 8268, 0, 12331, 4124, + 8269, 0, 4099, 8270, 4105, 8271, 0, 12343, 4100, 8272, + 0, 4099, 8273, 4105, 8274, 0, 12322, 4099, 8275, 0, 12356, + 4101, 8277, 4105, 8276, 0, 4101, 8278, 4105, 8276, 0, 4101, + 8279, 4105, 8276, 0, 4105, 8281, 4125, 8280, 0, 12332, + 4124, 8225, 0, 4100, 8283, 0, 4099, 8284, 4105, 8285, 0, + 12337, 4124, 8286, 0, 4108, 8289, 12313, 12310, 12323, + 4125, 8231, 0, 4125, 8296, 0, 12326, 4124, 8234, 0, 12329, + 4124, 8237, 0, 4105, 8300, 0, 12341, 4100, 8240, 0, 12320, + 4125, 8243, 0, 12345, 4124, 8304, 0, 4099, 8305, 0, 4099, + 8306, 0, 4099, 8307, 0, 4105, 8308, 0, 4101, 8310, 4125, + 8309, 0, 12333, 12335, 4124, 8254, 0, 4100, 8313, 0, 4099, + 8314, 4105, 8315, 0, 12340, 4104, 8316, 0, 4116, 8317, + 0, 4108, 8289, 12312, 12317, 20481, 2048, 2112, 4100, 8319, + 4124, 8323, 4125, 8324, 0, 4101, 8330, 4105, 8276, 0, 12324, + 4101, 8331, 0, 12327, 4101, 8332, 4105, 8276, 0, 12330, + 4124, 8333, 0, 12342, 4101, 8334, 4105, 8276, 0, 12321, + 12355, 12357, 12358, 12359, 4101, 8336, 4125, 8335, 0, + 4101, 8337, 0, 12363, 4101, 8338, 4105, 8276, 0, 12336, + 12338, 4124, 8286, 0, 4108, 8289, 12368, 4108, 8342, 4124, + 8343, 12315, 12316, 20481, 2048, 2112, 4100, 8319, 4124, + 8323, 0, 12378, 12379, 12380, 12374, 20481, 2048, 2112, + 4100, 8319, 4124, 8323, 4125, 8324, 12344, 12365, 4105, + 8352, 0, 12369, 4106, 8353, 12373, 12347, 12348, 12349, + 4101, 8354, 0, 12346, 4101, 8355, 0, 12361, 12362, 12350, + 4101, 8356, 4105, 8276, 0, 12339, 12367, 12392, 12393, + 12290, 4108, 8342, 4124, 8343, 12314, 12319, 4100, 8358, + 4108, 8342, 4124, 8343, 4126, 8359, 0, 4104, 8363, 0, 4101, + 8364, 4106, 8353, 0, 12376, 12364, 20481, 2048, 2112, 4100, + 8319, 4124, 8323, 4125, 8324, 12371, 12352, 12360, 12351, + 12318, 20481, 2048, 2112, 4100, 8319, 4124, 8323, 12391, + 12389, 4100, 8358, 4126, 8359, 12383, 12387, 4104, 8371, + 0, 12385, 12377, 4105, 8372, 0, 12370, 12375, 4106, 8353, + 12390, 4105, 8373, 0, 12386, 12384, 20481, 2048, 2112, + 4100, 8319, 4124, 8323, 4125, 8324, 0, 20481, 2048, 2112, + 4100, 8319, 4124, 8323, 12391, 4102, 8377, 12382, 12372, + 4105, 8379, 0, 4099, 8381, 0, 20481, 2048, 2112, 4100, + 8319, 4124, 8323, 12391, 4103, 8383, 4105, 8276, 0, 12366, + 4101, 8384, 0, 12381, 4104, 8385, 0, 4126, 8386, 0, 12388, + -1}; + +int pa[] { + 0, 31, 32, 35, 36, 40, 43, 47, 50, 53, 56, 57, 58, 59, + 60, 63, 66, 67, 70, 73, 76, 79, 82, 85, 86, 87, 88, 89, + 90, 91, 92, 92, 92, 95, 98, 103, 104, 107, 110, 111, 114, + 119, 120, 123, 128, 129, 132, 137, 138, 141, 146, 147, + 150, 155, 156, 159, 160, 165, 170, 175, 180, 181, 184, + 187, 192, 193, 196, 199, 92, 200, 201, 204, 207, 208, 92, + 211, 212, 215, 218, 219, 92, 222, 223, 226, 227, 230, 233, + 236, 239, 242, 247, 92, 248, 249, 252, 255, 260, 261, 264, + 267, 270, 271, 281, 286, 287, 290, 291, 296, 297, 300, + 301, 306, 307, 308, 309, 310, 311, 316, 319, 320, 325, + 92, 326, 327, 330, 333, 338, 339, 339, 347, 348, 349, 350, + 351, 361, 362, 365, 366, 369, 370, 371, 372, 375, 376, + 379, 380, 381, 382, 387, 388, 389, 390, 391, 392, 397, + 398, 407, 410, 415, 416, 417, 339, 427, 428, 429, 430, + 431, 439, 440, 445, 446, 449, 450, 451, 454, 455, 456, + 459, 462, 463, 464, 474, 482, 485, 486, 92, 489, 492, 500, + 505, 506, 509, 510, 513, 516, -1}; + + \ No newline at end of file diff --git a/src/c/g5.c b/src/c/g5.c new file mode 100644 index 00000000..14b84b4b --- /dev/null +++ b/src/c/g5.c @@ -0,0 +1,276 @@ +# include "gt.h" + +/* + + GT Compiler + Section 5: Error Message Editor + +*/ + +/********************************************************************** + + global variables + + sterm table of GT terminal symbols + snterm table of GT nonterminal symbols + sq table of states + +**********************************************************************/ + +extern char cstore[], *eopch[]; + +char *sterm[] { + "", "-|", "error", ";", "(", ")", "[", "]", ":", ",", "|", + "~", "amop", "TYPENAMES", "ALIGN", "POINTER", "CLASS", + "CONFLICT", "TYPE", "MEMNAMES", "MACROS", "SIZE", "INDIRECT", + "REGNAMES", "RETURNREG", "SAVEAREASIZE", "OFFSETRANGE", + "M", "idn", "integer", "string", 0}; + +char *snterm[] { + "", "$accept", "program", "$s1", "$s2", "$s1.list", "s1", + "$s2.list", "s2", "$or", "$r", "$t", "$o", "$m", "$o.list", + "$m.list", "$size", "s.list", "$align", "a.list", "$pointer", + "p.list", "$class", "c.list", "$offsetrange", "or.list", + "$returnreg", "r.list", "$type", "t.list", "$conflict", + "x.list", "$oploc", "$saveareasize", "s.elem", "a.elem", + "p.elem", "c.elem", "r.elem", "t.elem", "x.elem", "int_list", + "idn_list", "$typenames", "$memnames", "$regnames", "or.elem", + "oploc_list", "oploc", "oplist", "op1", "op2", "op3", "opl", + "ope", "clobber", "macro", "name_list", "cstring_list", + "cstring", "ope2", "name", "amop_list", 0}; + +int sq[] { + 0, 0, 4098, 4099, 4101, 4100, 4103, 13, 19, 23, 4102, 4139, + 4140, 4141, 26, 4105, 4120, 14, 15, 16, 17, 21, 25, 4104, + 4112, 4114, 4116, 4118, 4126, 4129, 4, 4, 4, 28, 4121, + 4142, 24, 4106, 4122, 29, 4115, 4131, 28, 4117, 4132, 28, + 4119, 4133, 4, 4127, 4136, 29, 4113, 4130, 29, 28, 4138, + 4138, 4138, 4, 3, 9, 28, 4123, 4134, 18, 4107, 4124, 4, + 3, 9, 4, 3, 9, 4, 3, 9, 28, 3, 9, 4, 3, 9, 3, 9, 5, 5, + 5, 29, 9, 4142, 4, 3, 9, 28, 4125, 4135, 12, 4108, 4110, + 4128, 4145, 4138, 4131, 29, 4132, 4138, 4133, 9, 4136, + 4138, 4130, 28, 3, 3, 3, 9, 29, 5, 4138, 4134, 4, 3, 9, + 8, 20, 4128, 4, 11, 22, 27, 28, 29, 4143, 4144, 4146, 4149, + 4150, 5, 5, 5, 28, 5, 29, 5, 5, 5, 4138, 4135, 4145, 12, + 28, 4109, 4111, 4152, 4153, 4157, 4150, 4150, 4144, 9, + 10, 5, 5, 5, 4152, 4, 30, 4154, 4155, 4157, 8, 5, 4147, + 4149, 4150, 4150, 4156, 4155, 8, 9, 9, 4148, 4149, 4156, + 6, 4151, 9, 4138, 3, 4156, 7, 5, 8, 30, -1}; + +/********************************************************************** + + ERROR MESSAGES + +**********************************************************************/ + +char *m1000[] { +/* 1000 */ "INVALID CHARACTER", +/* 1001 */ "INVALID ESCAPE CHARACTER", +/* 1002 */ "UNRECOGNIZED ABSTRACT MACHINE OPERATOR", +/* 1003 */ "INVALID MANIFEST CONSTANT DEFINITION", +/* 1004 */ "INVALID COMPILER CONTROL LINE", +/* 1005 */ "INVALID ESCAPE CONTROL LINE" + }; + +char *m2000[] { +/* 2000 */ 0, +/* 2001 */ "UNTERMINATED STRING CONSTANT", +/* 2002 */ "MULTIPLE TYPENAMES STATEMENTS IGNORED", +/* 2003 */ "MULTIPLE REGNAMES STATEMENTS IGNORED", +/* 2004 */ "MULTIPLE MEMNAMES STATEMENTS IGNORED", +/* 2005 */ "RETURN REGISTER FOR %t REDEFINED", +/* 2006 */ "%q DELETED", +/* 2007 */ "SYNTAX ERROR. PARSE SO FAR: ", +/* 2008 */ " %q", +/* 2009 */ "ALIGNMENT FACTORS MUST INCREASE", +/* 2010 */ " _ ", +/* 2011 */ " %t", +/* 2012 */ "DELETED: ", +/* 2013 */ "SKIPPED: ", +/* 2014 */ "MISSING SAVEAREASIZE STATEMENT", +/* 2015 */ "SIZE OF %t REDECLARED", +/* 2016 */ "SIZE OF %t NOT SPECIFIED", +/* 2017 */ "MACRO %t REDEFINED", +/* 2018 */ "ATTEMPT TO MIX REGISTER AND MEMORY IN LOCATION EXPRESSION", +/* 2019 */ 0, +/* 2020 */ "ALIGNMENT OF TYPE %t REDECLARED", +/* 2021 */ "INVALID ALIGMENT CLASS %d", +/* 2022 */ "NO POINTER CLASS CAN RESOLVE TYPE %t", +/* 2023 */ "ALIGNMENT CLASS FOR %t NOT SPECIFIED", +/* 2024 */ "SMALLEST ALIGNMENT FACTOR MUST BE 1", +/* 2025 */ 0, +/* 2026 */ "UNDEFINED POINTER CLASS %t", +/* 2027 */ "UNDEFINED REGISTER %t", +/* 2028 */ "UNDEFINED DATA TYPE %t", +/* 2029 */ "UNDEFINED MEMORY REFERENCE TYPE %t" + }; + +char *m4000[] { +/* 4000 */ "NAME TABLE OVERFLOW", +/* 4001 */ "NAME TABLE OVERFLOW", +/* 4002 */ "MACRO DEFINITION OVERFLOW", +/* 4003 */ "PROGRAM TOO COMPLICATED. PARSER STACK OVERFLOW.", +/* 4004 */ "MANIFEST CONSTANT DEFINITION TABLE OVERFLOW", +/* 4005 */ "PROGRAM TOO LARGE: SYMBOL TABLE OVERFLOW", +/* 4006 */ "TOO MANY NAMED MACROS", +/* 4007 */ 0, +/* 4008 */ 0, +/* 4009 */ 0, +/* 4010 */ 0, +/* 4011 */ 0, +/* 4012 */ "I GIVE UP", +/* 4013 */ "TYPENAMES STATEMENT MISSING", +/* 4014 */ "REGNAMES STATEMENT MISSING", +/* 4015 */ "MEMNAMES STATEMENT MISSING", +/* 4016 */ "TOO MANY POINTER CLASSES", +/* 4017 */ "TOO MANY REGISTERS", +/* 4018 */ "TOO MANY REGISTER CLASSES", +/* 4019 */ "TOO MANY DATA TYPES", +/* 4020 */ "TOO MANY MEMORY REFERENCE TYPES", +/* 4021 */ "POINTER STATEMENT MISSING", +/* 4022 */ "TYPE STATEMENT MISSING", +/* 4023 */ "OPLOC STATEMENTS MISSING", +/* 4024 */ "MACROS MISSING", +/* 4025 */ "RETURNREG STATEMENT MISSING" + }; + +char *m6000[] { +/* 6000 */ "T(P): ATTEMPT TO REFERENCE TOKEN %d", +/* 6001 */ "POP(P): STACK ERROR", +/* 6002 */ "LEX(P): TOKEN BUFFER OVERFLOW", +/* 6003 */ "SETSP(P): STACK POINTER TOO SMALL", +/* 6004 */ "SETSP(P): STACK POINTER TOO LARGE", +/* 6005 */ "LEX(P): INCONSISTENT TOKEN POINTERS", +/* 6006 */ "PARSE(P): ATTEMPT TO POP EMPTY PARSER STACK" + }; + +/********************************************************************** + + DTOKEN - Print Token + +**********************************************************************/ + +dtoken (type, index) + + {extern int cout; + ptoken (&type, cout); + } + +/********************************************************************** + + EPRINT - Error Editor Formatted Print Routine + +**********************************************************************/ + +eprint (fmt, x1, x2) char *fmt; + + {int *argp, x, c; + char *s; + + argp = &x1; /* argument pointer */ + while (c = *fmt++) + {if (c != '%') eputc (c); + else + {x = *argp++; + switch (c = *fmt++) { + +case 'd': /* decimal */ if (x<0) {x = -x; eputc ('-');} + eprd (x); + break; +case 'q': /* parser state */ + x = sq[x]; + if (x<0) break; + if (x<010000) eprint ("%s", sterm[x]); + else eprint ("<%s>", snterm[x-010000]); + break; +case 's': /* string */ s = x; + while (c = *s++) eputc (c); + break; +case 't': /* token */ dtoken (x, *argp++); + break; +default: eputc (c); + --argp; + } + } + } + } + +/********************************************************************** + + EPRD - Print Positive Decimal Integer + +**********************************************************************/ + +eprd (n) + + {int a; + if (a=n/10) eprd (a); + eputc (n%10+'0'); + } + +/********************************************************************** + + EPUTC - Write a character onto standard output unit. + + Break lines which exceed 60 characters. + +**********************************************************************/ + +eputc (c) + + {static int column; + extern int cout; + + if (column >= 59 && c == ' ') c = '\n'; + else if (column >= 80 && c != '\n') + {cputc ('\n', cout); column = 0; + } + cputc (c, cout); + if (c=='\n') column=0; else ++column; + } + +/********************************************************************** + + ERROR - Print Error Message + +**********************************************************************/ + +error (errno, lineno, p1, p2) + + {char *f, *getfmt(); + + if (lineno>0) eprint ("\n%d: ", lineno); + if (errno>=6000) eprint ("COMPILER ERROR. "); + + if (errno < 2000) + f = getfmt (errno-1000, m1000, sizeof m1000); + else if (errno < 4000) + f = getfmt (errno-2000, m2000, sizeof m2000); + else if (errno < 6000) + f = getfmt (errno-4000, m4000, sizeof m4000); + else f = getfmt (errno-6000, m6000, sizeof m6000); + + if (f==0) {f = "ERROR %d"; p1=errno;} + eprint (f, p1, p2); + if (errno>=4000) cleanup (1); + } + +/********************************************************************** + + GETFMT - get format given + N - relative error number + T - error message table + Z - size of error message table + +**********************************************************************/ + +char *getfmt (n, t, z) + char *t[]; + + {int nm; + + nm = z / sizeof t[0]; + if (n < 0 || n >= nm) return (0); + return (t[n]); + } + \ No newline at end of file diff --git a/src/c/gt.h b/src/c/gt.h new file mode 100644 index 00000000..e55b2799 --- /dev/null +++ b/src/c/gt.h @@ -0,0 +1,152 @@ +/* dependencies upon host machine !! */ + +# define WORDMASK 077777777777 /* mask all but high 3 bits */ +# define SMALLEST "-34359738368" /* smallest negative number */ + +/* table sizes */ + +# define hshsize 200 /* size of hash table for identifiers */ +# define cssiz 5000 /* size of character store */ +# define pssize 100 /* size of action routine stack */ +# define mcdsz 200 /* manifest constant definition table size */ +# define eopchsz 0300 + +/* various values */ + +# define MREAD 'r' /* read mode */ +# define MWRITE 'w' /* write mode */ +# define MAPPEND 'a' /* append mode */ +# define TEXT "t" /* text file */ +# define BINARY "b" /* binary file */ + +# define TRUE 1 +# define FALSE 0 +# define NULL 0 +# define UNDEF -1 +# define OPENLOSS -1 + +/* token types */ + +# define LEXEOF 0 /* internal end of file indicator */ +# define TEOF 1 /* end of file */ +# define _SEMI 3 +# define _LPARN 4 +# define _RPARN 5 +# define _LBRAK 6 +# define _RBRAK 7 +# define _COLON 8 +# define _COMMA 9 +# define _OR 10 +# define _NOT 11 +# define T_AMOP 12 /* abstract machine operator */ +# define _TYPENAMES 13 +# define _ALIGN 14 +# define _POINTER 15 +# define _CLASS 16 +# define _CONFLICT 17 +# define _TYPE 18 +# define _MEMNAMES 19 +# define _MACROS 20 +# define _SIZE 21 +# define _INDIRECT 22 +# define _REGNAMES 23 +# define _RETURNREG 24 +# define _SAVEAREASIZE 25 +# define _OFFSETRANGE 26 +# define _M 27 +# define TIDN 28 /* identifiers */ +# define TINTCON 29 /* integer constants */ +# define TSTRING 30 /* string constants */ + +/* location expression modes */ + +# define l_unknown 0 +# define l_register 1 +# define l_memory 2 + +/* basic data types */ + +# define tchar 0 /* character */ +# define tint 1 /* integer */ +# define tfloat 2 /* float */ +# define tdouble 3 /* double */ + +/* storage classes */ + +# define c_register 0 /* register */ +# define c_temp 1 /* temporary */ +# define c_auto 1 /* automatic */ +# define c_extdef 2 /* external definition */ +# define c_static 3 /* static */ +# define c_param 4 /* parameter */ +# define c_label 5 /* label */ +# define c_integer 6 /* integer literal */ +# define c_float 7 /* floating-point literal */ +# define c_string 8 /* string literal */ +# define c_indirect 9 /* indirection through reg #0 ... */ +# define c_extern 50 /* external */ +# define c_struct 51 /* structure type */ +# define c_mos 52 /* member of structure */ +# define c_dummy 53 /* dummy structure def - + for recursive definitions */ + +/* enodes */ + +# define e_iminus 0000 +# define e_dminus 0001 +# define e_incbi 0002 +# define e_bnot 0006 +# define e_not 0007 +# define e_sw 0012 +# define e_incbc 0013 +# define e_a0 0017 +# define e_a3 0022 +# define e_ind 0023 +# define e_jz0 0024 +# define e_jz3 0027 +# define e_jn0 0030 +# define e_jn3 0033 +# define e_addi 0100 +# define e_eaddi 0101 +# define e_subi 0104 +# define e_esubi 0105 +# define e_muli 0110 +# define e_divi 0114 +# define e_mod 0120 +# define e_ls 0122 +# define e_els 0123 +# define e_rs 0124 +# define e_ers 0125 +# define e_band 0126 +# define e_eand 0127 +# define e_xor 0130 +# define e_exor 0131 +# define e_bor 0132 +# define e_eor 0133 +# define e_and 0134 +# define e_or 0135 +# define e_p0sub 0136 +# define e_assign 0137 +# define e_add0 0146 +# define e_add3 0151 +# define e_sub0 0152 +# define e_sub3 0155 +# define e_movec 0160 +# define e_idn 0177 +# define e_int 0176 +# define e_string 0175 +# define e_float 0174 +# define e_call 0173 +# define e_colon 0172 +# define e_qmark 0171 +# define e_eqi 0200 +# define e_eqd 0206 +# define e_eqp0 0214 +# define e_gep3 0243 +# define e_incb0 0260 + +/* STRUCTURES */ + +struct _token {int type,index,line;}; +# define token struct _token + \ No newline at end of file diff --git a/src/c/gt.stinkr b/src/c/gt.stinkr new file mode 100644 index 0000000000000000000000000000000000000000..44d156989969baa64a0f8aabfbc486a1f30dff8a GIT binary patch literal 75 zcmb LORY%dVgLdFHg*%n literal 0 HcmV?d00001 diff --git a/src/c/h6000.gt b/src/c/h6000.gt new file mode 100644 index 00000000..c49f1385 --- /dev/null +++ b/src/c/h6000.gt @@ -0,0 +1,282 @@ +typenames (char,int,float,double); +memnames (reg,auto,ext,stat,param,label,intlit,floatlit,string, + ix0,ix1,ix2,ix3,ix4,ia,iq); +regnames (x0,x1,x2,x3,x4,a,q,f); +size 1(char),4(int,float),8(double); +align 1(char),4(int,float),8(double); +class x(x0,x1,x2,x3,x4), r(a,q); +conflict (a,f),(q,f); +saveareasize 16; +pointer p0(1), p1(4); +offsetrange p1 (,); +returnreg q(char,int,p0,p1), f(double); +type int(r), char(r), float(f), double(f), p0(r), p1(x); + +.sw: a,,1[x4]; ++p0: -p0: +i:-i:&:^: .OR: -p0p0:<<: >>: r,M,1; ++p1: M,M,x; x,r,1; x,intlit,1; +-p1: x,r,1; x,intlit,1; +=+i: =&: =^: =OR: M,r,1; +*i: /i: q,M,q[a]; ++d: -d: *d: /d: f,M,f; +%: q,M,a[q]; +=<<: =>>: M,a,q; M,q,a; +&u0: auto|ext|stat|string|ia|iq,,r; +&u1: M,,x; +.BNOT: .ic: .ci: r,,1; +-ui: M,,r; +.cf: .cd: .if: .id: a,,f; +.fc: .dc: .fi: .di: f,,q; +.fd: M,,f; +.df: -ud: f,,1; +.ip0: .p0i: r,,1; M,,r; +.ip1: .p0p1: r,,x; M,,x; +.p1i: .p1p0: x,,r; M,,r; +++bi: M,,1; +++ai: M,,a[q]; + M,,q[a]; +++ap1: --ap1: M,M,x; +==i: !=i: i: <=i: >=i: +==p0: !=p0: p0: <=p0: >=p0: r,M,M; +==d: !=d: d: <=d: >=d: f,M,M; +==p1: !=p1: p1: <=p1: >=p1: x,M,M; + +macros + ++i: " AD#R #S" +-i: " SB#R #S" +*i: " MPY #S" +/i: %: " DIV #S" ++d: " DFAD #S" +-d: " DFSB #S" +*d: " DFMP #S" +/d: " DFDV #S" +=+i: " AS#S #R" +&: " AN#F #S" +=&: " ANS#S #F" +^: " ER#F #S" +=^: " ERS#S #F" +.OR: " OR#F #S" +=OR: " ORS#S #F" + +>>: +(,intlit,): " #FRS %o(#'S)" +(,~intlit,): " LXL5 #S\n #FRS 0,5" + +<<: +(,intlit,): " #FLS %o(#'S)" +(,~intlit,): " LXL5 #S\n #FLS 0,5" + +=>>: +" LD#R #F + #RRS 0,#SL + ST#R #F" + +=<<: +" LD#R #F + #RLS 0,#SL + ST#R #F" + ++p0: +(,~intlit,): " #FRS 16\n AD#F #S\n #FLS 16" +(,intlit,): " ADL#R %co(#'S)" + +-p0: +(,~intlit,): " #FRS 16\n SB#F #S\n #FLS 16" +(,intlit,): " SBL#R %co(#'S)" + ++p1: +(M,M,): " LXL#R #S\n ADLX#R #F" +(x,r,): " #SLS 18\n ST#S .TEMP\n ADX#F .TEMP" +(x,intlit,): " EAX#R %o(#'S),#R" + +-p1: +(,r,): " #SLS 18\n ST#S .TEMP\n SBX#F .TEMP" +(,intlit,): " EAX#R -%o(#'S),#R" + +-ui: " LC#R #F" +-ud: " FNEG" +++bi: " AOS #F" +++ai: " LD#R #F\n AOS #F" + +++ap1: +" LDX#R #F + EAX5 %o(#'S),#1 + STX5 #F" + +--ap1: +" LDX#R #F + EAX5 -%o(#'S),#1 + STX5 #F" + +.BNOT: " ER#F =-1" +&u0: +(ia|iq,,r): +"%if(%o(#'F), AD#F %co(#'F)\n,)\" +(ia,,q): " LLR 36" +(iq,,a): " LLR 36" +(auto|stat,,r): +" EA#R %n(#3,0) +%if(%o(#'F), AD#R %co(#'F)\n,)\" +(ext|string,,r): +" EA#R #F" + +&u1: " EAX#R #F" + +==i: " CMP#F #S\n TZE #R" +!=i: " CMP#F #S\n TNZ #R" +i: " CMP#F #S\n TZE *+2\n TPL #R" +<=i: " CMP#F #S\n TZE #R\n TMI #R" +>=i: " CMP#F #S\n TPL #R" + +==d: " DFCMP #S\n TZE #R" +!=d: " DFCMP #S\n TNZ #R" +d: " DFCMP #S\n TZE *+2\n TPL #R" +<=d: " DFCMP #S\n TZE #R\n TMI #R" +>=d: " DFCMP #S\n TPL #R" + +==p0: " CMP#F #S\n TZE #R" +!=p0: " CMP#F #S\n TNZ #R" +p0: " CMP#F #S\n TZE *+2\n TRC #R" +<=p0: " CMP#F #S\n TZE #R\n TNC #R" +>=p0: " CMP#F #S\n TRC #R" + +==p1: " CMPX#F #S\n TZE #R" +!=p1: " CMPX#F #S\n TNZ #R" +p1: " CMPX#F #S\n TZE *+2\n TRC #R" +<=p1: " CMPX#F #S\n TZE #R\n TNC #R" +>=p1: " CMPX#F #S\n TRC #R" + +-p0p0: " SBL#F #S\n #FRL 16" + +.cc: +(auto,,): " EA#R 0,7\n" +(stat,,): " EA#R .STAT\n" +(ia,,q): " STA .TEMP\n LDQ .TEMP\n" +(iq,,a): " STQ .TEMP\n LDA .TEMP\n" +(auto|stat|indirect,,): +"%if(%o(#'F), AD#R %co(#'F)\n,)\ + TSX5 .CTO#R" +(ext|string,,): " LD#R #F\n #RRL 27" +(r,,r): " EA#R 0,#FL\n #RRL 18" +(r,,auto|stat|indirect|string): + " EAX5 0,#FL\n" +(r,,auto): " EA#F 0,7\n" +(r,,stat): " EA#F .STAT\n" +(r,,auto|stat): +"%if(%o(#'R), AD#F %co(#'R)\n,)\ + TSX4 .#FTOC" +(r,,string): " EA#F #R\n TSX4 .#FTOC" +(r,,ext): " #FLS 27\n ST#F #R\n #FRL 27" +(q,,ia): +"%if(%o(#'R), ADA %co(#'R)\n,)\ + TSX4 .ATOC" +(a,,iq): +"%if(%o(#'R), ADQ %co(#'R)\n,)\ + TSX4 .QTOC" +.ii: +(r,,M): " ST#F #R" +(M,,r): " LD#R #F" +(r,,r): " LLR 36" +.ff: +(f,,M): " FSTR #R" +(M,,f): " FLD #F" +.dd: +(f,,M): " DPSTR #R" +(M,,f): " DPLD #F" +.p0p0: +(r,,r): " LLR 36" +(r,,M): " ST#F #R" +(M,,r): " LD#R #F" +.p1p1: +(x,,x): " EAX#R 0,#F" +(x,,M): " STZ #R\n STX#F #R" +(M,,x): " LDX#R #F" +(x,,q): " EAQ 0,#F" +(q,,x): " EAX#R 0,QU" +(M,,q): " LDQ #F" +(q,,M): " STQ #R" + +.ci: "\" +.ic: " AN#F =O377,DL" + +.p0p1: .ip1: +(r,,x): " EAX#R 0,#FU" +(M,,x): " LDX#R #F" + +.p1p0: .p1i: +(x,,r): " EA#R 0,#F" +(M,,r): " LD#R #F" + +.ip0: .p0i: +(M,,r): " LD#R #F" +(r,,r): "\" + +.fd: " FLD #F" +.df: " FRD" + +.cf: .cd: .if: .id: +" LDQ 0,DL + LDE =35B25,DU + FNO" + +.fi: .di: " UFA =71B25,DU" +.fc: .dc: +" UFA =71B25,DU + ANQ =O377,DL" + +hd: +"$ GMAP + SYMREF .PROLG,.EPILG,.TEMP,.LSIWT,.TSWIT + SYMREF .CTOA,.CTOQ,.ATOC,.QTOC" + +en: " SYMDEF #0" +ex: " SYMREF #0" +st: ".I#0 EQU *" +rt: " TRA .EPILG" +go: " TRA #R" +l: ".L#0 EQU *" +lc: " ZERO .L#0" + +p: +"* +* FUNCTION %m(#1) +* +%i(#1) TSX0 .PROLG + ZERO .FS#0" +ca: +" TSX1 #F + ZERO #1/4,#0" +ep: +" TRA .EPILG +.FS#0 EQU #1/4" + +ls: +" TSX5 .LSWIT + ZERO #R,#0" +ts: +" TSX5 .TSWIT + ZERO #0,#5 + TRA #R" + +o: "#1" +co: "=V20/#1,16/0" + +ln: "%flush().N#0 EQU *" +eq: "%flush()#0 EQU *" +in: "%flush() DEC #0" +ad0: ad1: "%flush() ZERO #R" +sc: "%flush() ZERO .S#0" +end: "%flush() END" +f: "%flush() DEC %ff(#0)" +nf: "%flush() DEC -%ff(#0)" +d: "%flush() DEC %dd(#0)" +nd: "%flush() DEC -%dd(#0)" +al1: "%flush()\" +al2: "%flush() EVEN" +im: da: pu: pd: "\" + \ No newline at end of file diff --git a/src/c/pdp10.gt b/src/c/pdp10.gt new file mode 100644 index 00000000..e16c25af --- /dev/null +++ b/src/c/pdp10.gt @@ -0,0 +1,234 @@ +typenames (char, int, float, double); +regnames (a, c, d, b); +memnames (reg, auto, ext, stat, param, label, intlit, floatlit, + stringlit, ia, ic, id, ib); +size 1 (char, int, float, double); +align 1(char, int, float, double); +class r (a, b, c, d); +saveareasize 1; +pointer p0 (1); +offsetrange p0 (,); +returnreg a (int, double, p0); +type char(r), int(r), float(r), double(r), p0(r); + +.sw: a|c|d,,1[b]; +.argi: .argd: .arg0: r,,1; M,,1; + ++i: *i: &: ^: .OR: +p0: ++d: *d: r,r,1; r,M,1; M,r,2; + +-i: -p0: -p0p0: -d: /d: r,r,1; r,M,1; + +/i: a,r,1[b]; b,r,1[c]; c,r,1[d]; + a,M,1[b]; b,M,1[c]; c,M,1[d]; + +%: a,r,b; b,r,c; c,r,d; + a,M,b; b,M,c; c,M,d; + +<<: >>: r,r,1; r,intlit,1; + +=+i: =*i: =&: =^: =OR: +=+d: =*d: M,r,1; M,r,2; + +.BNOT: -ui: -ud: r,,1; M,,r; + +&u0: +++ai: ++ac: --ai: --ac: M,,r; + +++ap0: --ap0: M,b,a|c|d; M,d,b; + +++bi: ++bc: +--bi: --bc: M,,r; M,,1; + +++bp0: --bp0: M,r,2; + +.ic: .ci: .ip0: .p0i: .df: .fd: +.cf: .cd: .if: .id: r,,1; + +.fc: .dc: .fi: .di: a,,b; + +==p0: !=p0: p0: <=p0: >=p0: +==i: !=i: i: <=i: >=i: +==d: !=d: d: <=d: >=d: r,r,label; r,M,label; + +==0p0: !=0p0: r,,label; M,,label; + + + + +macros + ++i: *i: &: ^: .OR: +p0: + + (r,r,): " #O #F,#S" + (M,,): " #O #S,#F" + (r,~intlit,): " #O #F,#S" + (r,intlit,): " #O%ifm(#'S,I #F\,#6, #F\,#S)" + +-i: /i: %: -p0: sb: + + (,r,): " #O #F,#S" + (,~intlit,): " #O #F,#S" + (,intlit,): " #O%ifm(#'S,I #F\,#6, #F\,#S)" + ++d: *d: + + (r,,): " #O #F,#S" + (M,,): " #O #S,#F" + +-d: /d: -p0p0: + + " #O #F,#S" + +<<: + (,intlit,): " LSH #R,#6" + (,r,): " LSH #R,(#S)" +>>: + (,intlit,): " LSH #R,-#6" + (,r,): " MOVN #S,#S\n LSH #R,(#S)" + +=+i: " ADDB #S,#F" +=*i: " IMULB #S,#F" +=&: " ANDB #S,#F" +=^: " XORB #S,#F" +=OR: " IORB #S,#F" +=+d: " FADRB #S,#F" +=*d: " FMPRB #S,#F" + +&u0: " MOVEI #R,#F" +++ai: ++ac: " MOVE #R,#F\n AOS #F" +--ai: --ac: " MOVE #R,#F\n SOS #F" +++bi: ++bc: + (,,r): " MOVEI #R,1\n ADDB #R,#F" + (,,M): " AOS #F" +--bi: --bc: + (,,r): " SETO #R,\n ADDB #R,#F" + (,,M): " SOS #F" +++ap0: " MOVE #R,#F\n ADDM #S,#F" +--ap0: " MOVE #R,#F\n MOVN #S,#S\n ADDM #S,#F" +++bp0: " ADDB #S,#F" +--bp0: " MOVN #S,#S\n ADDB #S,#F" +.BNOT: + (r,,): " SETCA #R," + (M,,): " SETCM #R,#F" +-ui: -ud: " MOVN #R,#F" + +==p0: " CAMN #F,#S\n GO #R" +!=p0: " CAME #F,#S\n GO #R" +p0: " CAMLE #F,#S\n GO #R" +<=p0: " CAMG #F,#S\n GO #R" +>=p0: " CAML #F,#S\n GO #R" + +==i: "%ifm(#'S,%if(#6,\tCAIN\t#F\,#6\n\tGO\t#R,\tJUMPE\t#F\,#R),\tCAMN\t#F\,#S\n\tGO\t#R)" +!=i: "%ifm(#'S,%if(#6,\tCAIE\t#F\,#6\n\tGO\t#R,\tJUMPN\t#F\,#R),\tCAME\t#F\,#S\n\tGO\t#R)" +i: "%ifm(#'S,%if(#6,\tCAILE\t#F\,#6\n\tGO\t#R,\tJUMPG\t#F\,#R),\tCAMLE\t#F\,#S\n\tGO\t#R)" +<=i: "%ifm(#'S,%if(#6,\tCAIG\t#F\,#6\n\tGO\t#R,\tJUMPLE\t#F\,#R),\tCAMG\t#F\,#S\n\tGO\t#R)" +>=i: "%ifm(#'S,%if(#6,\tCAIL\t#F\,#6\n\tGO\t#R,\tJUMPGE\t#F\,#R),\tCAML\t#F\,#S\n\tGO\t#R)" + +==d: " FSBR #F,#S\n JUMPE #F,#R" +!=d: " FSBR #F,#S\n JUMPN #F,#R" +d: " FSBR #F,#S\n JUMPG #F,#R" +<=d: " FSBR #F,#S\n JUMPLE #F,#R" +>=d: " FSBR #F,#S\n JUMPGE #F,#R" + +==0p0: + (M,,): " SKIPN #F\n GO #R" + (r,,): " JUMPE #F,#R" +!=0p0: + (M,,): " SKIPE #F\n GO #R" + (r,,): " JUMPN #F,#R" + +.cc: .ii: +.ff: .dd: +.p0p0: + (r,,r): " MOVE #R,#F" + (r,,M): " MOVEM #F,#R" + (~intlit,,r): " MOVE #R,#F" + (intlit,,r): " %ifm(#'F,MOVEI\t#R\,#4,%ifm(#3,-#4,MOVNI\t#R\,-#4,MOVE\t#R\,#F))" + +.if: .id: +.cf: .cd: " FSC #R,155" +.di: .dc: +.fi: .fc: " JSP 0,FIXIFY""" +.ic: .ci: +.ip0: .p0i: +.df: .fd: "\" + +.argi: +.argd: +.arg0: " PPUSH #F" + +in: c: " #0" +ad0: " #R" + +al: "\" +ca: " CCALL #0,#F" + +end: +".PDATA +CONSTANTS +END" + +en: " ENTRY #0" +ex: " EXTERN #0" +eq: "#0:" +go: " GO #R" +hd: + +" TITLE %pname() + RADIX 10. +.INSRT C;NC INSERT +" + +ln: "\n; LINE #0\n" +p: + +"%setfno(#0) +\%A==#2 + \%A,,[ASCIZ/%m(#1)/] +%i(#1): ADDI P,FS#0" + +rt: +" SUBI P,FS#0+\%A+1 + GO @<\%A+1>(P)" +ep: +" SUBI P,FS#0+\%A+1 + GO @<\%A+1>(P) +FS#0==#1-1" + +st: "I#0:" +z: " BLOCK #0" + +f: d: " %ff(#0)" +nf: nd: " -%ff(#0)" + +ts: +"%if(#0,%sb(68,#'F,#'F,-6,#0) +,) JUMPL #F,#R + CAILE #F,#5-#0 + GO #R + GO @(#F)[" + +ets: " ]" + +ls: +" MOVE B,[-#0,,[" + +els: +" ]] + CAMN #F,(B) + GO @#0(B) + AOBJN B,.-2 + GO #R" + +lc: " L#0" +l: "L#0:" +sc: " S#0" +pu: ".CODE" +pd: ".PDATA" +im: ".UDATA" +da: ".IDATA" + \ No newline at end of file diff --git a/src/c/pdp11.gt b/src/c/pdp11.gt new file mode 100644 index 00000000..ac8ecb43 --- /dev/null +++ b/src/c/pdp11.gt @@ -0,0 +1,285 @@ +typenames (char, int, float, double); +regnames (r0, r2, r3, r1, fr0, fr1, fr2, fr3); +memnames (reg, auto, ext, stat, param, label, intlit, floatlit, + stringlit, ir0, ir2, ir3, ir1); +size 1 (char), 2 (int, float), 4 (double); +align 1 (char), 2 (int, float), 4 (double); +class r (r0, r1, r2, r3), f (fr0, fr1, fr2, fr3); +saveareasize 0; +pointer p0 (1); +offsetrange p0 (,); +returnreg r0 (int, p0), fr0 (double); +type char(r), int(r), float(f), double(f), p0(r); + +.sw: r0|r2,,1[r1,r3]; + ++i: &: .OR: +p0: r,r,1; r,M,1; M,r,2; + +-i: -p0: -p0p0: <<: >>: r,r,1; r,M,1; + +*i: r1,r,r1; + r3,r,r3; + r1,M,r1; + r3,M,r3; + r0,r,r1[r0]; + r2,r,r3[r2]; + r0,M,r1[r0]; + r2,M,r3[r2]; + +/i: r1,r2|r3,r0[r1]; + r3,r0|r1,r2[r3]; + r1,M,r0[r1]; + r3,M,r2[r3]; + +%: r1,r2|r3,r1[r0]; + r3,r0|r1,r3[r2]; + r1,M,r1[r0]; + r3,M,r3[r1]; + +^: r,r,1; + ++d: *d: f,f,1; f,M,1; M,f,2; + +-d: /d: f,f,1; f,M,1; + +=+i: =-i: =&: =OR: +++bp0: --bp0: M,r,1; M,M,1; + +=^: M,r,1; + +.BNOT: -ui: r,,1; + +-ud: f,,1; + +&u0: M,,r; + +++ai: ++ac: --ai: --ac: M,,r; + +++ap0: --ap0: M,r,r; M,M,r; + +++bi: ++bc: +--bi: --bc: M,,1; + +.ic: .ci: .ip0: .p0i: r,,1; + +.df: .fd: f,,1; + +.cf: .cd: r,,f; +.if: .id: r,,f; M,,f; +.fc: .dc: .fi: .di: f,,r; + +==p0: !=p0: p0: <=p0: >=p0: +==i: !=i: i: <=i: >=i: r,r,label; + r,M,label; + M,r,label; + M,M,label; + +==d: !=d: d: <=d: >=d: f,f,label; M,f,label; + + +macros + ++i: .OR: +p0: +d: *d: + + (r|f,,): " #O #S,#F" + (M,,): " #O #F,#S" + +-i: -p0: -p0p0: sb: ^: *i: -d: /d: + + " #O #S,#F" +/i: %: + +" tst #F + sxt #F-1 + #O #S,#F-1" + +&: + +(r,,): +" mov #S,-(sp) + com (sp) + bic (sp)+,#F" + +(M,,): +" mov #F,-(sp) + com (sp) + bic (sp)+,#S" + +<<: " ash #S,#F" +>>: +(,intlit,): " ash \#-#6.,#F" +(,~intlit,): +" mov #S,-(sp) + neg (sp) + ash (sp)+,#F" + +=+i: ++bp0: " add #S,#F" +=-i: --bp0: " sub #S,#F" +=OR: " bis #S,#F" +=^: " xor #S,#F" +=&: + +" mov #S,-(sp) + com (sp) + bic (sp)+,#F" + +.BNOT: -ui: -ud: + + " #O #R" + +&u0: +(auto,,): +" mov sp,#R + add \##4.,#R" +(ext|stat|label|stringlit,,): +" mov \##F,#R" +(param,,): +" mov r4,#R + add \##4.,#R" + +++ai: + +" mov #F,#R + inc #F" + +++ac: + +" movb #F,#R + incb #F" + +--ai: + +" mov #F,#R + dec #F" + +--ac: + +" movb #F,#R + decb #F" + +++ap0: + +" mov #F,#R + add #S,#F" + +--ap0: + +" mov #F,#R + sub #S,#F" + +++bi: " inc #R" +--bi: " dec #R" +++bc: " incb #R" +--bc: " decb #R" + +.ic: +.ip0: .p0i: +.df: .fd: "\" + +.ci: " bic \#177400,#R" + +.cf: .cd: + +" bic \#177400,#F + ldcid #F,#R" + +.if: .id: " ldcid #F,#R" +.fi: .di: +.fc: .dc: " stcdi #F,#R" + +==i: !=i: i: <=i: >=i: + +" cmp #F,#S + %bc(#'O) .+6 + jmp #R" + +==d: !=d: d: <=d: >=d: + +" cmpd #F,#S + %bc(#'O) .+6 + jmp #R" + +==p0: !=p0: p0: <=p0: >=p0: + +" cmp #F,#S + %ubc(#'O) .+6 + jmp #R" + +.cc: " movb #F,#R" +.ii: .p0p0: " mov #F,#R" +.ff: + + (f,,f): " ldd #F,#R" + (M,,f): " ldcfd #F,#R" + (f,,M): " stcdf #F,#R" + +.dd: + + (,,f): " ldd #F,#R" + (,,M): " std #F,#R" + +in: " #0." +ad0: " #R" +c: " .byte #0." +ca: + +" jsr r5,#F + #1. + #0." + +end: ".end" +en: ex: ".globl #0" +ep: + +" jmp epilog +fs#0=#1." + +eq: "#0:" +go: " jmp #R" +hd: + +".title %pname() +.insrt c;c11 insert +" + +ln: "\n; line #0\n" +p: + +" +%i(#1): jsr r0,prolog + fs#0" + +rt: " jmp epilog" +st: "i#0:" +z: " .blkb #0." + +f: d: " %ff(#0)" +nf: nd: " -%ff(#0)" + +ts: +"%if(#0,%sb(68,#'F,#'F,-6,#0) +,) tst #F + bge .+6 + jmp #R + cmp #F,\#<#5.-#0.> + bgt .+8. + asl #F + jmp @<.+8.>(#F) + jmp #R" + +ls: +" mov \##0.,r1 + mov \#.+18.,r3 + cmp #F,(r3)+ + bne .+6 + jmp @2*#0.-2(r3) + sob r1,.-8. + jmp #R" + +lc: " l#0" +l: "l#0:" +sc: " s#0" +pu: pd: ".text" +da: ".data" +im: ".bss" + \ No newline at end of file diff --git a/src/c/pdp20.gt b/src/c/pdp20.gt new file mode 100644 index 00000000..093978dc --- /dev/null +++ b/src/c/pdp20.gt @@ -0,0 +1,234 @@ +typenames (char, int, float, double); +regnames (a, c, d, b); +memnames (reg, auto, ext, stat, param, label, intlit, floatlit, + stringlit, ia, ic, id, ib); +size 1 (char, int, float, double); +align 1(char, int, float, double); +class r (a, b, c, d); +saveareasize 1; +pointer p0 (1); +offsetrange p0 (,); +returnreg a (int, double, p0); +type char(r), int(r), float(r), double(r), p0(r); + +.sw: a|c|d,,1[b]; +.argi: .argd: .arg0: r,,1; M,,1; + ++i: *i: &: ^: .OR: +p0: ++d: *d: r,r,1; r,M,1; M,r,2; + +-i: -p0: -p0p0: -d: /d: r,r,1; r,M,1; + +/i: a,r,1[b]; b,r,1[c]; c,r,1[d]; + a,M,1[b]; b,M,1[c]; c,M,1[d]; + +%: a,r,b; b,r,c; c,r,d; + a,M,b; b,M,c; c,M,d; + +<<: >>: r,r,1; r,intlit,1; + +=+i: =*i: =&: =^: =OR: +=+d: =*d: M,r,1; M,r,2; + +.BNOT: -ui: -ud: r,,1; M,,r; + +&u0: +++ai: ++ac: --ai: --ac: M,,r; + +++ap0: --ap0: M,b,a|c|d; M,d,b; + +++bi: ++bc: +--bi: --bc: M,,r; M,,1; + +++bp0: --bp0: M,r,2; + +.ic: .ci: .ip0: .p0i: .df: .fd: +.cf: .cd: .if: .id: r,,1; + +.fc: .dc: .fi: .di: a,,b; + +==p0: !=p0: p0: <=p0: >=p0: +==i: !=i: i: <=i: >=i: +==d: !=d: d: <=d: >=d: r,r,label; r,M,label; + +==0p0: !=0p0: r,,label; M,,label; + + + + +macros + ++i: *i: &: ^: .OR: +p0: + + (r,r,): " #O #F,#S" + (M,,): " #O #S,#F" + (r,~intlit,): " #O #F,#S" + (r,intlit,): " #O%ifm(#'S,I #F\,#6, #F\,#S)" + +-i: /i: %: -p0: sb: + + (,r,): " #O #F,#S" + (,~intlit,): " #O #F,#S" + (,intlit,): " #O%ifm(#'S,I #F\,#6, #F\,#S)" + ++d: *d: + + (r,,): " #O #F,#S" + (M,,): " #O #S,#F" + +-d: /d: -p0p0: + + " #O #F,#S" + +<<: + (,intlit,): " LSH #R,#6" + (,r,): " LSH #R,(#S)" +>>: + (,intlit,): " LSH #R,-#6" + (,r,): " MOVN #S,#S\n LSH #R,(#S)" + +=+i: " ADDB #S,#F" +=*i: " IMULB #S,#F" +=&: " ANDB #S,#F" +=^: " XORB #S,#F" +=OR: " IORB #S,#F" +=+d: " FADRB #S,#F" +=*d: " FMPRB #S,#F" + +&u0: " MOVEI #R,#F" +++ai: ++ac: " MOVE #R,#F\n AOS #F" +--ai: --ac: " MOVE #R,#F\n SOS #F" +++bi: ++bc: + (,,r): " MOVEI #R,1\n ADDB #R,#F" + (,,M): " AOS #F" +--bi: --bc: + (,,r): " SETO #R,\n ADDB #R,#F" + (,,M): " SOS #F" +++ap0: " MOVE #R,#F\n ADDM #S,#F" +--ap0: " MOVE #R,#F\n MOVN #S,#S\n ADDM #S,#F" +++bp0: " ADDB #S,#F" +--bp0: " MOVN #S,#S\n ADDB #S,#F" +.BNOT: + (r,,): " SETCA #R," + (M,,): " SETCM #R,#F" +-ui: -ud: " MOVN #R,#F" + +==p0: " CAMN #F,#S\n GO #R" +!=p0: " CAME #F,#S\n GO #R" +p0: " CAMLE #F,#S\n GO #R" +<=p0: " CAMG #F,#S\n GO #R" +>=p0: " CAML #F,#S\n GO #R" + +==i: "%ifm(#'S,%if(#6,\tCAIN\t#F\,#6\n\tGO\t#R,\tJUMPE\t#F\,#R),\tCAMN\t#F\,#S\n\tGO\t#R)" +!=i: "%ifm(#'S,%if(#6,\tCAIE\t#F\,#6\n\tGO\t#R,\tJUMPN\t#F\,#R),\tCAME\t#F\,#S\n\tGO\t#R)" +i: "%ifm(#'S,%if(#6,\tCAILE\t#F\,#6\n\tGO\t#R,\tJUMPG\t#F\,#R),\tCAMLE\t#F\,#S\n\tGO\t#R)" +<=i: "%ifm(#'S,%if(#6,\tCAIG\t#F\,#6\n\tGO\t#R,\tJUMPLE\t#F\,#R),\tCAMG\t#F\,#S\n\tGO\t#R)" +>=i: "%ifm(#'S,%if(#6,\tCAIL\t#F\,#6\n\tGO\t#R,\tJUMPGE\t#F\,#R),\tCAML\t#F\,#S\n\tGO\t#R)" + +==d: " FSBR #F,#S\n JUMPE #F,#R" +!=d: " FSBR #F,#S\n JUMPN #F,#R" +d: " FSBR #F,#S\n JUMPG #F,#R" +<=d: " FSBR #F,#S\n JUMPLE #F,#R" +>=d: " FSBR #F,#S\n JUMPGE #F,#R" + +==0p0: + (M,,): " SKIPN #F\n GO #R" + (r,,): " JUMPE #F,#R" +!=0p0: + (M,,): " SKIPE #F\n GO #R" + (r,,): " JUMPN #F,#R" + +.cc: .ii: +.ff: .dd: +.p0p0: + (r,,r): " MOVE #R,#F" + (r,,M): " MOVEM #F,#R" + (~intlit,,r): " MOVE #R,#F" + (intlit,,r): " %ifm(#'F,MOVEI\t#R\,#4,%ifm(#3,-#4,MOVNI\t#R\,-#4,MOVE\t#R\,#F))" + +.if: .id: +.cf: .cd: " FSC #R,155" +.di: .dc: +.fi: .fc: " JSP 0,FIXIFY""" +.ic: .ci: +.ip0: .p0i: +.df: .fd: "\" + +.argi: +.argd: +.arg0: " PPUSH #F" + +in: c: " #0" +ad0: " #R" + +al: "\" +ca: " CCALL #0,#F" + +end: +".PDATA +CONSTANTS +END" + +en: " ENTRY #0" +ex: " EXTERN #0" +eq: "#0:" +go: " GO #R" +hd: + +" TITLE %pname() + RADIX 10. +.INSRT NC +" + +ln: "\n; LINE #0\n" +p: + +"%setfno(#0) +\%A==#2 + \%A,,[ASCIZ/%m(#1)/] +%i(#1): ADDI P,FS#0" + +rt: +" SUBI P,FS#0+\%A+1 + GO @<\%A+1>(P)" +ep: +" SUBI P,FS#0+\%A+1 + GO @<\%A+1>(P) +FS#0==#1-1" + +st: "I#0:" +z: " BLOCK #0" + +f: d: " %ff(#0)" +nf: nd: " -%ff(#0)" + +ts: +"%if(#0,%sb(68,#'F,#'F,-6,#0) +,) JUMPL #F,#R + CAILE #F,#5-#0 + GO #R + GO @(#F)[" + +ets: " ]" + +ls: +" MOVE B,[-#0,,[" + +els: +" ]] + CAMN #F,(B) + GO @#0(B) + AOBJN B,.-2 + GO #R" + +lc: " L#0" +l: "L#0:" +sc: " S#0" +pu: ".CODE" +pd: ".PDATA" +im: ".UDATA" +da: ".IDATA" + \ No newline at end of file diff --git a/src/c/unix.gt b/src/c/unix.gt new file mode 100644 index 00000000..7f91df92 --- /dev/null +++ b/src/c/unix.gt @@ -0,0 +1,340 @@ +typenames (char, int, float, double); +regnames (r0, r2, r3, r1, fr0, fr1, fr2, fr3); +memnames (reg, auto, ext, stat, param, label, intlit, floatlit, + stringlit, ir0, ir2, ir3, ir1); +size 1 (char), 2 (int), 4 (float), 8 (double); +align 1 (char), 2 (int, float, double); +class r (r0, r1, r2, r3), f (fr0, fr1, fr2, fr3); +saveareasize 0; +pointer p0 (1); +offsetrange p0 (,); +returnreg r0 (int, p0), fr0 (double); +type char(r), int(r), float(f), double(f), p0(r); + +.sw: r0|r2,,1[r1,r3]; + ++i: &: .OR: +p0: r,r,1; r,M,1; M,r,2; + +-i: -p0: -p0p0: <<: >>: r,r,1; r,M,1; + +*i: r1,r,r1; + r3,r,r3; + r1,M,r1; + r3,M,r3; + r0,r,r1[r0]; + r2,r,r3[r2]; + r0,M,r1[r0]; + r2,M,r3[r2]; + +/i: r1,r2|r3,r0[r1]; + r3,r0|r1,r2[r3]; + r1,M,r0[r1]; + r3,M,r2[r3]; + +%: r1,r2|r3,r1[r0]; + r3,r0|r1,r3[r2]; + r1,M,r1[r0]; + r3,M,r3[r1]; + +^: r,r,1; + ++d: *d: f,f,1; f,~floatlit,1; ~floatlit,f,2; + +-d: /d: f,f,1; f,~floatlit,1; + +=+i: =-i: =&: =OR: +++bp0: --bp0: M,r,1; M,M,1; + +=^: M,r,1; + +.BNOT: -ui: r,,1; + +-ud: f,,1; + +&u0: M,,r; + +++ai: ++ac: --ai: --ac: M,,r; + +++ap0: --ap0: M,r,r; M,M,r; + +++bi: ++bc: +--bi: --bc: M,,1; + +.ic: .ci: .ip0: .p0i: r,,1; + +.df: .fd: f,,1; + +.cf: .cd: r,,f; +.if: .id: r,,f; M,,f; +.fc: .dc: .fi: .di: f,,r; + +==p0: !=p0: p0: <=p0: >=p0: +==i: !=i: i: <=i: >=i: r,r,label; + r,M,label; + M,r,label; + M,M,label; + +==d: !=d: d: <=d: >=d: f,f,label; ~floatlit,f,label; + +macros + ++i: .OR: +p0: +d: *d: + + (r|f,,): " #O #S,#F" + (M,,): " #O #F,#S" + +-i: -p0: -p0p0: sb: ^: *i: -d: /d: + + " #O #S,#F" +/i: %: + +" tst #F + sxt #F-1 + #O #S,#F-1" + +&: + +(r,,): +" mov #S,-(sp) + com (sp) + bic (sp)+,#F" + +(M,,): +" mov #F,-(sp) + com (sp) + bic (sp)+,#S" + +<<: " ash #S,#F" +>>: +(,intlit,): " ash $-#6.,#F" +(,~intlit,): +" mov #S,-(sp) + neg (sp) + ash +(sp),#F" + +=+i: ++bp0: " add #S,#F" +=-i: --bp0: " sub #S,#F" +=OR: " bis #S,#F" +=^: " xor #S,#F" +=&: + +" mov #S,-(sp) + com (sp) + bic (sp)+,#F" + +.BNOT: -ui: -ud: + + " #O #R" + +&u0: +(auto,,): +" mov sp,#R + add $#4.,#R" +(ext|stat|label|stringlit,,): +" mov $#F,#R" +(param,,): +" mov r4,#R + add $#4.,#R" + +++ai: + +" mov #F,#R + inc #F" + +++ac: + +" movb #F,#R + incb #F" + +--ai: + +" mov #F,#R + dec #F" + +--ac: + +" movb #F,#R + decb #F" + +++ap0: + +" mov #F,#R + add #S,#F" + +--ap0: + +" mov #F,#R + sub #S,#F" + +++bi: " inc #R" +--bi: " dec #R" +++bc: " incb #R" +--bc: " decb #R" + +.ic: +.ip0: .p0i: +.df: .fd: "\" + +.ci: " bic $177400,#R" + +.cf: .cd: + +" bic $177400,#F + movif #F,#R" + +.if: .id: " movif #F,#R" +.fi: .di: +.fc: .dc: " movfi #F,#R" + +==i: +==p0: + +" cmp #F,#S + jeq #R" + +!=i: +!=p0: + +" cmp #F,#S + jne #R" + +i: + +" cmp #F,#S + jgt #R" + +<=i: + +" cmp #F,#S + jle #R" + +>=i: + +" cmp #F,#S + jge #R" + +==d: + +" cmpf #F,#S + jeq #R" + +!=d: + +" cmpf #F,#S + jne #R" + +d: + +" cmpf #F,#S + jgt #R" + +<=d: + +" cmpf #F,#S + jle #R" + +>=d: + +" cmpf #F,#S + jge #R" + +p0: + +" cmp #F,#S + jhi #R" + +<=p0: + +" cmp #F,#S + jlos #R" + +>=p0: + +" cmp #F,#S + jhis #R" + +.cc: " movb #F,#R" +.ii: .p0p0: " mov #F,#R" +.ff: + + (f,,f): " movf #F,#R" + (M,,f): " movof #F,#R" + (f,,M): " movfo #F,#R" + +.dd: + +(~floatlit,,f): " movf #F,#R" +(,,M): " movf #F,#R" +(floatlit,,f): +" movf 0f,#R +.data +0: %ff(#4) +.text" + +in: " #0." +ad0: " #0" +c: " .byte #0." +al: ".even" +ca: " jsr r5,#F; #1.; #0." + +end: "\" +en: ex: ".globl #0" +ep: + +" jmp epilog +fs#0=#1." + +eq: "#0:" +go: " jbr #R" +hd: ".globl prolog,epilog" + +ln: "\n/ line #0\n" +p: "\n%i(#1): jsr r0,prolog; fs#0" + +rt: " jmp epilog" +st: "i#0:" +z: ".=.+#0." + +f: d: " %ff(#0)" +nf: nd: " %nff(#0)" + +ts: +"%if(#0,%sb(68,#'F,#'F,-6,#0) +,) cmp #F,$#5.-[#0.] + jhi #R + asl #F + jmp *0f(#F) +0:" + +ls: +" mov $#0.,r1 + mov $0f,r3 +2: cmp #F,(r3)+ + beq 1f + sob r1,2b + jbr #R +1: jmp *2*#0.-2(r3) +0:" + +lc: " l#0" +l: "l#0:" +sc: " s#0" +pu: pd: ".text" +da: ".data" +im: ".bss" + \ No newline at end of file diff --git a/src/c/yparse.c b/src/c/yparse.c new file mode 100644 index 00000000..50e5522b --- /dev/null +++ b/src/c/yparse.c @@ -0,0 +1,535 @@ +/* + + PARSING ROUTINE (for use with CC & OYACC) + + Requires the following: + + the tables produced by YACC + GETTOK - a lexical routine + PTOKEN - a token printing routine + a set of error message routines (one such set is + contained in the file YERROR >) + Returns TRUE if a fatal syntax error occured. + +*/ + +struct _token { int type, index, line; }; +# define token struct _token +token *dmperr(),*lex(),*tok(),*ctok(),*yreset(); + +# define pssize 200 +# define tbsize 30 +# define FALSE 0 +# define TRUE 1 + +extern int cout; + +/* GLOBAL VARIABLES USED TO RECEIVE INFO FROM GETTOK */ + +int lextype; /* indicates which terminal symbol read */ +int lexindex; /* used as translation element */ +int lexline; /* line-number of line which token appears on */ + +/* GLOBAL VARIABLES WHICH MAY BE SET TO INDICATE OPTIONS */ + +int debug FALSE; /* nonzero => print debugging info */ +int edebug FALSE; /* nonzero => print error recovery info */ +int xflag FALSE; /* nonzero => do not call action routines */ +int tflag FALSE; /* nonzero => print tokens as read */ + +/* GLOBAL VARIABLES REFERENCED BY ACTION ROUTINES */ + +int val; /* set to indicate translation element of LHS */ +int line; /* set to indicate line number of LHS */ +int *pv; /* used to reference translations of RHS */ +int *pl; /* used to reference line numbers of RHS */ +int lineno; /* used to reference lineno of current token */ + +/* INTERNAL STATIC VARIABLES */ + +static int *ps; /* parser stack pointer - states */ +static int s[pssize]; /* parser stack - states */ +static int v[pssize]; /* parser stack - translation elements */ +static int l[pssize]; /* parser stack - line numbers */ +static int *sps; /* save stack pointer - states*/ +static int *spv; /* save stack pointer - translation elements */ +static int *spl; /* save stack pointer - line numbers */ +static int ss[pssize]; /* save stack - states */ +static int sv[pssize]; /* save stack - translation elements */ +static int sl[pssize]; /* save stack - line numbers */ +static int must 7; /* number of tokens which must shift + correctly before error recovery is + considered successful */ +static int errcount 0; /* number of tokens left until successful */ +static int tskip; /* number of tokens skipped */ +static int spop; /* number of states popped */ +static int errmode 0; /* error recovery mode */ +static int tabmod FALSE; /* indicates index tables have been optimized */ + +/********************************************************************** + + PARSE - THE PARSER ITSELF + +**********************************************************************/ + +parse() + +{extern int (*act[])(), g[], pg[], r1[], r2[], a[], pa[], nwpbt; +int ac, op, n, state, *ap, *gp, control, i, r, + tlimit, slimit, *p, *ip, o, (*fp)(), t, errn; +token *ct, *tp; + +ps = &s[0]; +pv = &v[0]; +pl = &l[0]; + +state = 1; +*ps = 1; +*pv = 0; +*pl = 0; + +ct = lex(); + +if (!tabmod) + + { /* precompute index tables into action + and goto arrays */ + + ip = pa; + while ((o = *++ip) != -1) *ip = &a[o]; + ip = pg; + while ((o = *++ip) != -1) *ip = &g[o]; + tabmod = TRUE; + } + +while (TRUE) + {ap = pa[state]; + + if (debug) + cprint("executing state %d, token=%d\n",state, ct->type); + + while (TRUE) + + {ac = *ap++; + op = ac>>12; + n = ac&07777; + + switch (op) { + + case 1: /* SKIP ON TEST */ + + if (ct->type!=n) ++ap; + continue; + + case 2: /* SHIFT INPUT SYMBOL */ + + state = n; + +shift: val = ct->index; + line = ct->line; + ct = lex(); + + if (errcount) + {--errcount; + if (errcount==0) /* successful recovery */ + {ct = dmperr(); /* list recovery actions */ + control = 0; + break; + } + } + + control=1; /* stack new state */ + break; + + case 3: /* MAKE A REDUCTION */ + + if (debug) cprint ("reduce %d\n",n); + r = r2[n]; + ps =- r; + pv =- r; + pl =- r; + if (r>0) + {val = pv[1]; + line = pl[1]; + } + else + {val = ct->index; + line = ct->line; + } + if (!xflag && (fp = act[n])) (*fp)(); + state = *ps; + gp= pg[r1[n]]; + while (*gp) + {if (*gp==state) break; + gp=+2; + } + state = *++gp; + control = 1; /* stack new state */ + break; + + case 5: /* SHIFT ON MASK */ + + t = ct->type; + if (ap[t>>4] & (1<<(t&017))) /* bit on */ + {state = *(a+n+t-1); + goto shift; + } + + ap =+ nwpbt; /* skip over bit array */ + continue; + + case 4: /* ACCEPT INPUT */ + + if (errmode) + {ct = dmperr(); + control = 0; + break; + } + return (FALSE); + + case 0: /* SYNTAX ERROR */ + +/* The error recovery method used is to try skipping input symbols + and popping states off the stack in all possible combinations, + subject to a limitation on the number of symbols which may be + skipped. If a combination can be found which allows parsing + to continue for at least 7 more symbols, then the recovery is + considered a success. If no such combination can be found, the + parser gives up. + + In running through the possible recovery actions, skipping + input symbols is given priority over popping states, since + popping states tends to confuse the action routines, while + skipping symbols can not have any harmful effects on the + action routines. + + While searching for a successful combination of states and + symbols, the action routines are not called. When a successful + combination is found, the appropriate error messages are + written, the action routines are turned back on, and the parser + is reset at the point where the corrections have just been made. + + */ + + switch (errmode) { + + case 0: /* NEW ERROR */ + + if (edebug) cprint("errmode=0:st=%d,nst=%d,tok=%d\n", + state,ps-s,ct->type); + + synerr (ct->line); /* report syntax error */ + + p=s; + while (p<=ps) qprint (*p++); + pcursor (); + + tkeem(); /* enter error mode to save tokens */ + for (i=0;i<5;++i) + {tp = tok(i); + if (tp->type==1) break; + tprint (tp); + } + + save(); /* save parser stack */ + errcount = must; + errmode = 1; + xflag =| 2; /* turn off action routnes */ + + /* set up limits for recovery search */ + + tlimit = tbsize - must - 2; + slimit = ps-s; + + tskip = 0; + spop = 0; + errn = 1; + + case 1: /* try next recovery attempt */ + + restore(); + yreset(); + + if ((++tskip & 1) == 0) --spop; + if (spop<0 || ct->type==1 || tskip>tlimit) + {spop = errn++; + tskip = 0; + } + if (spop <= slimit) + {ct = ctok(tskip); + control = -spop; + break; + } + giveup (ct->line); /* give up */ + return (TRUE); + } + + if (edebug) cprint ("spop=%d,tskip=%d,token=%d\n", + spop,tskip,ct->type); + break; + } + + if (control>0) + {if (debug) cprint ("stack st=%d val=%d\n",state,val); + *++ps = state; + *++pv = val; + *++pl = line; + if (ps-s>=pssize) /* stack overflow */ + {stkovf (ct->line); + return (TRUE); + } + } + + else if (control<0) + {pv =+ control; + ps =+ control; + pl =+ control; + if (psline); + return (TRUE); + } + } + state = *ps; + break; + } + } +} + +/********************************************************************** + + DMPERR - PRINT ERROR RECOVERY ACTION TAKEN + RESET PARSER TO RESTART WITH ACTION ROUTINES + RETURN PTR TO NEW CURRENT TOKEN + +**********************************************************************/ + +token *dmperr() + + {int i; + token *tp; + extern token *ct; + + yreset(); + restore(); + if (spop>0) delmsg (ct->line); /* print DELETED: */ + for (i=1;i<=spop;++i) + qprint (ps[-spop+i]); /* print symbol associated with state */ + if (tskip>0) skpmsg (ct->line); + for(i=0;i= twp) + + /* If true, it is neccessary to read in another token. + If in normal mode, place the token in the first + element of the buffer. + */ + + {if (tokmode==0) ct=twp=tokbuf; + else + {if (twp>=tokbuf+tbsize) tkbovf (ct->line); + if (ct>twp) badtwp (ct->line); + } + rtoken (twp++); /* read token into next slot */ + } + + if (tflag && !tokmode) + {ptoken (ct, cout); + cputc (' ', cout); + } + lineno = ct->line; + return (ct); /* return ptr to token read */ + } + +token *tok(i) + + {token *p; + + p = ct + i; + if (p=tokbuf+tbsize) badtok (ct->line, i); + while (p>=twp) rtoken (twp++); + return (p); + } + +token *ctok(i) + + {return (ct = tok(i));} + +token *yreset() + + {return (ct = tokbuf);} + +tkeem() + + {int i,j; + token *tp1, *tp2; + + tokmode = 1; + j = i = twp - ct; /* number of valid tokens in buf */ + if (i>0) + {tp1 = tokbuf-1; + tp2 = ct-1; + while (i--) + {(++tp1)->type = (++tp2)->type; + tp1->index = tp2->index; + tp1->line = tp2->line; + } + } + ct = tokbuf; + twp = ct + j; + } + +tklem() + + {tokmode = 0;} + + +/********************************************************************** + + RTOKEN - PARSER READ TOKEN ROUTINE + +**********************************************************************/ + +rtoken(p) token *p; + + { + gettok(); + p->type = lextype; + p->index = lexindex; + p->line = lexline; + } + +/********************************************************************** + + PARSER ERROR MESSAGE ROUTINES + + synerr - announce syntax error + delmsg - print "DELETED:" message + skpmsg - print "SKIPPED:" message + + qprint - print symbol corresponding to parser state + tprint - print token + pcursor - print cursor symbol + + *** fatal errors *** + + giveup - announce failure of recovery attempt + stkovf - parser stack overflow + + *** internal fatal errors *** + + stkunf - parser stack underflow + tkbovf - token buffer overflow + badtwp - inconsistent token pointers + badtok - bad token reference + + ***** + + The routines are contained in the file YERROR.C so that + one may easily substitute other routines for them. + +*/