Digital Research
This commit is contained in:
2020-11-06 18:50:37 +01:00
parent 621ed8ccaf
commit 31738079c4
8481 changed files with 1888323 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,10 @@
$ diff DECL.c drb0:[steve.cpm68k.c.fparser]DECL.c
$ diff EXPR.c drb0:[steve.cpm68k.c.fparser]EXPR.c
$ diff ICODE.c drb0:[steve.cpm68k.c.fparser]ICODE.c
$ diff INIT.c drb0:[steve.cpm68k.c.fparser]INIT.c
$ diff INTERF.c drb0:[steve.cpm68k.c.fparser]INTERF.c
$ diff LEX.c drb0:[steve.cpm68k.c.fparser]LEX.c
$ diff MAIN.c drb0:[steve.cpm68k.c.fparser]MAIN.c
$ diff STMT.c drb0:[steve.cpm68k.c.fparser]STMT.c
$ diff TABL.c drb0:[steve.cpm68k.c.fparser]TABL.c
$ diff VERSION.c drb0:[steve.cpm68k.c.fparser]VERSION.c

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,311 @@
/*
Copyright 1982
Alcyon Corporation
8716 Production Ave.
San Diego, Ca. 92121
*/
#include "parser.h"
int bol 1;
int inittype;
int begseq;
/* int onepass; */
/*
This interfaces the Parser and the Code Generator, note that these
allow you to link together the Parser and the Code Generator.
*/
/* outbdata - set up for byte data*/
outbdata() /* returns - none*/
{
inittype = CHAR;
printf("\t.dc.b ");
}
/* outc - output a constant*/
outc(type,value) /* returns - none*/
int type;
int value;
{
if( type == CHAR )
outbdata();
else
outwdata();
printf("%d\n",value);
}
/* outwdata - set up for word data*/
outwdata() /* returns - none*/
{
inittype = INT;
printf("\t.dc.w ");
}
/* outdata - set up for data output*/
outdata() /* returns - none*/
{
inittype = INT;
printf("\t.data\n");
}
/* outldata - set up for long data output*/
outldata() /* returns - none*/
{
inittype = LONG;
printf("\t.data\n");
}
/* outfpdata - set up for floating point data output*/
outfpdata() /*[vlh] 3.4 returns - none*/
{
inittype = FLOAT;
printf("\t.data\n");
}
/* outbentry - outputs block/function entry code*/
outbentry(nlocs,nds,nas) /* returns - none*/
int nlocs; /* local size*/
int nds; /* number of D registers*/
int nas; /* number of A registers*/
{
if( !nds && !nas ) /* adjust for 1 arg*/
nlocs =+ 4;
printf("\tlink R14,#%d\n",-nlocs);
if( nds || nas ) {
printf("\tmovem.l R%d-R7",7-nds); /*7 for one arg*/
if( nas ) {
putchar('/');
printf("R%d-R13",14-nas);
}
printf(",-(sp)\n");
}
}
/* outbexit - output function exit code*/
outbexit(nds,nas) /* returns - none*/
int nds; /* number of D registers*/
int nas; /* number of A registers*/
{
if( nds || nas ) {
printf("\ttst.l (sp)+\n\tmovem.l (sp)+,"); /*1 arg stuff*/
if( nds ) {
printf("R%d-R7",8-nds);
if( nas )
putchar('/');
}
if( nas )
printf("R%d-R13",14-nas);
putchar('\n');
}
printf("\tunlk R14\n\trts\n");
}
/* outlocal - output local symbol for debugger*/
outlocal(type,sc,sym,val)
int type; /* local name type*/
int sc; /* storage type*/
char *sym; /* symbol name*/
int val;
{
switch( sc ) {
case STATIC:
if( notfunction(type) )
printf("\t~%.8s=L%d\n",sym,val);
break;
case REGISTER:
printf("\t~%.8s=R%d\n",sym,val);
break;
case AUTO:
printf("\t~%.8s=%d\n",sym,val);
break;
}
}
/* outswitch - output switch table info*/
outswitch(ncases,deflab,sp) /* returns - none*/
int ncases; /* number of cases in switch*/
int deflab; /* default label*/
struct swtch *sp; /* switch table pointer*/
{
register int vdif, val, hval, i, tlab;
register struct swtch *s;
val = sp->sw_value;
hval = sp[ncases-1].sw_value;
vdif = hval - val;
if( ncases <= 4 ) {
/*
*simple switch, do compares and brances, followed by branch to default
*/
for( s = sp; --ncases >= 0; s++ ) {
if( !s->sw_value )
printf("\ttst R0\n");
else
printf("\tcmp #%d,R0\n",s->sw_value);
printf("\tbeq L%d\n",s->sw_label);
}
outgoto(deflab);
}
else if( vdif > 0 && vdif <= ncases*3 ) {
/*jump switch, uses value in R0 to index into table of labels*/
if( val )
printf("\tsub #%d,R0\n",val);
tlab = nextlabel++;
printf("\tcmp #%d,R0\n\tbhi L%d\n",vdif,deflab); /*check for max*/
printf("\tasl #2,R0\n\tmove R0,R8\n\tadd.l #L%d,R8\n",tlab);
printf("\tmove.l (R8),R8\n\tjmp (R8)\n");
outdata();
outlab(tlab);
for( s = sp; val <= hval; val++ ) {
if( val == s->sw_value ) {
outclab(s->sw_label);
s++;
}
else
outclab(deflab);
}
outtext();
}
else {
/*
* direct switch, searches down table of values for match, if match
* found, branches to corresponding label in label table.
*/
tlab = nextlabel++;
printf("\text.l R0\n\tmove.l #L%d,R8\n\tmove #%d,R1\n",tlab,ncases);
i = nextlabel++;
outlab(i); /*loop label*/
printf("\tcmp.l (R8)+,R0\n\tdbeq R1,L%d\n",i);
printf("\tmove.l %d(R8),R8\n\tjmp (R8)\n",ncases*4);
outdata();
outlab(tlab);
for( s = sp, i = ncases; --i >= 0; s++ )
outlcon(s->sw_value);
outlcon(0); /* mark for default label*/
for( s = sp, i = ncases; --i >= 0; s++ )
outclab(s->sw_label);
outclab(deflab);
outtext();
}
}
outeof()
{
register int c;
v6flush(&sbuf);
v6flush(&obuf);
}
/* copysfile - copy string file to end of output file*/
copysfile(fname)
char *fname;
{
register int c;
close(sbuf.io_fd);
if( fopen(fname,&sbuf,0) < 0 ) /* 3rd arg for versados */
ferror("can't copy %s",fname);
while( (c=getc(&sbuf)) > 0 )
putc(c,&obuf);
v6flush(&obuf);
}
/* outword - output a word of data*/
outword(w) /* word expression*/
int w;
{
if( begseq )
putchar(',');
begseq++;
printf("%d",w);
}
/* outlong - output a long data*/
outlong(l) /* returns - none*/
long l; /* long data to output*/
{
outwdata();
outword(l.hiword);
outword(l.loword);
outendseq();
}
/* outfp - output floating point data*/
outfp(l) /*[vlh] 3.4 returns - none*/
long l; /* floating point data to output*/
{
outwdata();
outword(l.hiword);
outword(l.loword);
outendseq();
}
outendseq() /* returns - none*/
{
begseq = 0;
putchar('\n');
}
/*
* outtstr - output text string
* This outputs a string to the string file, this is used wherever
* you cannot output the string directly to data space, such as in
* the middle of expressions.
*/
outtstr(lab)
int lab;
{
char *savep;
int sbol;
savep = obp; /*save to restore later...*/
obp = &sbuf;
sbol = bol;
bol = 1;
printf("\tL%d:",lab);
outstr();
obp = savep;
bol = sbol;
}
/* outstr - output a string as a sequence of bytes*/
/* Outputs ".dc.b <byte1>,<byte2>,...,<0>*/
outstr()
{
register char *s;
register int i;
outbdata();
for( s = cstr, i = cstrsize; i > 0; i-- )
outword(*s++ & 0xff);
outendseq();
}
/*
* putchar - handle outputting to intermediate or error files
* This catches tabs to allow for the integration of the parser
* and code generator into one pass. By merely throwing away the
* tabs here, the output will be OK for the assembler.
*/
putchar(c)
char c;
{
if( !obp )
write(1,&c,1);
else if( c == '\t' ) {
if( bol ) /* not used && !onepass ) */
putc('(',obp); /*for code generator*/
}
else {
bol = (c == '\n');
putc(c,obp);
}
}

View File

@@ -0,0 +1,251 @@
/*
Copyright 1982
Alcyon Corporation
8716 Production Ave.
San Diego, Ca. 92121
*/
#include "machine.h"
/*
* intermediate code operators
* 0=>EOF, special operator
*/
#define EOF 0
/*1-59=>operators that generate code (entries in code gen optab)*/
#define ADD 1
#define SUB 2
#define MULT 3
#define DIV 4
#define MOD 5
#define RSH 6
#define LSH 7
#define AND 8
#define OR 9
#define XOR 10
#define NOT 11
#define UMINUS 12
#define COMPL 13
#define PREDEC 14
#define PREINC 15
#define POSTDEC 16
#define POSTINC 17
#define ASSIGN 18
#define EQADD 19
#define EQSUB 20
#define EQMULT 21
#define EQDIV 22
#define EQMOD 23
#define EQRSH 24
#define EQLSH 25
#define EQAND 26
#define EQOR 27
#define EQXOR 28
#define FJSR 29
#define EQUALS 30
#define NEQUALS 31
#define GREAT 32
#define GREATEQ 33
#define LESS 34
#define LESSEQ 35
#define INT2L 36
#define LONG2I 37
/*machine dependent operators that generate code*/
#define BTST 38
#define LOAD 39
#define LMULT 40
#define LDIV 41
#define LMOD 42
#define LEQMULT 43
#define LEQDIV 44
#define LEQMOD 45
#define EQADDR 46
#define EQNOT 47
#define EQNEG 48
#define DOCAST 49
#define STASSIGN 50 /*[vlh]*/
#define LONG2F 51 /*[vlh] 3.4*/
#define FLOAT2L 52 /*[vlh] 3.4*/
#define INT2F 53 /*[vlh] 3.4*/
#define FLOAT2I 54 /*[vlh] 3.4*/
#define LCGENOP 55 /*change if adding more operators...*/
/*intermediate code operators that do not generate code*/
#define ADDR 60
#define INDR 61
#define LAND 62
#define LOR 63
#define QMARK 64
#define COLON 65
#define COMMA 66
#define CINT 67
#define CLONG 68
#define SYMBOL 69
#define AUTOINC 70
#define AUTODEC 71
#define CALL 72
#define NACALL 73
#define BFIELD 74
#define IFGOTO 75
#define INIT 76
#define CFORREG 77
#define DCLONG 78
#define CFLOAT 79 /*[vlh] 3.4*/
/*operators local to parser*/
#define CAST 80
#define SEMI 81
#define LCURBR 82
#define RCURBR 83
#define LBRACK 84
#define RBRACK 85
#define LPAREN 86
#define RPAREN 87
#define STRING 88
#define RESWORD 89
#define APTR 90
#define PERIOD 91
#define SIZEOF 92
#define MPARENS 93
#define FRETURN 94
#define STACKEND 100
/*data types*/
#define TYPELESS 0
#define CHAR 1
#define SHORT 2
#define INT 3
#define LONG 4
#define UCHAR 5
#define USHORT 6
#define UNSIGNED 7
#define ULONG 8
#define FLOAT 9
#define DOUBLE 10
/*data types local to parser*/
#define STRUCT 11
#define FRSTRUCT 12
#define LLABEL 13
/*type flags and definitions*/
#define TYPE 017
#define SUPTYP 060
#define ALLTYPE 077
#define POINTER 020
#define FUNCTION 040
#define ARRAY 060
#define SUTYPLEN 2
/*data registers*/
#define DREG0 0
#define DREG2 2
#define DREG3 3
#define DREG4 4
#define DREG5 5
#define DREG6 6
#define DREG7 7
#define AREG3 11
#define AREG4 12
#define AREG5 13
/*storage classes*/
#define AUTO 1
#define REGISTER 2
#define EXTERNAL 3
#define STATIC 4
#define REGOFF 5
#define EXTOFF 6
#define STATOFF 7
#define INDEXED 8
/*exclusively code generator storage classes*/
#define CINDR 9
#define CLINDR 10
#define CFINDR 11 /* [vlh] 3.4 */
/*exclusively parser storage classes*/
#define STRPROTO 9
#define PDECLIST 10
#define PARMLIST 11
#define BFIELDCL 12
#define UNELCL 13
#define STELCL 14
/*opinfo table bits*/
#define OPPRI 077
#define OPBIN 0100
#define OPLVAL 0200
#define OPREL 0400
#define OPASSIGN 01000
#define OPLWORD 02000
#define OPRWORD 04000
#define OPCOM 010000
#define OPRAS 020000
#define OPTERM 040000
#define OPCONVS 0100000
/*68000 definitions*/
#define PTRSIZE 4
#define INTSIZE 2
#define LONGSIZE 4
#define SSIZE 8 /* chars per symbol */
#define TRUE 1
#define FALSE 0
#define TABC '\t' /* tab character */
#define EOLC '\n' /* end of line character */
#define BITSPBYTE 8
/*operator class priorities*/
#define TRMPRI 0 /* terminal nodes */
#define RPNPRI 1 /* ) and ] */
#define CALPRI 2 /* in-stack call, ( or [ */
#define COLPRI 3 /* init or case priority for : or , */
#define STKPRI 4 /* priority of end of stack */
#define COMPRI 5 /* normal priority for , */
#define ASGPRI 6 /* =, +=, -=, *=, /=, %=, ... */
#define QMKPRI 7 /* ?: */
#define LORPRI 8 /* || */
#define LNDPRI 9 /* && */
#define ORPRI 10 /* |, ! */
#define ANDPRI 11 /* & */
#define EQLPRI 12 /* ==, != */
#define RELPRI 13 /* >, <, >=, <= */
#define SHFPRI 14 /* <<, >> */
#define ADDPRI 15 /* +, - */
#define MULPRI 16 /* *, /, % */
#define UNOPRI 17 /* ++, --, &, *, -, ~, sizeof */
#define LPNPRI 18 /* ., ->, [, (, function call */
#define PSTPRI 19 /* in-stack post--, post++ */
struct io_buf {
int io_fd;
int io_nc;
char *io_p;
char io_b[512];
};
#ifdef PDP11
struct { short hiword; short loword; };
#endif
#ifdef MC68000
struct { short hiword; short loword; };
#endif
#ifdef VAX
struct { short loword; short hiword; };
#endif
#define EXPSIZE 1024
int exprarea[EXPSIZE];
/* v6io buffer declaration */
#define BLEN 512
struct iobuf{
int fildes;
int nunused;
char *xfree;
char buff[BLEN];
};

View File

@@ -0,0 +1,323 @@
/*
Copyright 1982
Alcyon Corporation
8716 Production Ave.
San Diego, Ca. 92121
*/
/*
C68 Parser - include file
*/
#include "icode.h"
/*symbol attribute fields*/
#define SRESWORD 001 /*is symbol a reserved word?*/
#define SGLOBAL 002 /*is symbol global?*/
#define STYPEDEF 004 /*typedef declaration?*/
#define SDEFINED 010 /*symbol defined?*/
/*reserved words*/
#define R_AUTO 1
#define R_BREAK 2
#define R_CASE 3
#define R_CHAR 4
#define R_CONTINUE 5
#define R_DO 6
#define R_DEFAULT 7
#define R_DOUBLE 8
#define R_GOTO 9
#define R_ELSE 10
#define R_EXTERNAL 11
#define R_FLOAT 12
#define R_FOR 13
#define R_IF 14
#define R_INT 15
#define R_LONG 16
#define R_REGISTER 17
#define R_RETURN 18
#define R_SHORT 19
#define R_SIZEOF 20
#define R_STATIC 21
#define R_STRUCT 22
#define R_SWITCH 23
#define R_TYPEDEF 24
#define R_UNION 25
#define R_UNSIGNED 26
#define R_WHILE 27
/*
* mixed-mode conversions, entries in 2-d array indexed by:
* (int,unsn,long,doub,ptr)
*/
#define INT_CHAR 1
#define UNSN_CHAR 1
#define LONG_CHAR 1
#define DOUB_CHAR 1
#define PTR_CHAR 1
#define INT_UNSN 0 /*no conversion is generated*/
#define INT_LONG 2
#define INT_DOUB 3
#define INT_PTR 4
#define UNSN_INT 0 /*no conversion is generated*/
#define UNSN_LONG 6
#define UNSN_DOUB 7
#define UNSN_PTR 8
#define LONG_INT 9
#define LONG_UNSN 10
#define LONG_DOUB 11
#define LONG_PTR 12
#define DOUB_INT 13
#define DOUB_UNSN 14
#define DOUB_LONG 15
#define PTR_INT 16
#define PTR_UNSN 17
#define PTR_LONG 18
#define PTR_PTR 19
#define BADCONV 20
/* miscellaneous constants */
#define OPSSIZE 40 /*operator stack size*/
#define OPDSIZE 80 /*operand stack size*/
#define HSIZE 517 /*hash table size, 3.4 made prime */
#define SYMSIZE 1024 /*size to alloc for symbol structures*/
#define SWSIZE 256 /*max no. of cases in a switch*/
#define DSIZE 1000 /*dimension table size*/
#define BITSPWORD 16 /*bits per word*/
#define AREGLO 010 /*A reg flag*/
#define HICREG 2 /*highest reg # used for code generation*/
#define BITSPCHAR 8 /*bits per char*/
#define CHRSPWORD 2 /*chars per word*/
#define STRSIZE 300 /*max string length*/
#define NFARGS 40 /*max no. of args to function*/
#define NFRSTR 20 /*max no. of forward ref struct proto*/
/*symbol table node*/
struct symbol {
char s_attrib; /* defined, resword, global, typedef */
char s_sc; /* auto, static, external, register */
int s_type; /* 4bits specified, 2 bit fields for ptr... */
int s_dp; /* index into dimension table */
int s_ssp; /* dimension table/function arg table */
int s_offset; /* offset inside of structure */
char s_symbol[SSIZE]; /* symbol identifier, to SSIZE chars */
struct symbol *s_struc; /* if struct, ptr to parent (sys III) */
struct symbol *s_next; /* next symbol table entry */
};
/*expression tree operator node*/
struct tnode {
int t_op;
int t_type;
int t_dp;
int t_ssp;
struct tnode *t_left;
struct tnode *t_right;
};
/*expression tree node for symbol - only keeps location*/
struct symnode {
int t_op;
int t_type; /*data type of symbol*/
int t_dp; /*dimension pointer of symbol*/
int t_ssp; /*structure size index to dtab*/
int t_sc; /*storage class of symbol*/
int t_offset; /*offset of symbol*/
int t_label;
};
/*expressioon tree node for external symbol - need to keep name*/
struct extnode {
int t_op;
int t_type;
int t_dp;
int t_ssp;
int t_sc;
int t_offset;
int t_reg;
int t_symbol[SSIZE]; /*symbol name*/
};
/*expression tree node for integer constant*/
struct conode {
int t_op;
int t_type;
int t_dp;
int t_ssp;
int t_value; /*constant value*/
};
struct lconode {
int t_op;
int t_type;
int t_dp;
int t_ssp;
long t_lvalue; /*constant value*/
};
struct swtch {
int sw_label;
int sw_value;
} swtab[SWSIZE]=0;
/*operator and operand stack used by expr*/
struct ops { /*operator stack*/
int o_op; /*operator*/
int o_pri; /*priority*/
} opstack[OPSSIZE]=0, *opp=0;
char *opdstack[OPDSIZE]=0; /*operand stack*/
char **opdp=0; /*operand stack pointer*/
char *opap=0; /*ptr to next available loc in exprarea*/
struct tnode *frp=0; /*pointer to function return info node*/
int cswp=0; /*current low switch table index*/
int clabel=0; /*continue label*/
int blabel=0; /*break label*/
int rlabel=0; /*return label*/
int dlabel=0; /*default label*/
int lineno=0; /*current line number of input*/
int errcnt=0; /*count of errors*/
int inclflag=0; /*in include file, don't incr line #'s*/
int inclline=0; /*[vlh]line# in incl file for err rpting*/
char inclfile[13]=0; /*[vlh]include filename for err rpting*/
int equalstop=0; /*stop lex at '=', used for external init*/
int commastop=0; /*stop parse @ comma(used for const expr)*/
int colonstop=0; /*stop parse @ colon(used for case value)*/
int instruct=0; /*set when in structure declaration*/
int smember=0; /*set when seen . or ->*/
int infunc=0; /*set when in function body*/
int tdflag=0; /*declaration is a typedef proto*/
char *tdp=0; /*points to typedef prototype*/
int localsize=0; /*length of local variables*/
int naregs=0; /*keeps track of ptr registers alloc'd*/
int ndregs=0; /*keep track of data registers alloc'd*/
int loadreg=0; /*need to load registers...*/
int boffset=0; /*current bit offset in structure*/
int eflag=0; /*[vlh] 3.4 IEEE floats */
int fflag=0; /*[vlh] 3.4 FFP floats */
int xflag=0; /*translate int's to long's*/
int wflag=0; /*[vlh] don't generate warning mesgs*/
int reducep=0; /*[vlh] if(procid); reduction*/
int peektok=0; /*peeked at token*/
/*dimension table*/
long dtab[DSIZE]=0; /* [vlh] 3.4 int => long */
int cdp=0; /*next entry in dtab to alloc*/
/*lexical analyzer values*/
int cvalue=0; /*current token value if keyword or CINT*/
int cstrsize=0; /*current string size*/
long clvalue=0; /*current token value if long constant*/
struct symbol *csp=0; /*current token symbol ptr if SYMBOL*/
char cstr[STRSIZE]=0; /*current token value if CSTRING*/
struct symbol *dsp=0; /*declarator symbol pointer*/
/* -1 -> not instruct, 0 -> unnamed struct */
struct symbol *strucptr[10]=0; /*[vlh] ptrs to struc symbols*/
/*function argument table, used to collect function parameters*/
struct farg {
struct symbol *f_sp;
int f_offset;
} fargtab[NFARGS]=0;
/*forward referenced structure prototype names*/
struct symbol *frstab[NFRSTR]=0;
int frstp=0;
/*output buffers for intermediate code and strings*/
struct io_buf obuf=0, sbuf=0, ibuf=0, *obp=0;
#define stypedef(sp) (sp->s_attrib&STYPEDEF)
#define walign(add) ((add+1)&(~1))
#define array(type) ((type&SUPTYP)==ARRAY)
#define function(type) ((type&SUPTYP)==FUNCTION)
#define pointer(type) ((type&SUPTYP)==POINTER)
#define notarray(type) ((type&SUPTYP)!=ARRAY)
#define notfunction(type) ((type&SUPTYP)!=FUNCTION)
#define notpointer(type) ((type&SUPTYP)!=POINTER)
#define btype(type) (type&TYPE)
#define suptype(type) (type&SUPTYP)
#define alltype(type) (type&(SUPTYP|TYPE))
#define asgop(op) ((opinfo[op]&OPASSIGN)!=0)
#define relop(op) ((opinfo[op]&OPREL)!=0)
#define lintegral(op) ((opinfo[op]&OPLWORD)!=0)
#define rintegral(op) ((opinfo[op]&OPRWORD)!=0)
#define rasop(op) ((opinfo[op]&OPRAS)!=0)
#define binop(op) ((opinfo[op]&OPBIN)!=0)
#define unaryop(op) ((opinfo[op]&OPBIN)==0)
#define leaf(op) ((opinfo[op]&OPTERM)!=0)
#define lvalop(op) ((opinfo[op]&OPLVAL)!=0)
#define oppriority(op) (opinfo[op]&OPPRI)
#define makeiop(op) (op|(0254<<8))
/* checks for symbol with structure element storage class */
#define isstel(tp) (tp->t_op==SYMBOL && (sesc(tp)))
#define sesc(t) (t->t_sc==STELCL||t->t_sc==UNELCL||t->t_sc==BFIELDCL)
/* peek at next token, if not read token put back, else delete */
/* 1 if matched, 0 otherwise */
#define peek(tok) ( (peektok=gettok()) == tok )
#define outcommon(sym,size) printf("\t.comm _%.8s,%ld\n",sym,size)
#define outgoto(lab) if( lab > 0 ) printf("\tbra L%d\n",lab)
/* change to text segment */
#define outtext() printf("\t.text\n")
/* change segment to bss */
#define outbss() printf("\t.bss\n")
/* output global symbol references */
#define outextdef(sym) printf("\t.globl _%.8s\n",sym)
/* outputs reserved memory [vlh] 3.4 %d => %ld */
#define outresmem(size) printf("\t.ds.b %ld\n",size)
/* output padding for word alignments */
#define outpad() printf("\t.even\n")
/* output long constant to assembler */
#define outlcon(val) printf("\t.dc.l %d\n",val)
/* output label constant */
#define outclab(lab) printf("\t.dc.l L%d\n",lab)
/* output a label */
#define outlab(lab) printf("\tL%d:",lab)
/* output function label */
#define outflab(sym) printf("\t_%.8s:\n\t~~%.8s:\n",sym,sym)
/* output data label */
#define outdlab(sym) printf("\t_%.8s:\n",sym)
/*functions returning pointers*/
char *expr();
char *talloc();
char *tnalloc();
char *enalloc();
char *snalloc();
char *cnalloc();
char *lcnalloc();
char *fpcnalloc();
char *popopd();
char *cvopgen();
char *arrayref();
char *funcref();
char *install();
char *lookup();
char *balpar();
char *sbrk();
long initlist();
long dsize();
long psize();
long dodecl();
long dlist();
long getdec();
long gethex();
long getoct();
long getfp();
long toieee();
long toffp();
int inittype=0;
int strassign=0;
int begseq=0;
#define EXPSIZE 1024
int exprarea[EXPSIZE]=0;
int opdontop=0;
int pbchar=0;
struct symbol *symbols=0;
struct symbol *symtab[HSIZE]=0;

View File

@@ -0,0 +1,106 @@
/*
Copyright 1982
Alcyon Corporation
8716 Production Ave.
San Diego, Ca. 92121
*/
#include "parser.h"
int bol;
outinit(tp,type) /* returns - none*/
struct tnode *tp;
{
outexpr(tnalloc(INIT,type,0,0,tp));
}
outcforreg(tp)
struct tnode *tp;
{
outexpr(tnalloc(CFORREG,tp->t_type,0,0,tp));
}
outifgoto(tp,dir,lab)
struct tnode *tp;
int dir;
int lab;
{
outexpr(tnalloc(IFGOTO,dir,lab,0,tp));
}
outexpr(tp)
struct tnode *tp;
{
if( !bol )
putchar('\n');
printf(".%x\n",lineno);
outtree(tp);
}
outtree(tp)
struct tnode *tp;
{
if( !tp )
return;
printf("%x.%x",tp->t_op,tp->t_type);
switch( tp->t_op ) {
case CINT:
printf(".%x\n",tp->t_value);
break;
case CLONG:
printf(".%x.%x\n",tp->t_lvalue.hiword,tp->t_lvalue.loword);
break;
case CFLOAT: /*[vlh] 3.4*/
printf(".%x.%x\n",tp->t_lvalue.hiword,tp->t_lvalue.loword);
break;
case SYMBOL:
printf(".%x",tp->t_sc);
if( tp->t_sc == EXTERNAL )
printf(".%.8s\n",tp->t_symbol);
else
printf(".%x\n",tp->t_offset);
break;
case 0:
putchar('\n');
break;
case IFGOTO:
case BFIELD:
printf(".%x\n",tp->t_dp);
outtree(tp->t_left);
break;
default:
putchar('\n');
outtree(tp->t_left);
if( binop(tp->t_op) )
outtree(tp->t_right);
break;
}
}
/* snalloc - symbol node allocation*/
/* Allocates a tree symbol node and sets the info in it*/
char *snalloc(type,sc,off,dp,ssp) /* returns pointer to node alloc'ed*/
int type; /* symbol type*/
int sc; /* storage class*/
int off; /* offset*/
int dp; /* dimension pointer or other info*/
int ssp; /* structure size pointer*/
{
register struct symnode *snp;
snp = talloc(sizeof(*snp));
snp->t_op = SYMBOL;
snp->t_sc = sc;
snp->t_type = type;
snp->t_dp = dp;
snp->t_ssp = ssp;
snp->t_offset = off;
return(snp);
}

View File

@@ -0,0 +1,827 @@
/*
Copyright 1982
Alcyon Corporation
8716 Production Ave.
San Diego, Ca. 92121
*/
#include "parser.h"
#define SOI '\01'
#define STEL HSIZE/2
/*
* the following are the cases within gettok, all other cases are
* single character unambiguous tokens. Note that we need to take
* special care not to interfere with the single character unambiguous
* operators, this is why there is a gap between WHITSP and EXCLAM.
*/
#define BADC 0 /*bad character*/
#define WHITSP 101 /*white space*/
#define EXCLAM 102 /*exlamation point*/
#define DQUOTE 103 /*double quote*/
#define PERCNT 104 /*percent sign*/
#define AMPER 105 /*ampersand*/
#define SQUOTE 106 /*single quote*/
#define STAR 107 /*asterisk or mult sign*/
#define PLUS 108 /*plus sign*/
#define MINUS 109 /*minus sign*/
#define SLASH 110 /*divide sign*/
#define DIGIT 111 /*0..9*/
#define LCAROT 112 /*less than sign*/
#define EQUAL 113 /*equals sign*/
#define RCAROT 114 /*greater than*/
#define ALPHA 115 /*a..z,A..Z and underbar*/
#define CAROT 116 /*^*/
#define BAR 117 /*vertical bar*/
char ctype[] {
BADC, BADC, BADC, BADC, BADC, BADC, BADC, BADC,
BADC, WHITSP, WHITSP, WHITSP, WHITSP, WHITSP, BADC, BADC,
BADC, BADC, BADC, BADC, WHITSP, BADC, BADC, BADC,
BADC, BADC, BADC, BADC, BADC, BADC, BADC, BADC,
WHITSP, EXCLAM, DQUOTE, BADC, BADC, PERCNT, AMPER, SQUOTE,
LPAREN, RPAREN, STAR, PLUS, COMMA, MINUS, PERIOD, SLASH,
DIGIT, DIGIT, DIGIT, DIGIT, DIGIT, DIGIT, DIGIT, DIGIT,
DIGIT, DIGIT, COLON, SEMI, LCAROT, EQUAL, RCAROT, QMARK,
BADC, 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, LBRACK, BADC, RBRACK, CAROT, ALPHA,
BADC, 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, LCURBR, BAR, RCURBR, COMPL, BADC
};
/*key word table*/
struct resword {
char *r_name;
int r_value;
} reswords[] {
"auto", R_AUTO,
"break", R_BREAK,
"case", R_CASE,
"char", R_CHAR,
"continue", R_CONTINUE,
"do", R_DO,
"default", R_DEFAULT,
"double", R_DOUBLE,
"goto", R_GOTO,
"else", R_ELSE,
"extern", R_EXTERNAL,
"float", R_FLOAT,
"for", R_FOR,
"if", R_IF,
"int", R_INT,
"long", R_LONG,
"register", R_REGISTER,
"return", R_RETURN,
"short", R_SHORT,
"sizeof", R_SIZEOF,
"static", R_STATIC,
"struct", R_STRUCT,
"switch", R_SWITCH,
"typedef", R_TYPEDEF,
"union", R_UNION,
"unsigned", R_UNSIGNED,
"while", R_WHILE,
0,
};
#define SELFMOD 0200
#define ASMASK 0177
/*
* this table is used to check for an operator after an equals sign.
* note that =-, =* and =& may all have an ambiguous meaning if not
* followed by a space, this is checked for in gettok.
*/
char asmap[] {
EQUALS, /*==*/
EQADD, /*=+*/
EQSUB|SELFMOD, /*=-*/
EQMULT|SELFMOD, /*=**/
EQDIV, /*=/*/
EQOR, /*=|*/
EQAND|SELFMOD, /*=&*/
EQXOR, /*=^*/
EQMOD, /*=%*/
};
char escmap[] "\b\n\r\t";
int pbchar; /*pushed back character*/
struct symbol *symtab[HSIZE]; /*hash table*/
struct symbol *symbols; /*pointer to next avail symbol buf*/
int nsyms; /*number of symbol bufs in memory*/
/*
* getdec - get a decimal number
* Uses Horner's method to get decimal number. Note that
* multiplication by 10 is cleverly programmed as two shifts and two
* adds. This is because long multiplies are painful on both the
* PDP-11 and 68000.
*/
long getdec() /* returns number*/
{
register long value;
register char c;
for( value = 0; (c=ngetch()) >= '0' && c <= '9'; ) {
value =<< 1; /*value = value*2*/
value =+ value << 2; /*value*2 + value*8 = value*10*/
value =+ (c-'0');
}
putback(c);
return(value);
}
#define BIAS 127L
#define EXPSIZ 4
#define FRACSIZ 20
long toieee();
long toffp();
float power10();
/*
* getfp - get a floating point constant
* we've already gotten the significant digits, now build a
* floating point number with possible decimal digits and an
* exponent, yields an ieee formated floating point number,
* unless the fflag is on, then a ffp constant is generated.
*/
long
getfp(significant)
long significant;
{
register char c;
register long places; /* decimal places */
int esign;
float exp, fraction, fp;
places = 0L; esign = 0; fraction = significant; exp = 0.0;
if ((c = ngetch()) == '.') /* get decimal places */
for( ; (c=ngetch()) >= '0' && c <= '9';) {
fraction = fraction * 10.0;
fraction = fraction + (c - '0');
places++;
}
if (c=='e' || c=='E') { /* exponent exists */
esign = (peekis('-')) ? 1 : (peekis('+')) ? 0 : 0;
for( ; (c=ngetch()) >= '0' && c <= '9'; ) {
exp = exp * 10.0;
exp = exp + (c - '0');
}
}
putback(c);
if (esign)
exp = -exp;
places = exp - places;
fp = fraction * power10(places);
if (fflag)
return( toffp(fp) );
else
return ( toieee(fp) );
}
float
power10(pwr) /* used by getfp, 10^pwr */
long pwr;
{
float f;
if (pwr < 0L) /* negative power */
for (f = 1.0; pwr < 0L; pwr++)
f = f / 10.0;
else /* positive power */
for (f = 1.0; pwr > 0L; pwr--)
f = f * 10.0;
return(f);
}
long
toffp(f) /* converts current machine float to ffp rep */
float f;
{
register long exp;
register int sign, count;
long l;
if (f == 0.0)
return(0L);
if (f < 0.0) {
sign = 1;
f = -f;
}
else
sign = 0;
exp = 0L;
for( ; f >= 1.0; f = f / 2.0)
exp++;
for( ; f < 0.5; f = f * 2.0)
exp--;
f = f * 16777216.0; /* 2 ^ 24 */
l = f;
l =<< 8;
if (sign)
l =| 0x80;
exp =+ 0x40;
l =| (exp & 0x7f);
return(l);
}
long
toieee(f) /* converts current machine float to ieee rep */
float f;
{
register long exp;
register int sign, count;
long l;
if (f == 0.0)
return(0L);
if (f < 0.0) {
sign = 1;
f = -f;
}
else
sign = 0;
exp = 0L;
for( ; f >= 2.0; f = f / 2.0)
exp++;
for( ; f < 1.0; f = f * 2.0)
exp--;
f = f - 1.0;
f = f * 8388608.0; /* 2 ^ 23 */
l = f;
if (sign)
l =| 0x80000000;
exp = (exp + BIAS)<<23;
l =| (exp & 0x7f800000);
return(l);
}
#define toupper(c) ((c) & ~32)
/* gethex - get an hexidecimal number*/
/* Uses Horner's method to get hexidecimal number*/
long gethex() /* returns number*/
{
register long value;
register char c, ch;
value = 0;
while( 1 ) {
if( (c=ngetch()) >= '0' && c <= '9' )
c =- '0';
else if((ch=toupper(c)) >= 'A' && ch <= 'F' ) /* [vlh] */
c = ch - ('A'-10);
else
break;
value = (value<<4) + c;
}
putback(c);
return(value);
}
/* getoct - get an octal number*/
/* Uses Horner's method to get octal number*/
long getoct(flag) /* returns number*/
int flag; /* string flag 1=>in string, else 0*/
{
register long value;
register char c;
register int count;
count = 0;
for( value = 0; (c=ngetch()) >= '0' && c <= '7'; ) {
if( flag && ++count > 3 )
break;
value = (value<<3) + (c-'0');
}
putback(c);
return(value);
}
/*
* gettok - get next token from input
* Checks pushed-packed token buffer, supresses / * * / comments,
* folds multiple character special symbols into single word token.
*/
gettok() /* returns token type*/
{
register int c, nextc, i;
register char *p;
register long value;
char sym[SSIZE];
if( peektok ) {
i = peektok;
peektok = 0;
return(i);
}
while( (c=ngetch()) != EOF ) {
switch(ctype[c]) {
case BADC: /*bad character*/
error("invalid character");
break;
case SEMI:
cvalue = 0; /* [vlh] not reserved word... */
default:
return( ctype[c] );
case WHITSP: /*skip all white space*/
break;
case EXCLAM: /*!= or !*/
return( peekis('=') ? NEQUALS : NOT );
case DQUOTE: /*quoted string*/
getstr(cstr,STRSIZE,'"');
cvalue = nextlabel++;
return(STRING);
case PERCNT: /*%= or %*/
return( peekis('=') ? EQMOD : MOD );
case AMPER: /*&=, && or &*/
return( peekis('=') ? EQAND : peekis('&') ? LAND : AND );
case SQUOTE: /*character constant*/
getstr(cstr,STRSIZE,'\'');
if( cstrsize > CHRSPWORD+1 ) {
error("character constant too long");
cstrsize = CHRSPWORD + 1;
}
cvalue = 0;
for( p = cstr; --cstrsize > 0; ) {
cvalue =<< BITSPCHAR;
cvalue =| (*p++ & 0377);
}
return(CINT);
case STAR: /**= or **/
return( peekis('=') ? EQMULT : MULT );
case PLUS: /*+=, ++ or +*/
return( peekis('=') ? EQADD : peekis('+') ? PREINC : ADD );
case MINUS: /*-=, --, -> or -*/
return( peekis('=') ? EQSUB : peekis('-') ? PREDEC :
peekis('>') ? APTR : SUB );
case SLASH: /*/ *..* /, //..., /= or /*/
if( peekis('*') ) {
while( (c=ngetch()) != EOF )
if( c == '*' && peekis('/') )
break;
if( c == EOF ) {
error("no */ before EOF");
return(EOF);
}
continue;
}
if( peekis('/') ) {
while( (c=ngetch()) != EOF && c != EOLC )
;
continue;
}
return( peekis('=') ? EQDIV : DIV );
case DIGIT: /*number constant (long or reg)*/
i = 0; /*flags if long constant*/
if( c != '0' ) {
putback(c);
dofp:
value = getdec();
if ((c=ngetch())=='.' || c=='e' || c=='E') { /*[vlh] 3.4 */
putback(c);
clvalue = getfp(value);
return(CFLOAT);
}
putback(c);
if( value > 32767 || value < -32768 )
i++;
}
else if( peekis('x') || peekis('X') ) {
value = gethex();
if( value < 0 || value >= 0x10000L )
i++;
}
else {
if (peekis('.')) {
putback('.');
goto dofp;
}
value = getoct(0);
if( value < 0 || value >= 0x10000L )
i++;
}
if( peekis('l') || peekis('L') || i ) {
clvalue = value;
return(CLONG);
}
cvalue = value;
return(CINT);
case LCAROT: /*<=, <<, <<= or <*/
return( peekis('=') ? LESSEQ : peekis('<') ?
(peekis('=') ? EQLSH : LSH) : LESS );
case EQUAL: /*==, =<<, =>>, =+, ..., =*/
if( peekis('<') ) {
if( peekis('<') )
return(EQLSH);
}
else if( peekis('>') ) {
if( peekis('>') )
return(EQRSH);
}
else if( (i=index("=+-*/|&^%",(c=ngetch()))) >= 0 ) {
i = asmap[i];
if( i & SELFMOD ) {
if( (nextc=ngetch()) != ' ' )
if (!wflag) /*[vlh] old fashion initialization*/
error("=%c assumed",c);
putback(nextc);
}
return( i & ASMASK );
}
else
putback(c);
return(ASSIGN);
case RCAROT: /*>=, >>, >>= or >*/
return( peekis('=') ? GREATEQ : peekis('>') ?
(peekis('=') ? EQRSH : RSH) : GREAT );
case ALPHA: /*[A-Za-z][A-Za-z0-9]**/
p = &sym[0];
i = SSIZE;
for(; ctype[c] == ALPHA || ctype[c] == DIGIT; c=ngetch(),i-- )
if( i > 0 )
*p++ = c;
if( i > 0 )
*p = '\0';
putback(c);
csp = lookup(sym);
if( csp->s_attrib & SRESWORD ) {
cvalue = csp->s_offset;
return(RESWORD);
}
smember = 0;
return(SYMBOL);
case CAROT: /*^= or ^*/
return( peekis('=') ? EQXOR : XOR );
case BAR: /*|=, || or |*/
return( peekis('=') ? EQOR : peekis('|') ? LOR : OR );
}
}
return(EOF);
}
/*
* peekis - peeks at next character for specific character
* Gets next (possibly pushed back) character, if it matches
* the given character 1 is returned, otherwise the character
* is put back.
*/
peekis(tc) /* returns 1 if match, 0 otherwise*/
int tc; /* test character*/
{
register int c;
if( (c=ngetch()) == tc )
return(1);
putback(c);
return(0);
}
/* ngetch - get a possibly pushed back character*/
/* Checks pbchar variable, returns it if non-zero, handles counting*/
/* of new lines and whether you are in an include or not.*/
ngetch() /* returns character read or EOF*/
{
register int c;
register char *ifile;
if( pbchar ) {
c = pbchar;
pbchar = 0;
}
else if( (c=getc(&ibuf)) == EOLC ) {
if( inclflag )
inclflag = 0;
else
lineno++;
}
else if( c == SOI) { /*[vlh]add incl filename & line # */
inclflag++;
ifile = &inclfile;
while ((c=getc(&ibuf)) != SOI)
*ifile++ = c&0377;
*ifile = 0;
inclline = getdec() & 077777;
c = ' ';
}
else if( c < 0 )
c = EOF;
return(c);
}
/*
* peekc - peek at the next non-whitespace character after token
* This allows for the problem of having to look at two tokens
* at once. The second token is always a semi-colon or colon,
* so we only look at the single character, rather than going
* thru gettok.
*/
peekc(tc) /* returns 1 if match, 0 otherwise*/
int tc; /* character to look for*/
{
register int c;
while( ctype[(c=ngetch())] == WHITSP) ;
if( c == tc )
return(1);
putback(c);
return(0);
}
/* putback - puts back a single character*/
/* Checks pbchar for error condition.*/
putback(c) /* returns - none*/
int c;
{
if( pbchar )
error("too many chars pushed back");
else
pbchar = c;
}
/* getstr - get a quoted (single or double) character string*/
/* Gets specified number of characters, handling escapes.*/
getstr(str,nchars,endc) /* returns - none*/
char *str; /* pointer to string buffer*/
int nchars; /* max number of characters*/
char endc; /* ending string character*/
{
register char *p;
register int i;
register int c;
register int j;
cstrsize = 1;
p = str;
for( i = nchars; (c=ngetch()) != endc; i-- ) {
if( c == EOF || c == EOLC ) {
error("string cannot cross line");
break;
}
if( c == '\\' ) {
if( (c=ngetch()) >= '0' && c <= '7' ) {
putback(c);
if( (c=getoct(1)) < 0 || c > 255 ) {
error("bad character constant");
continue;
}
}
else if( (j=index("bnrt",c)) >= 0 )
c = escmap[j];
else if( c == EOLC ) /*escape followed by nl->ignore*/
continue;
}
if( i > 0 ) { /*room left in string?*/
cstrsize++;
*p++ = c;
}
else if( !i ) /*only say error once...*/
error("string too long");
}
if( i <= 0 ) /*string overflow?*/
p--;
*p = '\0';
}
/* syminit - initialize the symbol table, install reswords*/
/* Goes thru the resword table and installs them into the symbol*/
/* table.*/
syminit() /* returns - none*/
{
register struct resword *rp;
for( rp = &reswords[0]; rp->r_name != 0; rp++ )
install(rp->r_name,SRESWORD|SDEFINED,rp->r_value);
}
/* install - install a symbol in the symbol table*/
/* Allocates a symbol entry, copies info into it and links it*/
/* into the hash table chain.*/
char *install(sym,attrib,offset) /* returns pointer to symbol struct*/
char *sym; /* symbol to install*/
int attrib; /* attribues of symbol*/
int offset; /* symbol offset (resword value)*/
{
register struct symbol *sp;
register int i;
while( !(sp=symbols) ) {
if( !(sp=sbrk(SYMSIZE)) )
ferror("symbol table overflow");
for( i = SYMSIZE/(sizeof *symbols); --i >= 0; ) {
sp->s_next = symbols;
symbols = sp++;
}
}
symbols = sp->s_next;
sp->s_attrib = attrib;
sp->s_sc = 0; sp->s_type = 0; sp->s_dp = 0; sp->s_ssp = 0;
sp->s_offset = offset;
sp->s_struc = (instruct) ? strucptr[smember+instruct] : 0;
symcopy(sym,sp->s_symbol); /*copy symbol to symbol struct*/
i = symhash(sym,instruct|smember); /*link into chain list*/
sp->s_next = symtab[i];
symtab[i] = sp;
return(sp);
}
/* lookup - looks up a symbol in symbol table*/
/* Hashes symbol, then goes thru chain, if not found, then*/
/* installs the symbol.*/
char *lookup(sym) /* returns pointer to symbol buffer*/
char *sym; /* pointer to symbol*/
{
register struct symbol *sp, *hold;
register char *p;
int exact; /* same name, diff type or offset */
p = sym;
for( sp = symtab[symhash(p,0)]; sp != 0; sp = sp->s_next )
if((sp->s_attrib&(SRESWORD|STYPEDEF)) && symequal(p,sp->s_symbol))
return(sp);
if (!(smember|instruct)) { /*[vlh]*/
for( sp=symtab[symhash(p,0)]; sp!=0; sp=sp->s_next )
if( symequal(p,sp->s_symbol) ) return(sp);
}
else { /* doing a declaration or an expression */
hold = 0; exact = 0;
for( sp=symtab[symhash(p,instruct|smember)]; sp!=0; sp=sp->s_next )
if( symequal(p,sp->s_symbol) )
if (symsame(sp,hold,&exact)) return(sp);
else if (!hold && !exact) hold = sp;
if (hold && !exact) return(hold);
}
return(install(p,0,0));
}
/* freesyms - frees all local symbols at end of function declaration*/
/* Searches thru symbol table, deleting all symbols marked as locals*/
freesyms() /* returns - none*/
{
register int i, tinfo;
register struct symbol *sp, *tp, *nextp, **htp;
for( htp = &symtab[0], i = HSIZE; --i >= 0; htp++ )
for( tp = 0, sp = *htp; sp != 0; sp = nextp ) {
nextp = sp->s_next;
if( !(sp->s_attrib&SDEFINED) ) {
error("undefined label: %.8s",sp->s_symbol);
sp->s_attrib =| SDEFINED;
}
if( sp->s_attrib & (SGLOBAL|SRESWORD) )
tp = sp;
else {
if( tp )
tp->s_next = sp->s_next;
else
*htp = sp->s_next;
sp->s_next = symbols;
symbols = sp;
}
}
}
/* chksyms - checks symbol table for undefined symbols, etc.*/
/* Goes thru the symbol table checking for undeclared forward*/
/* referenced structures, and outputs local symbols for debugger.*/
chksyms() /* returns - none*/
{
register struct symbol **htp, *sp;
register int i, sc;
for( htp = &symtab[0], i = HSIZE; --i >= 0; htp++ )
for( sp = *htp; sp != 0; sp = sp->s_next ) {
sc = sp->s_sc;
if(sc!=0 && sp->s_ssp>=0 && (btype(sp->s_type))==FRSTRUCT) {
sp->s_ssp = frstab[sp->s_ssp]->s_ssp; /* 3.4 ssp>0 */
sp->s_type = (sp->s_type&~TYPE) | STRUCT;
}
if( sc == PDECLIST ) {
error("not in parameter list: %.8s",sp->s_symbol);
sp->s_sc = AUTO;
}
if( infunc )
outlocal(sp->s_type,sp->s_sc,sp->s_symbol,sp->s_offset);
}
}
/* symhash - compute hash value for symbol*/
/* Sums the symbols characters and takes that modulus the hash table*/
/* size.*/
symhash(sym,stel) /* returns hash value for symbol*/
char *sym; /* pointer to symbol*/
int stel; /* structure element flag*/
{
register char *p;
register int hashval, i;
hashval = (stel ? STEL : 0 );
for( p = sym, i = SSIZE; *p != '\0' && i > 0; i-- )
hashval =+ *p++;
return( hashval % HSIZE );
}
/* symequal - check for symbol equality*/
/* Does comparison between two symbols.*/
symequal(sym1,sym2) /* returns 1 if equal, 0 otherwise*/
char *sym1; /* pointer to first symbol*/
char *sym2; /* pointer to second symbol*/
{
register char *p, *q;
register int i;
for( p = sym1, q = sym2, i = SSIZE; *p == *q++; )
if( *p++ == '\0' || --i == 0 )
return(1);
return(0);
}
/* symsame - symbol member same as declared */
symsame(sp,hold,exact) /* [vlh] */
struct symbol *sp, *hold;
int *exact;
{
if (strucptr[smember+instruct])
if (strucptr[smember+instruct]==sp->s_struc) return(1);
if (hold)
if (sp->s_type != hold->s_type || sp->s_offset != hold->s_offset)
*exact = 1;
return(0);
}
/* symcopy - symbol copy*/
/* Copies one symbol to another.*/
symcopy(sym1,sym2) /* returns - none*/
char *sym1; /* pointer to symbol to copy*/
char *sym2; /* pointer to area to copy to*/
{
register char *p, *q;
register int i;
for( p = sym1, q = sym2, i = SSIZE; --i >= 0; )
*q++ = ( *p ? *p++ : '\0');
}
/* index - find the index of a character in a string*/
/* This is identical to Software Tools index.*/
index(str,chr) /* returns index of c in str or -1*/
char *str; /* pointer to string to search*/
char chr; /* character to search for*/
{
register char *s;
register int i;
for( s = str, i = 0; *s != '\0'; i++ )
if( *s++ == chr )
return(i);
return(-1);
}
/* next - if next token matches given token, skip and return success*/
/* This allows for clean parsing of declarations.*/
next(tok) /* returns 1 if matched, 0 otherwise*/
int tok;
{
register int token;
if( (token=gettok()) == tok )
return(1);
peektok = token;
return(0);
}
/* pbtok - put back the given token*/
/* This merely sets the peektok variable*/
pbtok(tok) /* returns - none*/
int tok;
{
if( peektok )
error("too many tokens pushed back");
peektok = tok;
}

View File

@@ -0,0 +1,6 @@
$1lo68 -r -f $1 -unofloat 0$1s.o DECL.o EXPR.o ICODE.o INTERF.o LEX.o MAIN.o STMT.o TABL.o 0$1lib6.a 0$1libF.a 0$1clib
era *.o
era c068.rel
ren c068.rel=c.out
user 13!make $1

View File

@@ -0,0 +1,39 @@
$ num
DECL.C
DECL.lis
$ num
EXPR.C
EXPR.lis
$ num
ICODE.C
ICODE.lis
$ num
INIT.C
INIT.lis
$ num
INTERF.C
INTERF.lis
$ num
LEX.C
LEX.lis
$ num
MAIN.C
MAIN.lis
$ num
STMT.C
STMT.lis
$ num
TABL.C
TABL.lis
$ num
VERSION.C
VERSION.lis
$ num
ICODE.H
ICODE.lst
$ num
MACHINE.H
MACHINE.lst
$ num
PARSER.H
PARSER.lst

View File

@@ -0,0 +1,10 @@
/*
* Use this file to determine what kind of machine you want the
* Alcyon stuff to run on ....
*/
/*#define MC68000 1*/ /* 68000 version */
/*#define VAX 1*/ /* VAX Version */
#define PDP11 1 /* PDP-11 Version*/
/*#define CPM 1*/ /* CP/M Operating System*/
#define UNIX 1 /* UNIX Operating System*/
/*#define VMS 1*/ /* VMS Operating System*/

View File

@@ -0,0 +1,10 @@
/*
* Use this file to determine what kind of machine you want the
* Alcyon stuff to run on ....
*/
#define MC68000 1 /* 68000 version */
/*#define VAX 1*/ /* VAX Version */
/*#define PDP11 1*/ /* PDP-11 Version*/
#define CPM 1 /* CP/M Operating System*/
/*#define UNIX 1*/ /* UNIX Operating System*/
/*#define VMS 1*/ /* VMS Operating System*/

View File

@@ -0,0 +1,10 @@
/*
* Use this file to determine what kind of machine you want the
* Alcyon stuff to run on ....
*/
/*#define MC68000 1*/ /* 68000 version */
#define VAX 1 /* VAX Version */
/*#define PDP11 1*/ /* PDP-11 Version*/
/*#define CPM 1*/ /* CP/M Operating System*/
/*#define UNIX 1*/ /* UNIX Operating System*/
#define VMS 1 /* VMS Operating System*/

View File

@@ -0,0 +1,10 @@
/*
* Use this file to determine what kind of machine you want the
* Alcyon stuff to run on ....
*/
/*#define MC68000 1*/ /* 68000 version */
#define VAX 1 /* VAX Version */
/*#define PDP11 1*/ /* PDP-11 Version*/
/*#define CPM 1*/ /* CP/M Operating System*/
/*#define UNIX 1*/ /* UNIX Operating System*/
#define VMS 1 /* VMS Operating System*/

View File

@@ -0,0 +1,173 @@
/*
Copyright 1982
Alcyon Corporation
8716 Production Ave.
San Diego, Ca. 92121
*/
char *version "@(#) c068 parser 4.0 - Feb 11, 1983";
/*
ALCYON C Compiler for the Motorola 68000 - Parser
Called from c68:
c068 source icode strings
source: input source code, preprocessed with comments stripped
icode: contains the intermediate code for the code generator,
for a detailed explanaion see ../doc/icode.
strings: contains all the string constants.
The basic structure of the parser is as follows:
main main driver for parser
syminit initializes symbol table
doextdef external definition syntax
getatt get type attributes
dlist declaration list for structures/unions
getatt recursive gettype call
dodecl do one declaration
declarator handle declarator syntax
dodecl do one external declaraion
initlist external initialization list
cexpr constant expressions
expr arithmetic expressions
maketree build operator tree
funcbody function body
dlist declaration list
stmt function statements
stmt recursive stmt call
expr arithmetic expressions
*/
#include "parser.h"
int nextlabel 1;
int lineno;
char *exprp &exprarea[0];
/*
* main - main routine for parser
* Checks arguments, opens input and output files, does main loop
* for external declarations and blocks.
*/
main(argc,argv) /* returns - none*/
int argc; /* argument count*/
char *argv[]; /* argument pointers*/
{
register char *q;
register int i;
for( i = 4; i < argc; i++ ) {
q = argv[i];
if( *q++ != '-' )
usage();
while( 1 ) {
switch( *q++ ) {
case 'F':
case 'f':
fflag++;
continue;
case 'E':
case 'e':
eflag++;
continue;
case 'W':
case 'w':
wflag++;
continue;
case '\0':
break;
default:
usage();
}
break;
}
}
if( argc < 4 )
usage();
if( fopen(argv[1],&ibuf,0) < 0 ) /* 3rd arg for versados */
ferror("can't open %s",argv[i]);
if( fcreat(argv[2],&obuf,0) < 0 || fcreat(argv[3],&sbuf,0) < 0 )
ferror("temp creation error");
obp = &obuf;
lineno++;
frstp = -1; /* [vlh] 3.4 - initialize only once */
syminit();
while( !peek(EOF) )
doextdef();
outeof();
outdata();
copysfile(argv[3]);
exit(errcnt!=0);
}
/* usage - output usage error message and die*/
usage()
{
ferror("usage: c068 source icode str [-e] [-f] [-w]");
}
/* error - report an error message*/
/* outputs current line number and error message*/
error(s,x1,x2,x3,x4,x5,x6) /* returns - none*/
char *s; /* error message*/
int x1, x2, x3, x4, x5, x6; /* args for printf*/
{
register char *savep;
savep = obp;
obp = 0;
errcnt++;
if (!inclflag) {
if( lineno )
printf("* %d: ",lineno);
}
else /*[vlh] generate filename and approp line #*/
printf("%s: * %d: ",inclfile,inclline);
printf(s,x1,x2,x3,x4,x5,x6);
printf("\n");
obp = savep;
}
/* ferror - fatal error*/
/* Outputs error message and exits*/
ferror(s,x1,x2,x3,x4,x5,x6) /* returns - none*/
char *s; /* error message*/
int x1, x2, x3, x4, x5, x6; /* args for printf*/
{
error(s,x1,x2,x3,x4,x5,x6);
exit(1);
}
v6flush(v6buf)
struct iobuf *v6buf;
{
register i;
i = BLEN - v6buf->nunused;
v6buf->nunused = BLEN;
v6buf->xfree = &(v6buf->buff[0]);
if(write(v6buf->fildes,v6buf->xfree,i) != i)
return(-1);
return(0);
}
printf(string,a,b,c,d,e,f,g)
char *string;
int a,b,c,d,e,f,g;
{
char area[256];
register char *p;
sprintf(area,string,a,b,c,d,e,f,g);
for(p = &area[0]; *p; p++)
putchar(*p);
}

View File

@@ -0,0 +1,86 @@
$1stat machine.h=rw
$1pip machine.h=machine.68k
$1cp68 -i 0$1 DECL.c $1x.i
$1c068 $1x.i $1x.ic $1x.st -f
$1c168 $1x.ic DECL.s -LD
era $1x.i
era $1x.ic
era $1x.st
$1as68 -s 0$1 -f $1 -l -u DECL.s
era DECL.s
$1cp68 -i 0$1 EXPR.c $1x.i
$1c068 $1x.i $1x.ic $1x.st -f
$1c168 $1x.ic EXPR.s -LD
era $1x.i
era $1x.ic
era $1x.st
$1as68 -s 0$1 -f $1 -l -u EXPR.s
era EXPR.s
$1cp68 -i 0$1 ICODE.c $1x.i
$1c068 $1x.i $1x.ic $1x.st -f
$1c168 $1x.ic ICODE.s -LD
era $1x.i
era $1x.ic
era $1x.st
$1as68 -s 0$1 -f $1 -l -u ICODE.s
era ICODE.s
$1cp68 -i 0$1 INTERF.c $1x.i
$1c068 $1x.i $1x.ic $1x.st -f
$1c168 $1x.ic INTERF.s -LD
era $1x.i
era $1x.ic
era $1x.st
$1as68 -s 0$1 -f $1 -l -u INTERF.s
era INTERF.s
$1cp68 -i 0$1 LEX.c $1x.i
$1c068 $1x.i $1x.ic $1x.st -f
$1c168 $1x.ic LEX.s -LD
era $1x.i
era $1x.ic
era $1x.st
$1as68 -s 0$1 -f $1 -l -u LEX.s
era LEX.s
$1cp68 -i 0$1 MAIN.c $1x.i
$1c068 $1x.i $1x.ic $1x.st -f
$1c168 $1x.ic MAIN.s -LD
era $1x.i
era $1x.ic
era $1x.st
$1as68 -s 0$1 -f $1 -l -u MAIN.s
era MAIN.s
$1cp68 -i 0$1 STMT.c $1x.i
$1c068 $1x.i $1x.ic $1x.st -f
$1c168 $1x.ic STMT.s -LD
era $1x.i
era $1x.ic
era $1x.st
$1as68 -s 0$1 -f $1 -l -u STMT.s
era STMT.s
$1cp68 -i 0$1 TABL.c $1x.i
$1c068 $1x.i $1x.ic $1x.st -f
$1c168 $1x.ic TABL.s -LD
era $1x.i
era $1x.ic
era $1x.st
$1as68 -s 0$1 -f $1 -l -u TABL.s
era TABL.s
$1cp68 -i 0$1 VERSION.c $1x.i
$1c068 $1x.i $1x.ic $1x.st -f
$1c168 $1x.ic VERSION.s -LD
era $1x.i
era $1x.ic
era $1x.st
$1as68 -s 0$1 -f $1 -l -u VERSION.s
era VERSION.s
link $1

View File

@@ -0,0 +1,320 @@
/*
Copyright 1982
Alcyon Corporation
8716 Production Ave.
San Diego, Ca. 92121
*/
/*
C68 Parser - include file
*/
#include <stdio.h>
#include <klib.h>
#undef putchar
#define putchar xputchar
#undef ferror
#define printf xprintf
#include "icode.h"
/*symbol attribute fields*/
#define SRESWORD 001 /*is symbol a reserved word?*/
#define SGLOBAL 002 /*is symbol global?*/
#define STYPEDEF 004 /*typedef declaration?*/
#define SDEFINED 010 /*symbol defined?*/
/*reserved words*/
#define R_AUTO 1
#define R_BREAK 2
#define R_CASE 3
#define R_CHAR 4
#define R_CONTINUE 5
#define R_DO 6
#define R_DEFAULT 7
#define R_DOUBLE 8
#define R_GOTO 9
#define R_ELSE 10
#define R_EXTERNAL 11
#define R_FLOAT 12
#define R_FOR 13
#define R_IF 14
#define R_INT 15
#define R_LONG 16
#define R_REGISTER 17
#define R_RETURN 18
#define R_SHORT 19
#define R_SIZEOF 20
#define R_STATIC 21
#define R_STRUCT 22
#define R_SWITCH 23
#define R_TYPEDEF 24
#define R_UNION 25
#define R_UNSIGNED 26
#define R_WHILE 27
/*
* mixed-mode conversions, entries in 2-d array indexed by:
* (int,unsn,long,doub,ptr)
*/
#define INT_CHAR 1
#define UNSN_CHAR 1
#define LONG_CHAR 1
#define DOUB_CHAR 1
#define PTR_CHAR 1
#define INT_UNSN 0 /*no conversion is generated*/
#define INT_LONG 2
#define INT_DOUB 3
#define INT_PTR 4
#define UNSN_INT 0 /*no conversion is generated*/
#define UNSN_LONG 6
#define UNSN_DOUB 7
#define UNSN_PTR 8
#define LONG_INT 9
#define LONG_UNSN 10
#define LONG_DOUB 11
#define LONG_PTR 12
#define DOUB_INT 13
#define DOUB_UNSN 14
#define DOUB_LONG 15
#define PTR_INT 16
#define PTR_UNSN 17
#define PTR_LONG 18
#define PTR_PTR 19
#define BADCONV 20
/* miscellaneous constants */
#define OPSSIZE 40 /*operator stack size*/
#define OPDSIZE 80 /*operand stack size*/
#define HSIZE 517 /*hash table size, 3.4 made prime */
#define SYMSIZE 1024 /*size to alloc for symbol structures*/
#define SWSIZE 256 /*max no. of cases in a switch*/
#define DSIZE 1000 /*dimension table size*/
#define BITSPWORD 16 /*bits per word*/
#define AREGLO 010 /*A reg flag*/
#define HICREG 2 /*highest reg # used for code generation*/
#define BITSPCHAR 8 /*bits per char*/
#define CHRSPWORD 2 /*chars per word*/
#define STRSIZE 300 /*max string length*/
#define NFARGS 40 /*max no. of args to function*/
#define NFRSTR 20 /*max no. of forward ref struct proto*/
/*symbol table node*/
struct symbol {
char s_attrib; /* defined, resword, global, typedef */
char s_sc; /* auto, static, external, register */
int s_type; /* 4bits specified, 2 bit fields for ptr... */
int s_dp; /* index into dimension table */
int s_ssp; /* dimension table/function arg table */
int s_offset; /* offset inside of structure */
char s_symbol[SSIZE]; /* symbol identifier, to SSIZE chars */
struct symbol *s_struc; /* if struct, ptr to parent (sys III) */
struct symbol *s_next; /* next symbol table entry */
};
/*expression tree operator node*/
struct tnode {
int t_op;
int t_type;
int t_dp;
int t_ssp;
struct tnode *t_left;
struct tnode *t_right;
};
/*expression tree node for symbol - only keeps location*/
struct symnode {
int t_op;
int t_type; /*data type of symbol*/
int t_dp; /*dimension pointer of symbol*/
int t_ssp; /*structure size index to dtab*/
int t_sc; /*storage class of symbol*/
int t_offset; /*offset of symbol*/
int t_label;
};
/*expressioon tree node for external symbol - need to keep name*/
struct extnode {
int t_op;
int t_type;
int t_dp;
int t_ssp;
int t_sc;
int t_offset;
int t_reg;
int t_symbol[SSIZE]; /*symbol name*/
};
/*expression tree node for integer constant*/
struct conode {
int t_op;
int t_type;
int t_dp;
int t_ssp;
int t_value; /*constant value*/
};
struct lconode {
int t_op;
int t_type;
int t_dp;
int t_ssp;
long t_lvalue; /*constant value*/
};
struct swtch {
int sw_label;
int sw_value;
} swtab[SWSIZE];
/*operator and operand stack used by expr*/
struct ops { /*operator stack*/
int o_op; /*operator*/
int o_pri; /*priority*/
} opstack[OPSSIZE], *opp;
char *opdstack[OPDSIZE]; /*operand stack*/
char **opdp; /*operand stack pointer*/
char *opap; /*ptr to next available loc in exprarea*/
char *exprp; /*place to start building expression*/
int opinfo[]; /*operator info table*/
struct tnode *frp; /*pointer to function return info node*/
int swp; /*current entry in switch table*/
int cswp; /*current low switch table index*/
int nextlabel; /*generates unique label numbers*/
int clabel; /*continue label*/
int blabel; /*break label*/
int rlabel; /*return label*/
int dlabel; /*default label*/
int lineno; /*current line number of input*/
int errcnt; /*count of errors*/
int inclflag; /*in include file, don't incr line #'s*/
int inclline; /*[vlh]line# in incl file for err rpting*/
char inclfile[13]; /*[vlh]include filename for err rpting*/
int equalstop; /*stop lex at '=', used for external init*/
int commastop; /*stop parse @ comma(used for const expr)*/
int colonstop; /*stop parse @ colon(used for case value)*/
int instruct; /*set when in structure declaration*/
int smember; /*set when seen . or ->*/
int infunc; /*set when in function body*/
int tdflag; /*declaration is a typedef proto*/
char *tdp; /*points to typedef prototype*/
int localsize; /*length of local variables*/
int naregs; /*keeps track of ptr registers alloc'd*/
int ndregs; /*keep track of data registers alloc'd*/
int loadreg; /*need to load registers...*/
int boffset; /*current bit offset in structure*/
int eflag; /*[vlh] 3.4 IEEE floats */
int fflag; /*[vlh] 3.4 FFP floats */
int xflag; /*translate int's to long's*/
int wflag; /*[vlh] don't generate warning mesgs*/
int reducep; /*[vlh] if(procid); reduction*/
int peektok; /*peeked at token*/
/*dimension table*/
long dtab[DSIZE]; /* [vlh] 3.4 int => long */
int cdp; /*next entry in dtab to alloc*/
/*lexical analyzer values*/
int cvalue; /*current token value if keyword or CINT*/
int cstrsize; /*current string size*/
long clvalue; /*current token value if long constant*/
struct symbol *csp; /*current token symbol ptr if SYMBOL*/
char cstr[STRSIZE]; /*current token value if CSTRING*/
struct symbol *dsp; /*declarator symbol pointer*/
/* -1 -> not instruct, 0 -> unnamed struct */
struct symbol *strucptr[10]; /*[vlh] ptrs to struc symbols*/
/*function argument table, used to collect function parameters*/
struct farg {
struct symbol *f_sp;
int f_offset;
} fargtab[NFARGS];
/*forward referenced structure prototype names*/
struct symbol *frstab[NFRSTR];
int frstp;
/*output buffers for intermediate code and strings*/
struct io_buf obuf, sbuf, ibuf, *obp;
#define stypedef(sp) (sp->s_attrib&STYPEDEF)
#define walign(add) ((add+1)&(~1))
#define array(type) ((type&SUPTYP)==ARRAY)
#define function(type) ((type&SUPTYP)==FUNCTION)
#define pointer(type) ((type&SUPTYP)==POINTER)
#define notarray(type) ((type&SUPTYP)!=ARRAY)
#define notfunction(type) ((type&SUPTYP)!=FUNCTION)
#define notpointer(type) ((type&SUPTYP)!=POINTER)
#define btype(type) (type&TYPE)
#define suptype(type) (type&SUPTYP)
#define alltype(type) (type&(SUPTYP|TYPE))
#define asgop(op) ((opinfo[op]&OPASSIGN)!=0)
#define relop(op) ((opinfo[op]&OPREL)!=0)
#define lintegral(op) ((opinfo[op]&OPLWORD)!=0)
#define rintegral(op) ((opinfo[op]&OPRWORD)!=0)
#define rasop(op) ((opinfo[op]&OPRAS)!=0)
#define binop(op) ((opinfo[op]&OPBIN)!=0)
#define unaryop(op) ((opinfo[op]&OPBIN)==0)
#define leaf(op) ((opinfo[op]&OPTERM)!=0)
#define lvalop(op) ((opinfo[op]&OPLVAL)!=0)
#define oppriority(op) (opinfo[op]&OPPRI)
#define makeiop(op) (op|(0254<<8))
/* checks for symbol with structure element storage class */
#define isstel(tp) (tp->t_op==SYMBOL && (sesc(tp)))
#define sesc(t) (t->t_sc==STELCL||t->t_sc==UNELCL||t->t_sc==BFIELDCL)
/* peek at next token, if not read token put back, else delete */
/* 1 if matched, 0 otherwise */
#define peek(tok) ( (peektok=gettok()) == tok )
#define outcommon(sym,size) printf("\t.comm _%.8s,%ld\n",sym,size)
#define outgoto(lab) if( lab > 0 ) printf("\tbra L%d\n",lab)
/* change to text segment */
#define outtext() printf("\t.text\n")
/* change segment to bss */
#define outbss() printf("\t.bss\n")
/* output global symbol references */
#define outextdef(sym) printf("\t.globl _%.8s\n",sym)
/* outputs reserved memory [vlh] 3.4 %d => %ld */
#define outresmem(size) printf("\t.ds.b %ld\n",size)
/* output padding for word alignments */
#define outpad() printf("\t.even\n")
/* output long constant to assembler */
#define outlcon(val) printf("\t.dc.l %d\n",val)
/* output label constant */
#define outclab(lab) printf("\t.dc.l L%d\n",lab)
/* output a label */
#define outlab(lab) printf("\tL%d:",lab)
/* output function label */
#define outflab(sym) printf("\t_%.8s:\n\t~~%.8s:\n",sym,sym)
/* output data label */
#define outdlab(sym) printf("\t_%.8s:\n",sym)
/*functions returning pointers*/
char *expr();
char *talloc();
char *tnalloc();
char *enalloc();
char *snalloc();
char *cnalloc();
char *lcnalloc();
char *fpcnalloc();
char *popopd();
char *cvopgen();
char *arrayref();
char *funcref();
char *install();
char *lookup();
char *balpar();
char *sbrk();
long initlist();
long dsize();
long psize();
long dodecl();
long dlist();
long getdec();
long gethex();
long getoct();
long getfp();
long toieee();
long toffp();

View File

@@ -0,0 +1,16 @@
e:send DECL.C
e:send EXPR.C
e:send ICODE.C
e:send INTERF.C
e:send LEX.C
e:send MAIN.C
e:send STMT.C
e:send TABL.C
e:send VERSION.C
e:send ICODE.H
e:send PARSER.H
e:send MACHINE.68K
e:send LINK.SUB
e:send MAKE.SUB
e:send MACHINE.H
e:send SEND12.SU

View File

@@ -0,0 +1,507 @@
/*
Copyright 1982
Alcyon Corporation
8716 Production Ave.
San Diego, Ca. 92121
*/
#include "parser.h"
#define labgen(l,sl) sl=l;l=nextlabel++;
int swp -1;
/* stmt - process a single statement*/
stmt() /* returns - none*/
{
register int token, lab, i;
register struct tnode *tp;
register char *p;
while( 1 ) {
switch(token=gettok()) {
case LCURBR: /*handle { ... }*/
while( !next(EOF) ) {
if( next(RCURBR) )
return;
stmt();
}
case EOF:
error("{ not matched by }");
case SEMI: /*null statement*/
return;
case RCURBR:
pbtok(token);
return;
case SYMBOL: /*symbol: statement*/
if( peekc(':') ) {
dolabel();
continue;
}
default: /*anything else...*/
pbtok(token);
outexpr(expr());
break;
case RESWORD:
switch(cvalue) {
case R_BREAK:
lab = brklabel();
outgoto(lab); /*branch to break label*/
break;
case R_CASE:
docase();
continue;
case R_CONTINUE:
lab = contlabel(); /*branch to continue label*/
outgoto(lab);
break;
case R_DEFAULT:
dodefault();
continue;
case R_DO:
dodo();
break;
case R_FOR:
dofor();
return;
case R_GOTO:
lab = gotolabel();
outgoto(lab);
break;
case R_IF:
doif();
return;
case R_RETURN:
doreturn();
break;
case R_SWITCH:
doswitch();
return;
case R_WHILE:
dowhile();
return;
default:
synerr("invalid keyword");
return;
}
}
if( !next(SEMI) )
synerr("missing semicolon");
return;
}
}
/* balpar - handle expression within parenthesis for while and if*/
/* Merely checks for left and right parens and builds expression.*/
char *balpar() /* returns pointer to expression*/
{
register struct tnode *tp;
if( next(LPAREN) ) {
reducep = 1;
tp = expr();
reducep = 0;
if( next(RPAREN) )
return(tp);
}
synerr("parenthesized expression syntax");
return(0);
}
/* synerr - syntax error*/
/* Outputs error message and tries to resyncronize input.*/
synerr(s,x1,x2,x3,x4,x5,x6) /* returns - none*/
char *s; /* printf format string*/
int x1, x2, x3, x4, x5, x6; /* printf arguments*/
{
register int token;
error(s,x1,x2,x3,x4,x5,x6);
while( (token=gettok()) != SEMI && token != EOF && token != LCURBR &&
token != RCURBR )
;
pbtok(token);
}
/* gotolabel - gets label id for goto*/
/* This is used for both: goto symbol and if(...)goto symbol*/
gotolabel() /* returns 0 if not, else label id*/
{
register struct symbol *sp;
if( !next(SYMBOL) )
synerr("expected label");
else {
sp = csp;
if( !(sp->s_sc) ) {
sp->s_type = LLABEL;
if( !sp->s_offset )
sp->s_offset = nextlabel++;
}
if( (!sp->s_sc || sp->s_sc == STATIC ) && sp->s_type == LLABEL )
return(sp->s_offset);
synerr("invalid label");
}
return(0);
}
/* dolabel - do statement label*/
/* Checks current symbol for already being defined, then sets*/
/* symbol attributes for label.*/
dolabel() /* returns - none*/
{
register struct symbol *sp;
sp = csp;
if( sp->s_sc )
error("label redeclaration: %.8s",sp->s_symbol);
else {
sp->s_attrib =| SDEFINED;
sp->s_sc = STATIC;
sp->s_type = LLABEL;
if( !sp->s_offset )
sp->s_offset = nextlabel++;
outlab(sp->s_offset);
}
}
/* brklabel - generate break label*/
/* Checks if break label is undefined, and if so, generates message*/
brklabel() /* returns label number*/
{
if( !blabel )
error("invalid break statement");
return(blabel);
}
/* contlabel - generate continue label*/
/* Checks if continue label is undefined, and if so, generates message*/
contlabel() /* returns label number*/
{
if( !clabel )
error("invalid continue statement");
return(clabel);
}
/* docase - handles: case constant : statement*/
/* Checks for being in a switch statement, adds entry to switch table*/
docase() /* returns - none*/
{
register int value, lab;
colonstop++;
value = cexpr(); /*get case value*/
colonstop--;
if( !next(COLON) ) /*check for colon*/
synerr("missing colon");
if( swp < 0 )
error("case not inside a switch block");
else if( swp >= (SWSIZE-1) )
error("too many cases in switch");
else {
addswitch(&swtab[cswp],swp-cswp,value,lab=nextlabel++);
outlab(lab);
swp++;
}
}
/* dodefault - handles: default : statement*/
/* Checks for colon and being in a switch statement*/
dodefault() /* returns - none*/
{
if( !next(COLON) )
error("missing colon");
if( swp < 0 )
error("default not inside a switch block");
else {
dlabel = nextlabel++; /*allocate default label*/
outlab(dlabel); /*output default label*/
}
}
/* dodo - handles: do statement while ( expression )*/
dodo() /* returns - none*/
{
register int lab, saveblab, saveclab;
labgen(blabel,saveblab);
labgen(clabel,saveclab);
lab = nextlabel++;
outlab(lab); /*branch back to here*/
stmt(); /*do statement*/
outlab(clabel); /*continue label*/
if( !nextrw(R_WHILE) ) {
error("missing while"); /*only advisory...*/
outgoto(lab);
}
else
outifgoto(balpar(),TRUE,lab); /*while expression*/
outlab(blabel); /*break label*/
blabel = saveblab; /*restore labels*/
clabel = saveclab;
}
/*
* dofor - handle: for ( expression ; expression ; expression ) statement
* Hard part is handling re-initialization expression, which is
* parsed and saved, then the statement is parsed, then the reinit
* clause expression tree is output.
*/
dofor() /* returns - none*/
{
register int lab, saveblab, saveclab, reinit, clineno;
register char *savep;
register struct tnode *tp;
labgen(blabel,saveblab);
labgen(clabel,saveclab);
if( !next(LPAREN) ) {
forerr:
synerr("invalid for statement");
return;
}
if( !next(SEMI) ) { /*do init expression*/
outexpr(expr());
if( !next(SEMI) )
goto forerr;
}
outlab(clabel); /*branch back to here*/
if( !next(SEMI) ) { /*do for condition*/
outifgoto(expr(),FALSE,blabel);
if( !next(SEMI) )
goto forerr;
}
if( next(RPAREN) ) { /*no re-init - easy case*/
stmt(); /*output statement*/
outgoto(clabel); /*output continue label*/
}
else { /*there is a re-init clause*/
labgen(clabel,lab);
savep = exprp;
tp = expr(); /*save re-init tree until done*/
exprp = opap; /*remember until reinit is output*/
reinit = lineno;
if( !next(RPAREN) )
goto forerr;
stmt(); /*do statment*/
clineno = lineno;
lineno = reinit;
outlab(clabel); /*we branch to here for reinit*/
outexpr(tp); /*output re-init clause*/
exprp = savep;
lineno = clineno;
outgoto(lab); /*branch back to top of loop*/
}
outlab(blabel); /*break to here*/
blabel = saveblab;
clabel = saveclab; /*restore labels*/
}
/* doif - handles: if ( expression ) statement [ else statement ]*/
/* Handles special cases for goto, break, continue and return.*/
doif() /* returns - none*/
{
register struct tnode *tp;
register int elselab, exitlab;
tp = balpar(); /*if( expr )...*/
exitlab = 0;
if( nextrw(R_GOTO) )
exitlab = gotolabel();
else if( nextrw(R_BREAK) )
exitlab = brklabel();
else if( nextrw(R_CONTINUE) )
exitlab = contlabel();
else if( nextrw(R_RETURN) ) {
if( peekc(';') ) {
exitlab = rlabel;
putback(';');
}
else
pbtok(RESWORD);
}
if( exitlab ) { /*easy goto, do branch if true*/
outifgoto(tp,TRUE,exitlab);
if( !next(SEMI) )
synerr("missing semicolon");
if( nextrw(R_ELSE) ) /*else clause, just output it*/
stmt();
}
else { /*hard goto, branch over statement*/
elselab = nextlabel++;
outifgoto(tp,FALSE,elselab);
stmt();
if( nextrw(R_ELSE) ) {
exitlab = nextlabel++; /*branches over else clause*/
outgoto(exitlab); /*branch out of then clause*/
outlab(elselab); /*label to start else clause*/
stmt(); /*else statement*/
outlab(exitlab);
}
else
outlab(elselab); /*no else, just branch out*/
}
}
/*
* doreturn - handles: return [ expression ] ;
* Expression is the hard part, must create an assignment expression
* to assign expression to the type of the function, then get it
* loaded into a specific register.
*/
doreturn() /* returns - none*/
{
register struct tnode *tp;
if( !peekc(';') ) /*need to compute return?*/
outforreg(FRETURN,frp,expr());
else
putback(';');
outgoto(rlabel); /*branch to the return label*/
}
/*
* doswitch - handles: switch ( expression ) statement
* Evaluates the expression, forces the result into a known register
* collects the case statements in swtab, then outputs the switch
* operator and switch cases.
*/
doswitch() /* returns - none*/
{
register int saveblab, swlab, savedlab, saveswp, i;
register struct tnode *tp;
labgen(blabel,saveblab);
tp = balpar();
integral(tp,-1); /*must be integral type result*/
outforreg(ASSIGN,snalloc(INT,AUTO,0,0,0),tp);
saveswp = swp; /*remember old switch pointer*/
if( saveswp < 0 )
swp++;
i = cswp;
cswp = swp; /*remember real first entry*/
swlab = nextlabel++;
outgoto(swlab); /*branch to switch code*/
savedlab = dlabel;
dlabel = 0;
stmt(); /*do switch statement*/
outgoto(blabel); /*output branch just in case*/
outlab(swlab); /*here we now do the switch code*/
if( !dlabel )
dlabel = blabel;
outswitch(swp-cswp,dlabel,&swtab[cswp]);
outlab(blabel); /*break to here*/
cswp = i;
swp = saveswp;
blabel = saveblab;
dlabel = savedlab;
}
/* dowhile - handles: while ( expression ) statement*/
/* This is fairly straight-forward.*/
dowhile() /* returns - none*/
{
register int saveclab, saveblab;
labgen(blabel,saveblab);
labgen(clabel,saveclab);
outlab(clabel); /*continue label*/
outifgoto(balpar(),FALSE,blabel); /*condition clause*/
stmt(); /*statement*/
outgoto(clabel); /*branch back to top of loop*/
outlab(blabel); /*break to here*/
blabel = saveblab;
clabel = saveclab; /*restore labels*/
}
/* nextrw - is next token the specified reserved word?*/
nextrw(rw) /* returns 1 if match, 0 otherwise*/
int rw; /* reserved word to match*/
{
register int token;
if( (token=gettok()) != RESWORD || cvalue != rw ) {
pbtok(token);
return(0);
}
return(1);
}
/*
* addswitch - add an entry into current switch table, bubble sorting
* This makes it easier on the code generator and also checks for
* duplicate labels at the "right" time.
*/
addswitch(sp,ncases,nval,nlab) /* returns - none*/
struct swtch *sp; /* switch table pointer*/
int ncases; /* number of cases in switch*/
int nval; /* new value*/
int nlab; /* new label*/
{
register struct swtch *nswp, *s;
register int temp, i;
nswp = &sp[ncases];
nswp->sw_value = nval;
nswp->sw_label = nlab;
s = nswp--;
for( ; --ncases >= 0; s--, nswp-- ) {
if( s->sw_value == nswp->sw_value )
error("duplicate case value");
if( s->sw_value < nswp->sw_value ) {
temp = s->sw_value;
s->sw_value = nswp->sw_value;
nswp->sw_value = temp;
temp = s->sw_label;
s->sw_label = nswp->sw_label;
nswp->sw_label = temp;
}
}
}
/* outforreg - generate assignment for switch and return*/
outforreg(op,ltp,rtp) /*returns - none*/
int op; /*operator for build tree*/
struct tnode *ltp; /*left expression tree*/
struct tnode *rtp; /*right expression tree*/
{
register struct tnode *tp;
opp = opstack;
opdp = opdstack;
pushopd(ltp);
pushopd(rtp);
maketree(op);
if( tp = popopd() )
outcforreg(tp->t_right);
opp = opdp = 0;
}
/* outassign - generate assignment for function args*/
outassign(ltp,rtp) /*returns - none*/
struct tnode *ltp; /*left expression tree*/
struct tnode *rtp; /*right expression tree*/
{
opp = opstack;
opdp = opdstack;
pushopd(ltp);
pushopd(rtp);
maketree(ASSIGN);
outexpr(popopd());
opp = opdp = 0;
}

View File

@@ -0,0 +1,119 @@
/*
Copyright 1982
Alcyon Corporation
8716 Production Ave.
San Diego, Ca. 92121
*/
#include "parser.h"
#define ASGOP OPRAS|OPASSIGN|OPLVAL|OPBIN
/*info on operators:*/
/*000077-- OPPRI - priority*/
/*000100-- OPBIN - binary operator*/
/*000200-- OPLVAL - left operand must be lvalue*/
/*000400-- OPREL - relational operator*/
/*001000-- OPASSIGN - assignment operator*/
/*002000-- OPLWORD - int required on left*/
/*004000-- OPRWORD - int required on right*/
/*010000-- OPCOM commutative*/
/*020000-- OPRAS - right associative*/
/*040000-- OPTERM - termination node*/
/*100000 - OPCONVS - conversion operator*/
int opinfo[] {
TRMPRI, /*EOF*/
ADDPRI|OPCOM|OPBIN, /*ADD - expr + expr*/
ADDPRI|OPBIN, /*SUB - expr - expr*/
MULPRI|OPCOM|OPBIN, /*MULT - expr * expr*/
MULPRI|OPBIN, /*DIV - expr / expr*/
MULPRI|OPBIN, /*MOD - expr % expr*/
SHFPRI|OPLWORD|OPRWORD|OPBIN, /*RSH - expr >> expr*/
SHFPRI|OPLWORD|OPRWORD|OPBIN, /*LSH - expr << expr*/
ANDPRI|OPCOM|OPLWORD|OPRWORD|OPBIN, /*AND - expr & expr*/
ORPRI|OPCOM|OPLWORD|OPRWORD|OPBIN, /*OR - expr | expr*/
ORPRI|OPCOM|OPLWORD|OPRWORD|OPBIN, /*XOR - expr ^ expr*/
UNOPRI|OPRAS|OPLWORD, /*NOT - ! expr*/
UNOPRI|OPRAS, /*UMINUS - - expr*/
UNOPRI|OPRAS|OPLWORD, /*COMPL - ~ expr*/
UNOPRI|OPRAS|OPLVAL|OPBIN, /*PREDEC - --lvalue*/
UNOPRI|OPRAS|OPLVAL|OPBIN, /*PREINC - ++lvalue*/
UNOPRI|OPRAS|OPLVAL|OPBIN, /*POSTDEC - lvalue--*/
UNOPRI|OPRAS|OPLVAL|OPBIN, /*POSTINC - lvalue++*/
ASGPRI|ASGOP, /*ASSIGN - lvalue = expr*/
ASGPRI|ASGOP, /*EQADD - lvalue += expr*/
ASGPRI|ASGOP, /*EQSUB - lvalue -= expr*/
ASGPRI|ASGOP, /*EQMULT - lvalue *= expr*/
ASGPRI|ASGOP, /*EQDIV - lvalue /= expr*/
ASGPRI|ASGOP, /*EQMOD - lvalue %= expr*/
ASGPRI|ASGOP|OPLWORD|OPRWORD, /*EQRSH - lvalue >>= expr*/
ASGPRI|ASGOP|OPLWORD|OPRWORD, /*EQLSH - lvalue <<= expr*/
ASGPRI|ASGOP|OPLWORD|OPRWORD, /*EQAND - lvalue &= expr*/
ASGPRI|ASGOP|OPLWORD|OPRWORD, /*EQOR - lvalue |= expr*/
ASGPRI|ASGOP|OPLWORD|OPRWORD, /*EQXOR - lvalue ^= expr*/
TRMPRI, /*FJSR - generate function jsr*/
EQLPRI|OPREL|OPBIN, /*EQUALS - expr == expr*/
EQLPRI|OPREL|OPBIN, /*NEQUALS - expr != expr*/
RELPRI|OPREL|OPBIN, /*GREAT - expr > expr*/
RELPRI|OPREL|OPBIN, /*GREATEQ - expr >= expr*/
RELPRI|OPREL|OPBIN, /*LESS - expr < expr*/
RELPRI|OPREL|OPBIN, /*LESSEQ - expr <= expr*/
TRMPRI|OPCONVS, /*INT2L*/
TRMPRI|OPCONVS, /*LONG2I*/
TRMPRI|OPBIN, /*BTST*/
TRMPRI, /*LOAD*/
TRMPRI|OPBIN, /*LMULT*/
TRMPRI|OPBIN, /*LDIV*/
TRMPRI|OPBIN, /*LMOD*/
TRMPRI|OPBIN, /*LEQMULT*/
TRMPRI|OPBIN, /*LEQDIV*/
TRMPRI|OPBIN, /*LEQMOD*/
TRMPRI|ASGOP, /*EQADDR*/
TRMPRI, /*EQNOT*/
TRMPRI, /*EQNEG*/
TRMPRI|OPBIN, /*DOCAST*/
ASGPRI|ASGOP, /*STASSIGN [vlh]*/
TRMPRI|OPCONVS, /*LONG2F [vlh] 3.4*/
TRMPRI|OPCONVS, /*FLOAT2L [vlh] 3.4*/
TRMPRI|OPCONVS, /*INT2F [vlh] 3.4*/
TRMPRI|OPCONVS, /*FLOAT2F [vlh] 3.4*/
TRMPRI, /*unused - 55*/
TRMPRI, /*unused - 56*/
TRMPRI, /*unused - 57*/
TRMPRI, /*unused - 58*/
TRMPRI, /*unused - 59*/
UNOPRI|OPRAS|OPLVAL, /*ADDR - & expr*/
UNOPRI|OPRAS|OPLWORD, /*INDR - * expr*/
LNDPRI|OPBIN, /*LAND - expr && expr*/
LORPRI|OPBIN, /*LOR - expr || expr*/
QMKPRI|OPRAS|OPBIN, /*QMARK - expr ? expr : expr*/
QMKPRI|OPRAS|OPBIN, /*COLON*/
COMPRI|OPBIN, /*COMMA*/
TRMPRI|OPTERM, /*CINT*/
TRMPRI|OPTERM, /*CLONG*/
TRMPRI|OPTERM, /*SYMBOL*/
TRMPRI|OPTERM, /*AUTOINC*/
TRMPRI|OPTERM, /*AUTODEC*/
LPNPRI|OPBIN, /*CALL - call with arguments*/
LPNPRI, /*NACALL - no argument call*/
TRMPRI, /*BFIELD - field selection*/
TRMPRI, /*IFGOTO*/
TRMPRI, /*INIT*/
TRMPRI, /*CFORREG*/
TRMPRI, /*unused - 78*/
TRMPRI|OPTERM, /*CFLOAT [vlh] 3.4*/
UNOPRI|OPRAS|OPASSIGN|OPBIN, /*CAST*/
TRMPRI, /*SEMI*/
TRMPRI, /*LCURBR - {*/
TRMPRI, /*RCURBR - }*/
LPNPRI, /*LBRACK - [*/
RPNPRI, /*RBRACK - ]*/
LPNPRI, /*LPAREN - )*/
RPNPRI, /*RPAREN - )*/
TRMPRI|OPTERM, /*STRING*/
TRMPRI, /*RESWORD*/
LPNPRI|OPBIN, /*APTR - expr -> symbol*/
LPNPRI|OPBIN, /*PERIOD - expr . symbol*/
UNOPRI|OPRAS, /*SIZEOF - sizeof expr*/
LPNPRI|OPBIN, /*MPARENS - matching parens ()*/
UNOPRI|OPRAS|OPASSIGN|OPBIN, /*FRETURN*/
};

View File

@@ -0,0 +1,16 @@
e:vax DECL.C s
e:vax EXPR.C s
e:vax ICODE.C s
e:vax INTERF.C s
e:vax LEX.C s
e:vax MAIN.C s
e:vax STMT.C s
e:vax TABL.C s
e:vax VERSION.C s
e:vax ICODE.H s
e:vax PARSER.H s
e:vax MACHINE.68K s
e:vax LINK.SUB s
e:vax MAKE.SUB s
e:vax MACHINE.H s
e:vax SEND12.SUB s

View File

@@ -0,0 +1 @@
char *compiled "@(#) parser - Thu Feb 10 13:02 1983";

View File

@@ -0,0 +1,18 @@
$ parser
$ set noon
$ !
$ ! C068 make file for VMS
$ !
$ copy machine.vax machine.h
$ pur machine.h
$ cx DECL
$ cx EXPR
$ cx ICODE
$ cx INIT
$ cx INTERF
$ cx LEX
$ cx MAIN
$ cx STMT
$ cx TABL
$ cx VERSION
$ clink DECL,EXPR,ICODE,INTERF,LEX,MAIN,STMT,TABL,init,version,lib:klib/lib c068

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,196 @@
/*
Copyright 1982
Alcyon Corporation
8716 Production Ave.
San Diego, Ca. 92121
*/
#include <stdio.h>
#include <klib.h>
#undef putchar
#define putchar xputchar
#undef ferror
#define ferror xferror
#define printf xprintf
#include "icode.h"
char brtab[][2];
int invrel[];
int swaprel[];
char *strtab[];
char null[];
/*operator tree node for unary and binary operators*/
struct tnode {
int t_op; /*operator*/
int t_type; /*data type of result*/
int t_su; /*Sethy-Ullman number*/
int t_ssp;
struct tnode *t_left; /*left sub-tree*/
struct tnode *t_right; /*right sub-tree (undefined if unary)*/
};
/*constant terminal node*/
struct conode {
int t_op; /*operator*/
int t_type; /*type*/
int t_su; /*Sethy-Ullman number*/
int t_ssp;
int t_value; /*value or label number*/
};
struct lconode {
int t_op; /*operator*/
int t_type; /*type*/
int t_su; /*Sethy-Ullman number*/
int t_ssp;
long t_lvalue; /*value or label number*/
};
/*local symbol terminal node*/
struct symnode {
int t_op; /*operator*/
int t_type; /*symbol data type*/
int t_su; /*Sethy-Ullman number*/
int t_ssp;
int t_sc; /*storage class*/
int t_offset; /*register offset*/
int t_reg; /*register number*/
int t_label; /*label number if static*/
};
/*external symbol reference node*/
struct extnode {
int t_op; /*operator*/
int t_type; /*symbol data type*/
int t_su; /*Sethy-Ullman number*/
int t_ssp;
int t_sc; /*storage class*/
int t_offset; /*register offset*/
int t_reg; /*register number*/
char t_symbol[SSIZE]; /*symbol name*/
};
/*68000 special - indexed symbol node*/
/*this is used to generate a An(off,Xn.type) address*/
struct indexnode {
int t_op;
int t_type;
int t_su;
int t_ssp;
int t_sc;
int t_offset;
int t_reg;
int t_xreg;
int t_xtype;
};
int lflag;
int dflag;
int mflag;
int cflag;
int eflag;
int fflag;
int oflag;
struct io_buf ibuf, obuf;
int lineno;
int naregs;
int ndregs;
int errcnt;
int opinfo[];
int nextlabel;
char null[];
char optab[][6];
char *mnemonics[];
char *codeskels[];
int stacksize;
char *tnalloc();
char *snalloc();
char *cenalloc();
char *xnalloc();
char *talloc();
char *cnalloc();
char *lcnalloc();
char *fpcnalloc();
char *canon();
char *commute();
char *constant();
char *match();
char *addptree();
char *fixbfield();
char *coffset();
char *tcopy();
#define wallign(add) ((add+1)&(~1))
#define array(type) ((type&SUPTYP)==ARRAY)
#define function(type) ((type&SUPTYP)==FUNCTION)
#define pointer(type) ((type&SUPTYP)==POINTER)
#define notarray(type) ((type&SUPTYP)!=ARRAY)
#define notfunction(type) ((type&SUPTYP)!=FUNCTION)
#define notpointer(type) ((type&SUPTYP)!=POINTER)
#define isfloat(type) (type==FLOAT)
#define btype(type) (type&TYPE)
#define suptype(type) (type&SUPTYP)
#define alltype(type) (type&(SUPTYP|TYPE))
#define asgop(op) ((opinfo[op]&OPASSIGN)!=0)
#define relop(op) ((opinfo[op]&OPREL)!=0)
#define lintegral(op) ((opinfo[op]&OPLWORD)!=0)
#define rintegral(op) ((opinfo[op]&OPRWORD)!=0)
#define rasop(op) ((opinfo[op]&OPRAS)!=0)
#define binop(op) ((opinfo[op]&OPBIN)!=0)
#define unaryop(op) ((opinfo[op]&(OPBIN|OPTERM))==0)
#define leafop(op) ((opinfo[op]&OPTERM)!=0)
#define notleafop(op) ((opinfo[op]&OPTERM)==0)
#define lvalop(op) ((opinfo[op]&OPLVAL)!=0)
#define oppriority(op) (opinfo[op]&OPPRI)
#define commop(op) ((opinfo[op]&OPCOM)!=0)
#define convop(op) ((opinfo[op]&OPCONVS)!=0)
#define notconvop(op) ((opinfo[op]&OPCONVS)==0)
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define QUICKVAL 8
#define LEP 14
#define FORCC 1
#define FOREFF 2
#define FORSTACK 3
#define FORCREG 4
#define FORSP 5
#define FORREG 4
#define HICREG 2
#define NCREGS 3
#define AREGLO 8
#define IMMED 1
#define NOTIMMED 0
#define NOTLOFFSET 0
/* one line routines turned into defines [vlh] for speed */
/*outgoto - output "bra L[labno]"*/
#define outgoto(lab) if (lab>0) printf("bra L%d\n",lab)
/*outlab - output "L[labno]:"*/
#define outlab(lab) if (lab>0) printf("L%d:",lab)
/*outext - output register sign extension*/
#define outext(reg) printf("ext.l R%d\n",reg)
/*outuext - output unsigned to long register extension*/
#define outuext(reg) printf("swap R%d\nclr R%d\nswap R%d\n",reg,reg,reg)
/*outswap - output swap register instruction*/
#define outswap(reg) printf("swap R%d\n",reg)
/*outaddr - output "add [type] R1 R2" instruction*/
#define outaddr(r1,r2,tp) outrr("add",r1,r2,(tp))
/*outccsave - ouput instruction to move cc's to register*/
#define outccsave(reg) printf("move sr,R%d\n",reg)
/*outccrestore - output instruction to restore cc's from register*/
#define outccrestore(reg) printf("move R%d,ccr\n",reg)
/*basetype - get the btype info sans unsigned*/
#define basetype(type) ((type==UNSIGNED) ? INT : type)
#define unsign(type) ((type) == UNSIGNED)
#define longorptr(type) (type==LONG || (type&SUPTYP))
#define unorptr(type) (type==UNSIGNED || (type&SUPTYP))
#define dreg(reg) ((reg) & (~AREGLO))
#define areg(reg) ((reg) | AREGLO)
#define isareg(reg) ((reg) >= AREGLO)
#define isdreg(reg) ((reg) < AREGLO)
#define isreg(tp) ((tp)->t_op == SYMBOL && (tp)->t_sc == REGISTER)

View File

@@ -0,0 +1,756 @@
/*
Copyright 1982
Alcyon Corporation
8716 Production Ave.
San Diego, Ca. 92121
*/
#include "cgen.h"
#include "cskel.h"
/* scodegen - over-all code generation for expression*/
/* Picks off post-fix ++, --.*/
scodegen(tp,cookie,reg) /* returns register result is in*/
struct tnode *tp;
int cookie;
int reg;
{
struct tnode *clist[20];
struct tnode **clp;
register struct tnode **cp;
register int r;
register int ccflag;
register struct tnode *rtp;
if( tp->t_op == COMMA ) {
scodegen(tp->t_left,FOREFF,reg);
return(scodegen(tp->t_right,cookie,reg));
}
ccflag = 0;
clp = clist;
tp = addptree(tp,&clp);
if( clp > clist ) {
/*
* post ++, -- in tree. We need to compile the tree post operators
* then generate code to do the post operators, then do any fix up of
* condition codes since the Stupid 68000 architect was a nimnul.
*/
if( cookie == FORCC ) {
/*
* here we make the observation that if we are comparing something with
* zero OR the top operator of the tree is not a comparison operator,
* we can compile the tree to a register, and then set the condition
* codes OK with a tst instruction at the end.
*/
if( relop(tp->t_op) ) {
if( (rtp=constant(tp->t_right)) && !rtp->t_value ) {
ccflag = 1;
tp = tp->t_left;
cookie = FORREG;
}
else
ccflag = 2;
}
else {
ccflag = 1;
cookie = FORREG;
}
}
}
r = codegen(tp,cookie,reg);
if( clp > clist ) {
if( ccflag == 2 )
outccsave(r);
for( cp = clist; cp < clp; cp++ )
codegen(*cp,FOREFF,r+1);
if( ccflag == 1 )
outcmp0(r,tp);
else if( ccflag == 2 )
outccrestore(r);
}
return(r);
}
/* addptree - prune off postfix ++, -- from expression tree*/
/* This prunes off ++, -- and collects those expressions for*/
/* scodegen.*/
char *addptree(tp,clp) /* returns pointer to pruned tree*/
struct tnode *tp;
struct tnode ***clp;
{
register int op;
op = tp->t_op;
if( leafop(op) || op == QMARK ) /* [vlh] 4.0 QMARK... */
return(tp);
if( op == POSTINC || op == POSTDEC ) {
*(*clp)++ = tp;
return( tcopy(tp->t_left) );
}
if( binop(op) )
tp->t_right = addptree(tp->t_right,clp);
tp->t_left = addptree(tp->t_left,clp);
return(tp);
}
/* codegen - generate code for expression*/
/* This calls up rcodegen, which prunes off any special register*/
/* optimization code, then calls ucodegen (unrecursive) code*/
/* generation.*/
codegen(tp,cookie,reg) /* returns reg result is in*/
struct tnode *tp; /* tree pointer*/
int cookie; /* code generation goals*/
int reg; /* first available register*/
{
register int size, savestk, ssize, r, i, scookie;
register struct tnode *rtp;
#ifndef NODEBUG
if( cflag )
printf("codegen op=%d cookie=%d reg=%d\n",tp->t_op,cookie,reg);
#endif
switch( tp->t_op ) {
case CALL:
case NACALL:
ssize = 0;
savestk = stacksize;
if( tp->t_left->t_op != SYMBOL )
stacksize++;
if( tp->t_op == CALL ) {
rtp = tp->t_right;
while( rtp->t_op == COMMA ) {
ssize =+ dofarg(rtp->t_right);
rtp = rtp->t_left;
}
ssize =+ dofarg(rtp);
}
tp->t_op = FJSR; /*generate JSR (unary op)*/
codegen(tp,FORREG,reg);
popstack(ssize);
stacksize = savestk;
fixresult(tp,cookie,0);
return(0); /*result in R0*/
case COMMA:
codegen(tp->t_left,FOREFF,reg);
return(codegen(tp->t_right,cookie,reg));
case AND:
if( cookie == FORCC && (i=isonebit(tp->t_right)) >= 0 &&
(i=dobitadd(tp->t_left,i)) >= 0 ) {
if( convop(tp->t_right->t_op) )
tp->t_right = tp->t_right->t_left;
tp->t_right->t_value = i;
tp->t_op = BTST;
tp = canon(tp);
sucomp(tp,reg,1);
}
break;
}
if( rcodegen(&tp,cookie,reg) ) {
if( cookie == FORCC && tp->t_op == SYMBOL && tp->t_sc == REGISTER
&& isdreg(tp->t_reg))
return(reg);
}
r = ucodegen(tp,cookie,reg);
return(r);
}
/* fixresult - fix result of code generation*/
fixresult(tp,cookie,reg) /* returns - none*/
struct tnode *tp;
int cookie; /* wanted this cookie*/
int reg;
{
#ifndef NODEBUG
if (cflag)
printf("fixresult cookie=%d reg=%d op=%d\n",cookie,reg,tp->t_op);
#endif
switch( cookie ) {
case FORCC:
outcmp0(reg,tp);
break;
case FORSP:
case FORSTACK:
stacksize++;
outrpush(reg,tp,cookie==FORSTACK);
break;
}
return(reg);
}
/* ucodegen - generate code for tree given cookie and starting register*/
/* Handles the matching of the expression tree node with the*/
/* corresponding code generation table. When a match is found,*/
/* expand is called to expand the code skeleton macro.*/
ucodegen(tp,cookie,reg) /* returns reg result is in*/
struct tnode *tp; /* pointer to expression tree*/
int cookie; /* (FORCC,FOREFF,FORREG,FORSTACK)*/
int reg; /* first available register*/
{
register int r;
register char *p;
#ifndef NODEBUG
if(cflag)
putexpr("ucodegen",tp);
#endif
switch( tp->t_op ) {
case STASSIGN: /*[vlh]*/
outstrcpy(codegen(tp->t_left,FORREG,areg(reg)),
codegen(tp->t_right,FORREG,areg(reg+1)), tp->t_type);
return(reg);
break;
case SYMBOL:
if( cookie == FOREFF )
return(reg);
break;
case LSH:
if( (isareg(reg)) && (p=constant(tp->t_right)) &&
!(unsign(tp->t_left->t_type)) &&
(p->t_value == 1 || p->t_value == 2) ) {
r = codegen(tp->t_left,FORREG,reg);
outmovr(r,reg,tp->t_left);
if( p->t_value == 2 )
outaddr(reg,reg,tp);
outaddr(reg,reg,tp);
fixresult(tp,cookie,reg);
return(reg);
}
break;
case EQMULT:
case EQDIV:
case LEQMULT:
case LEQDIV:
case EQMOD:
case LEQMOD:
case EQRSH:
case EQLSH:
case EQAND:
case EQOR:
case EQXOR:
if( indexreg(tp->t_left) ) {
reg = dreg(reg);
outmovr(r=tp->t_left->t_reg,reg,tp);
tp->t_left->t_reg = reg;
codegen(tp,cookie,reg+1);
outmovr(reg,r,tp);
return(reg);
}
break;
case ADD:
case EQADD:
if( (p=constant(tp->t_right)) && p->t_value < 0 &&
p->t_value >= -QUICKVAL ) {
p->t_value = - p->t_value;
tp->t_op =+ (SUB-ADD);
}
break;
}
sucomp(tp,reg,1);
if( (r=loadexpr(tp,cookie,reg)) >= 0 )
return(r);
if( (r=cqmark(tp,cookie,reg)) >= 0 )
return(r);
if( (r=hardrel(tp,cookie,reg)) >= 0 )
return(r);
if( cookie == FORCC && (p=match(tp,FOREFF,reg)) != 0 ) {
r = expand(tp,FOREFF,reg,p);
if( asgop(tp->t_op) && indexreg(tp->t_left) )
outcmp0(tp->t_left->t_reg,tp->t_left);
}
else if( p = match(tp,cookie,reg) )
r = expand(tp,cookie,reg,p);
else if( cookie != FORREG )
r = fixresult(tp,cookie,ucodegen(tp,FORREG,reg));
else
error("no code table for %d",tp->t_op);
return(r);
}
/* outstrcpy - output structure copy */
outstrcpy(lr,rr,size) /*[vlh]*/
int lr, rr; /* left register, right register */
int size; /* structure size to copy */
{
register int lab;
lab = nextlabel++;
printf("move #%d,r%d\n",(size/2)-1,dreg(lr));
outlab(lab);
printf("move (r%d)+,(r%d)+\ndbra r%d,L%d\n",rr,lr,dreg(lr),lab);
}
/* loadexpr - load an addressable expression into a register*/
/* This checks for any possible usage of the register indexed*/
/* addressing mode. Note that this relies on the good graces of the*/
/* load code skeletons not to muck up the compiler registers before*/
/* loading an addressable expression...*/
loadexpr(tp,cookie,reg) /* returns register loaded or -1*/
struct tnode *tp; /* pointer to expression tree*/
int reg; /* register to load*/
{
register struct tnode *rtp, *ltp, *xtp, *atp;
register int off, r, type, nr, ar, xr, xt;
if( tp->t_op == INDR || LOADABLE(tp) ) {
type = tp->t_type;
if( tp->t_op == INDR && (ltp=tp->t_left)->t_op == ADD ) {
rtp = ltp->t_right;
ltp = ltp->t_left;
off = 0;
if( rtp->t_op == CINT && ((off=rtp->t_value) < -128 ||
off > 127 || ltp->t_op != ADD ) ) {
tp = snalloc(type,AUTO,off,0,0);
if( indexreg(ltp) )
tp->t_reg = ltp->t_reg;
else {
r = codegen(ltp,FORREG,areg(reg));
if( isdreg(r) )
outmovr(r,areg(r),ltp);
tp->t_reg = areg(r);
}
}
else {
if( rtp->t_op == CINT ) {
rtp = ltp->t_right;
ltp = ltp->t_left;
}
if(indexreg(rtp) || (!(indexreg(ltp)) && (isreg(rtp)))) {
xtp = ltp;
ltp = rtp;
rtp = xtp;
}
xtp = atp = 0;
if( indexreg(ltp) ) {
ar = ltp->t_reg;
if( (isreg(rtp)) && rtp->t_type != CHAR ) {
xr = rtp->t_reg;
xt = rtp->t_type;
}
else
xtp = rtp;
}
else if( (isreg(ltp)) && ltp->t_type != CHAR &&
(lflag || rtp->t_op != ADDR) ) {
xr = ltp->t_reg;
xt = ltp->t_type;
atp = rtp;
}
else if( rtp->t_op == ADDR ) {
atp = ltp;
xtp = rtp;
}
else {
atp = rtp;
xtp = ltp;
}
nr = 0;
if( atp )
nr++;
if( xtp && (xtp->t_op != ADDR || lflag ) )
nr++;
if( dreg(nr+reg) <= HICREG ) {
r = reg;
if( atp ) {
ar = codegen(atp,FORREG,areg(r));
if( isdreg(ar) ) {
outmovr(ar,areg(ar),atp);
ar = areg(ar);
}
r++;
}
if( xtp && xtp->t_op == ADDR && !lflag ) {
tp = xtp->t_left;
tp->t_sc =+ (EXTOFF-EXTERNAL);
tp->t_offset =+ off;
tp->t_reg = ar;
}
else {
if( xtp ) {
xr = codegen(xtp,FORREG,areg(r));
xt = xtp->t_type;
}
tp = xnalloc(type,ar,off,xr,xt);
}
}
}
}
if( (isareg(reg)) && tp->t_type == CHAR )
reg = dreg(reg);
tp = tnalloc(LOAD,tp->t_type,SU_EASY,0,tp,null);
return( codegen(tp,cookie,reg) );
}
return(-1);
}
/* coffset - check offset for addressable node*/
char *coffset(tp) /* returns ptr to const off node*/
struct tnode *tp; /* pointer to node*/
{
register struct tnode *rtp;
if( tp->t_op == ADD ) {
rtp = tp->t_right;
if( rtp->t_op == CINT )
return(rtp);
if(!lflag) {
if( rtp->t_op == ADDR )
return(rtp->t_left);
rtp = tp->t_left;
if( rtp->t_op == ADDR ) {
tp->t_left = tp->t_right;
tp->t_right = rtp;
return(rtp->t_left);
}
}
}
return(0);
}
/* hardrel - do relationals returning a value*/
hardrel(tp,cookie,reg) /* returns reg or -1*/
struct tnode *tp; /* pointer to tree*/
int cookie; /* cookie for code generation*/
int reg; /* low register*/
{
char *p;
int op, lab1, lab2;
if( cookie != FORCC && (relop(op=tp->t_op) || op == LOR ||
op == LAND || op == NOT) ) {
lab1 = nextlabel++;
condbr(tp,TRUE,lab1,reg);
p = canon(cnalloc(INT,0));
codegen(p,cookie,reg);
lab2 = nextlabel++;
outgoto(lab2);
outlab(lab1);
p = canon(cnalloc(INT,1));
codegen(p,cookie,reg);
outlab(lab2);
return(reg);
}
return(-1);
}
/* cqmark - compile question mark operator*/
/* This does the compilation of the question mark operator.*/
cqmark(tp,cookie,reg) /* returns reg or -1*/
struct tnode *tp;
int cookie;
int reg;
{
register int lab1, lab2, savestk, r;
if( tp->t_op == QMARK && cookie != FORCC ) {
lab1 = nextlabel++;
condbr(tp->t_left,FALSE,lab1,reg);
savestk = stacksize;
r = scodegen(tp->t_right->t_left,cookie,reg); /* [mc] 4.0 */
outmovr(r,reg,tp);
stacksize = savestk;
outgoto(lab2=nextlabel++);
outlab(lab1);
r = scodegen(tp->t_right->t_right,cookie,reg); /* [mc] 4.0 */
outmovr(r,reg,tp);
outlab(lab2);
return(reg);
}
return(-1);
}
/* condbr - handle conditional branch code generation*/
/* This handles the conditional branch code generation, handling*/
/* the special cases for constants, ||, &&, ! and generating the*/
/* correct conditional branch instruction.*/
condbr(tp,dir,lab,reg)
struct tnode *tp;
int dir;
int lab;
int reg;
{
register struct tnode *ltp, *rtp;
register int lab1, optype, op, subdir;
ltp = tp->t_left;
if( binop(op=tp->t_op) )
rtp = tp->t_right;
subdir = dir; /*set up for LOR*/
switch( op ) {
case CINT:
if( !tp->t_value ) {
if( dir == FALSE )
outgoto(lab);
}
else if( dir != FALSE )
outgoto(lab);
break;
case NOT:
condbr(ltp,!dir,lab,reg);
break;
case LAND:
dir = !dir;
case LOR:
if( dir == FALSE ) {
lab1 = nextlabel++;
condbr(ltp,!subdir,lab1,reg);
condbr(rtp,subdir,lab,reg);
outlab(lab1);
}
else {
condbr(ltp,subdir,lab,reg);
condbr(rtp,subdir,lab,reg);
}
break;
case COMMA:
scodegen(tp->t_left,FOREFF,reg);
condbr(tp->t_right,dir,lab,reg);
break;
default:
if( op == NEQUALS && ltp->t_op == PREDEC &&
isdreg(ltp->t_left->t_reg) && ltp->t_left->t_type == INT &&
rtp->t_op == CINT && rtp->t_value == -1 ) {
outdbra(ltp->t_left->t_reg,lab);
break;
}
if( relop(op) && ltp->t_op == AUTOINC && rtp->t_op == AUTOINC &&
ltp->t_type == rtp->t_type )
outcmpm(tp);
else
scodegen(tp,FORCC,reg);
optype = 0;
if( relop(op) ) {
if( unorptr(ltp->t_type) || unorptr(rtp->t_type) )
optype =+ 1;
}
else
op = NEQUALS;
if(!dir)
op = invrel[op-EQUALS];
optype = brtab[op-EQUALS][optype];
printf("%s L%d\n",mnemonics[optype],lab);
break;
}
}
rcodegen(tpp,cookie,reg) /* returns changed flag*/
struct tnode **tpp; /* pointer to tree*/
int cookie; /* code generation cookie*/
int reg; /* register to use for code*/
{
register int change, op;
register struct tnode *tp;
tp = *tpp;
op = tp->t_op;
change = 0;
if( notleafop(op) && op != COMMA ) {
change =+ rcodegen(&tp->t_left,cookie,reg);
if( binop(op) )
change =+ rcodegen(&tp->t_right,cookie,reg);
change =+ rcgen(tpp,cookie,reg);
}
if( change )
*tpp = canon(*tpp);
return(change);
}
rcgen(tpp,cookie,reg) /* returns changed flag*/
struct tnode **tpp; /* pointer to tree*/
int cookie; /* code generation goals*/
int reg; /* register to use*/
{
register struct tnode *tp, *p, *ltp, *rtp;
register int op, change;
change = 0;
for( tp = *tpp ; binop(op=tp->t_op); *tpp=tp=canon(tp), change++ ) {
ltp = tp->t_left;
if( ltp->t_op != SYMBOL )
break;
rtp = tp->t_right;
switch( op ) {
case ASSIGN:
if( ltp->t_sc != REGISTER )
return(change);
switch( rtp->t_op ) {
case MULT:
case DIV:
case MOD:
case AND:
case OR:
case XOR:
case LSH:
case RSH:
if( isareg(ltp->t_reg) )
return(change);
case ADD:
case SUB:
p = rtp->t_right;
if(NOTADDRESSABLE(ltp) || !noref(rtp->t_right,ltp->t_reg))
return(change);
p = rtp->t_left;
if( p->t_op != SYMBOL || p->t_sc != REGISTER ||
p->t_reg != ltp->t_reg ) {
tp->t_right = p;
#ifndef NODEBUG
if( cflag > 1 )
putexpr("rcgen",tp);
#endif
codegen(tp,FOREFF,reg);
}
tp->t_right = rtp->t_right;
tp->t_op = rtp->t_op + (EQADD-ADD);
continue;
}
case EQLSH:
case EQRSH:
if( ltp->t_sc != REGISTER )
return(change);
case EQADD:
case EQSUB:
case EQAND:
case EQOR:
case EQXOR:
if( ltp->t_type == CHAR )
return(change);
#ifndef NODEBUG
if( cflag > 1 )
putexpr("rcgen",tp);
#endif
ucodegen(tp,FOREFF,reg);
tp = ltp;
continue;
case PREDEC:
case PREINC:
if( cookie == FORCC || ltp->t_type == CHAR )
return(change);
ucodegen(tp,FOREFF,reg);
tp = ltp;
continue;
}
break;
}
return(change);
}
noref(tp,reg) /* 4.0 change */
struct tnode *tp; /* returns 1 if no reference in tree to reg */
int reg;
{
if ( leafop(tp->t_op) ) {
if (tp->t_op == SYMBOL && tp->t_sc == REGISTER && tp->t_reg == reg)
return(0);
return(1);
}
if ( !noref(tp->t_left,reg) )
return(0);
if (binop(tp->t_op))
return( noref(tp->t_right,reg) );
return(1);
}
/* cdsize - compute size of data item*/
cdsize(tp) /* returns data size in bytes*/
struct tnode *tp;
{
register int type;
type = tp->t_type;
if( suptype(type) )
return(PTRSIZE);
switch( type ) {
case CHAR:
case INT:
case UNSIGNED:
return(INTSIZE);
case LONG:
case FLOAT: /* [vlh] 3.4 */
return(LONGSIZE);
}
error("cdsize: invalid type %d",type);
return(0);
}
dofarg(tp) /* returns number of bytes pushed*/
struct tnode *tp; /* pointer to expression tree*/
{
register int nb;
nb = 0;
if( tp->t_op == SYMBOL && tp->t_sc == STRUCT )
error("structure operation not implemented");
else if( stacksize ) {
codegen(tp,FORSTACK,0);
nb = cdsize(tp);
}
else
codegen(tp,FORSP,0);
return( nb );
}
/* dobitadd - do bit operation address checking and fixup*/
dobitadd(tp,bitno) /* returns -1 if can't or bitno*/
struct tnode *tp;
int bitno;
{
register int offset;
if( tp->t_type == CHAR )
offset = 0;
else
offset = cdsize(tp) - (bitno/BITSPBYTE) - 1;
if( tp->t_op == SYMBOL ) {
switch( tp->t_sc ) {
case REGISTER:
if( isdreg(tp->t_reg) )
return(bitno);
default:
return(-1);
case EXTERNAL:
case STATIC:
case REGOFF:
case STATOFF:
case EXTOFF:
tp->t_offset =+ offset;
return( bitno % BITSPBYTE );
}
}
else if( tp->t_op == INDR ) {
tp->t_left = tnalloc(ADD,tp->t_left->t_type,0,0,tp->t_left,
cnalloc(INT,offset));
return( bitno % BITSPBYTE );
}
return(-1);
}
isonebit(tp) /* returns -1 if not 1 bit, else bitno*/
struct tnode *tp; /* pointer to tree*/
{
if( tp = constant(tp) )
return( onebit(tp->t_value) );
return(-1);
}

View File

@@ -0,0 +1,92 @@
/*
Copyright 1981
Alcyon Corporation
8474 Commerce Av.
San Diego, Ca. 92121
*/
/*built-in literals*/
#define MOV 128
#define MOVL 129
#define JSR 130
#define CLR 131
#define CLRL 132
#define EXTW 133
#define EXTL 134
#define LEA 135
#define STK 136
/*built-in macros*/
#define TREE 141
#define LEFT 142
#define RIGHT 143
#define LOFFSET 144
#define ROFFSET 145
#define LADDR 146
#define RADDR 147
#define CR 148
#define NR 149
#define CAR 150
#define NAR 151
#define TLEFT 152
#define TRIGHT 153
#define TEITHER 154
#define TLEFTL 155
#define OP 156
#define AOP 157
#define MODSWAP 158
#define EXL 159
#define EXLR 160
#define EXLRN 161
#define EXRL 162
#define EXRLN 163
#define PSH 164
#define POP 165
#define POP8 166
#define OPCALL 167
#define POP4 169
#define LADDRP 168
/*modifiers for compiling sub-trees*/
#define S_INDR 1 /*indirection*/
#define S_STACK 2 /*onto stack*/
#define S_FORCC 4 /*set condition codes*/
#define S_NEXT 8 /*into next register*/
/*Sethy-Ullman values*/
#define SU_ZERO 0x000 /*zero*/
#define SU_ONE 0x100 /*one*/
#define SU_SMALL 0x200 /*constant between 1 and 8*/
#define SU_QUICK 0x300 /*quick constant between -128 and 127*/
#define SU_CONST 0x400 /*any constant*/
#define SU_AREG 0x500 /*A register*/
#define SU_REG 0x600 /*register*/
#define SU_ADDR 0x700 /*addressable*/
#define SU_XREG 0x800 /*A register used as data...*/
#define SU_EASY 0x900 /*easy*/
#define SU_HARD 0xa00 /*hard*/
#define SU_VHARD 0xb00 /*very hard ... function calls, etc.*/
#define SU_ANY 0xf00 /*anything*/
#define ADDRESSABLE(x) (x->t_su<=SU_ADDR)
#define NOTADDRESSABLE(x) (x->t_su>SU_ADDR)
#define LOADABLE(x) (x->t_su<=SU_XREG)
/*flag byte (operand type):*/
#define T_CHAR 1 /*char only*/
#define T_SHORT 2 /*short*/
#define T_INT 3 /*int only*/
#define T_LONG 4 /*long*/
#define T_UCHAR 5 /*unsigned char*/
#define T_USHORT 6 /*unsigned short*/
#define T_UNSN 7 /*unsigned int*/
#define T_ULONG 8 /*unsigned long*/
#define T_FLOAT 9 /*float*/
#define T_DOUB 10 /*double*/
#define T_ANY 11 /*int or word (implied)*/
#define T_INDR 0x10 /*pointer type (bit)*/
struct skeleton {
int sk_left;
int sk_right;
char *sk_def;
};

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,251 @@
/*
Copyright 1982
Alcyon Corporation
8716 Production Ave.
San Diego, Ca. 92121
*/
#include "machine.h"
/*
* intermediate code operators
* 0=>EOF, special operator
*/
#define EOF 0
/*1-59=>operators that generate code (entries in code gen optab)*/
#define ADD 1
#define SUB 2
#define MULT 3
#define DIV 4
#define MOD 5
#define RSH 6
#define LSH 7
#define AND 8
#define OR 9
#define XOR 10
#define NOT 11
#define UMINUS 12
#define COMPL 13
#define PREDEC 14
#define PREINC 15
#define POSTDEC 16
#define POSTINC 17
#define ASSIGN 18
#define EQADD 19
#define EQSUB 20
#define EQMULT 21
#define EQDIV 22
#define EQMOD 23
#define EQRSH 24
#define EQLSH 25
#define EQAND 26
#define EQOR 27
#define EQXOR 28
#define FJSR 29
#define EQUALS 30
#define NEQUALS 31
#define GREAT 32
#define GREATEQ 33
#define LESS 34
#define LESSEQ 35
#define INT2L 36
#define LONG2I 37
/*machine dependent operators that generate code*/
#define BTST 38
#define LOAD 39
#define LMULT 40
#define LDIV 41
#define LMOD 42
#define LEQMULT 43
#define LEQDIV 44
#define LEQMOD 45
#define EQADDR 46
#define EQNOT 47
#define EQNEG 48
#define DOCAST 49
#define STASSIGN 50 /*[vlh]*/
#define LONG2F 51 /*[vlh] 3.4*/
#define FLOAT2L 52 /*[vlh] 3.4*/
#define INT2F 53 /*[vlh] 3.4*/
#define FLOAT2I 54 /*[vlh] 3.4*/
#define LCGENOP 55 /*change if adding more operators...*/
/*intermediate code operators that do not generate code*/
#define ADDR 60
#define INDR 61
#define LAND 62
#define LOR 63
#define QMARK 64
#define COLON 65
#define COMMA 66
#define CINT 67
#define CLONG 68
#define SYMBOL 69
#define AUTOINC 70
#define AUTODEC 71
#define CALL 72
#define NACALL 73
#define BFIELD 74
#define IFGOTO 75
#define INIT 76
#define CFORREG 77
#define DCLONG 78
#define CFLOAT 79 /*[vlh] 3.4*/
/*operators local to parser*/
#define CAST 80
#define SEMI 81
#define LCURBR 82
#define RCURBR 83
#define LBRACK 84
#define RBRACK 85
#define LPAREN 86
#define RPAREN 87
#define STRING 88
#define RESWORD 89
#define APTR 90
#define PERIOD 91
#define SIZEOF 92
#define MPARENS 93
#define FRETURN 94
#define STACKEND 100
/*data types*/
#define TYPELESS 0
#define CHAR 1
#define SHORT 2
#define INT 3
#define LONG 4
#define UCHAR 5
#define USHORT 6
#define UNSIGNED 7
#define ULONG 8
#define FLOAT 9
#define DOUBLE 10
/*data types local to parser*/
#define STRUCT 11
#define FRSTRUCT 12
#define LLABEL 13
/*type flags and definitions*/
#define TYPE 017
#define SUPTYP 060
#define ALLTYPE 077
#define POINTER 020
#define FUNCTION 040
#define ARRAY 060
#define SUTYPLEN 2
/*data registers*/
#define DREG0 0
#define DREG2 2
#define DREG3 3
#define DREG4 4
#define DREG5 5
#define DREG6 6
#define DREG7 7
#define AREG3 11
#define AREG4 12
#define AREG5 13
/*storage classes*/
#define AUTO 1
#define REGISTER 2
#define EXTERNAL 3
#define STATIC 4
#define REGOFF 5
#define EXTOFF 6
#define STATOFF 7
#define INDEXED 8
/*exclusively code generator storage classes*/
#define CINDR 9
#define CLINDR 10
#define CFINDR 11 /* [vlh] 3.4 */
/*exclusively parser storage classes*/
#define STRPROTO 9
#define PDECLIST 10
#define PARMLIST 11
#define BFIELDCL 12
#define UNELCL 13
#define STELCL 14
/*opinfo table bits*/
#define OPPRI 077
#define OPBIN 0100
#define OPLVAL 0200
#define OPREL 0400
#define OPASSIGN 01000
#define OPLWORD 02000
#define OPRWORD 04000
#define OPCOM 010000
#define OPRAS 020000
#define OPTERM 040000
#define OPCONVS 0100000
/*68000 definitions*/
#define PTRSIZE 4
#define INTSIZE 2
#define LONGSIZE 4
#define SSIZE 8 /* chars per symbol */
#define TRUE 1
#define FALSE 0
#define TABC '\t' /* tab character */
#define EOLC '\n' /* end of line character */
#define BITSPBYTE 8
/*operator class priorities*/
#define TRMPRI 0 /* terminal nodes */
#define RPNPRI 1 /* ) and ] */
#define CALPRI 2 /* in-stack call, ( or [ */
#define COLPRI 3 /* init or case priority for : or , */
#define STKPRI 4 /* priority of end of stack */
#define COMPRI 5 /* normal priority for , */
#define ASGPRI 6 /* =, +=, -=, *=, /=, %=, ... */
#define QMKPRI 7 /* ?: */
#define LORPRI 8 /* || */
#define LNDPRI 9 /* && */
#define ORPRI 10 /* |, ! */
#define ANDPRI 11 /* & */
#define EQLPRI 12 /* ==, != */
#define RELPRI 13 /* >, <, >=, <= */
#define SHFPRI 14 /* <<, >> */
#define ADDPRI 15 /* +, - */
#define MULPRI 16 /* *, /, % */
#define UNOPRI 17 /* ++, --, &, *, -, ~, sizeof */
#define LPNPRI 18 /* ., ->, [, (, function call */
#define PSTPRI 19 /* in-stack post--, post++ */
struct io_buf {
int io_fd;
int io_nc;
char *io_p;
char io_b[512];
};
#ifdef PDP11
struct { short hiword; short loword; };
#endif
#ifdef MC68000
struct { short hiword; short loword; };
#endif
#ifdef VAX
struct { short loword; short hiword; };
#endif
#define EXPSIZE 1024
int exprarea[EXPSIZE];
/* v6io buffer declaration */
#define BLEN 512
struct iobuf{
int fildes;
int nunused;
char *xfree;
char buff[BLEN];
};

View File

@@ -0,0 +1,418 @@
/*
Copyright 1982
Alcyon Corporation
8716 Production Ave.
San Diego, Ca. 92121
*/
char null[]=0;
#define SSIZE 8 /* chars per symbol */
/*operator tree node for unary and binary operators*/
struct tnode {
int t_op; /*operator*/
int t_type; /*data type of result*/
int t_su; /*Sethy-Ullman number*/
int t_ssp;
struct tnode *t_left; /*left sub-tree*/
struct tnode *t_right; /*right sub-tree (undefined if unary)*/
};
/*constant terminal node*/
struct conode {
int t_op; /*operator*/
int t_type; /*type*/
int t_su; /*Sethy-Ullman number*/
int t_ssp;
int t_value; /*value or label number*/
};
struct lconode {
int t_op; /*operator*/
int t_type; /*type*/
int t_su; /*Sethy-Ullman number*/
int t_ssp;
long t_lvalue; /*value or label number*/
};
/*local symbol terminal node*/
struct symnode {
int t_op; /*operator*/
int t_type; /*symbol data type*/
int t_su; /*Sethy-Ullman number*/
int t_ssp;
int t_sc; /*storage class*/
int t_offset; /*register offset*/
int t_reg; /*register number*/
int t_label; /*label number if static*/
};
/*external symbol reference node*/
struct extnode {
int t_op; /*operator*/
int t_type; /*symbol data type*/
int t_su; /*Sethy-Ullman number*/
int t_ssp;
int t_sc; /*storage class*/
int t_offset; /*register offset*/
int t_reg; /*register number*/
char t_symbol[SSIZE]; /*symbol name*/
};
/*68000 special - indexed symbol node*/
/*this is used to generate a An(off,Xn.type) address*/
struct indexnode {
int t_op;
int t_type;
int t_su;
int t_ssp;
int t_sc;
int t_offset;
int t_reg;
int t_xreg;
int t_xtype;
};
int lflag=0;
int dflag=0;
int mflag=0;
int cflag=0;
int eflag=0;
int fflag=0;
int oflag=0;
int lineno=0;
int naregs=0;
int ndregs=0;
int errcnt=0;
int stacksize=0;
char *tnalloc();
char *snalloc();
char *cenalloc();
char *xnalloc();
char *talloc();
char *cnalloc();
char *lcnalloc();
char *fpcnalloc();
char *canon();
char *commute();
char *constant();
char *match();
char *addptree();
char *fixbfield();
char *coffset();
char *tcopy();
#define wallign(add) ((add+1)&(~1))
#define array(type) ((type&SUPTYP)==ARRAY)
#define function(type) ((type&SUPTYP)==FUNCTION)
#define pointer(type) ((type&SUPTYP)==POINTER)
#define notarray(type) ((type&SUPTYP)!=ARRAY)
#define notfunction(type) ((type&SUPTYP)!=FUNCTION)
#define notpointer(type) ((type&SUPTYP)!=POINTER)
#define isfloat(type) (type==FLOAT)
#define btype(type) (type&TYPE)
#define suptype(type) (type&SUPTYP)
#define alltype(type) (type&(SUPTYP|TYPE))
#define asgop(op) ((opinfo[op]&OPASSIGN)!=0)
#define relop(op) ((opinfo[op]&OPREL)!=0)
#define lintegral(op) ((opinfo[op]&OPLWORD)!=0)
#define rintegral(op) ((opinfo[op]&OPRWORD)!=0)
#define rasop(op) ((opinfo[op]&OPRAS)!=0)
#define binop(op) ((opinfo[op]&OPBIN)!=0)
#define unaryop(op) ((opinfo[op]&(OPBIN|OPTERM))==0)
#define leafop(op) ((opinfo[op]&OPTERM)!=0)
#define notleafop(op) ((opinfo[op]&OPTERM)==0)
#define lvalop(op) ((opinfo[op]&OPLVAL)!=0)
#define oppriority(op) (opinfo[op]&OPPRI)
#define commop(op) ((opinfo[op]&OPCOM)!=0)
#define convop(op) ((opinfo[op]&OPCONVS)!=0)
#define notconvop(op) ((opinfo[op]&OPCONVS)==0)
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define QUICKVAL 8
#define LEP 14
#define FORCC 1
#define FOREFF 2
#define FORSTACK 3
#define FORCREG 4
#define FORSP 5
#define FORREG 4
#define HICREG 2
#define NCREGS 3
#define AREGLO 8
#define IMMED 1
#define NOTIMMED 0
#define NOTLOFFSET 0
/* one line routines turned into defines [vlh] for speed */
/*outgoto - output "bra L[labno]"*/
#define outgoto(lab) if (lab>0) printf("bra L%d\n",lab)
/*outlab - output "L[labno]:"*/
#define outlab(lab) if (lab>0) printf("L%d:",lab)
/*outext - output register sign extension*/
#define outext(reg) printf("ext.l R%d\n",reg)
/*outuext - output unsigned to long register extension*/
#define outuext(reg) printf("swap R%d\nclr R%d\nswap R%d\n",reg,reg,reg)
/*outswap - output swap register instruction*/
#define outswap(reg) printf("swap R%d\n",reg)
/*outaddr - output "add [type] R1 R2" instruction*/
#define outaddr(r1,r2,tp) outrr("add",r1,r2,(tp))
/*outccsave - ouput instruction to move cc's to register*/
#define outccsave(reg) printf("move sr,R%d\n",reg)
/*outccrestore - output instruction to restore cc's from register*/
#define outccrestore(reg) printf("move R%d,ccr\n",reg)
/*basetype - get the btype info sans unsigned*/
#define basetype(type) ((type==UNSIGNED) ? INT : type)
#define unsign(type) ((type) == UNSIGNED)
#define longorptr(type) (type==LONG || (type&SUPTYP))
#define unorptr(type) (type==UNSIGNED || (type&SUPTYP))
#define dreg(reg) ((reg) & (~AREGLO))
#define areg(reg) ((reg) | AREGLO)
#define isareg(reg) ((reg) >= AREGLO)
#define isdreg(reg) ((reg) < AREGLO)
#define isreg(tp) ((tp)->t_op == SYMBOL && (tp)->t_sc == REGISTER)
/*
* intermediate code operators
* 0=>EOF, special operator
*/
#define EOF 0
/*1-59=>operators that generate code (entries in code gen optab)*/
#define ADD 1
#define SUB 2
#define MULT 3
#define DIV 4
#define MOD 5
#define RSH 6
#define LSH 7
#define AND 8
#define OR 9
#define XOR 10
#define NOT 11
#define UMINUS 12
#define COMPL 13
#define PREDEC 14
#define PREINC 15
#define POSTDEC 16
#define POSTINC 17
#define ASSIGN 18
#define EQADD 19
#define EQSUB 20
#define EQMULT 21
#define EQDIV 22
#define EQMOD 23
#define EQRSH 24
#define EQLSH 25
#define EQAND 26
#define EQOR 27
#define EQXOR 28
#define FJSR 29
#define EQUALS 30
#define NEQUALS 31
#define GREAT 32
#define GREATEQ 33
#define LESS 34
#define LESSEQ 35
#define INT2L 36
#define LONG2I 37
/*machine dependent operators that generate code*/
#define BTST 38
#define LOAD 39
#define LMULT 40
#define LDIV 41
#define LMOD 42
#define LEQMULT 43
#define LEQDIV 44
#define LEQMOD 45
#define EQADDR 46
#define EQNOT 47
#define EQNEG 48
#define DOCAST 49
#define STASSIGN 50 /*[vlh]*/
#define LONG2F 51 /*[vlh] 3.4*/
#define FLOAT2L 52 /*[vlh] 3.4*/
#define INT2F 53 /*[vlh] 3.4*/
#define FLOAT2I 54 /*[vlh] 3.4*/
#define LCGENOP 55 /*change if adding more operators...*/
/*intermediate code operators that do not generate code*/
#define ADDR 60
#define INDR 61
#define LAND 62
#define LOR 63
#define QMARK 64
#define COLON 65
#define COMMA 66
#define CINT 67
#define CLONG 68
#define SYMBOL 69
#define AUTOINC 70
#define AUTODEC 71
#define CALL 72
#define NACALL 73
#define BFIELD 74
#define IFGOTO 75
#define INIT 76
#define CFORREG 77
#define DCLONG 78
#define CFLOAT 79 /*[vlh] 3.4*/
/*operators local to parser*/
#define CAST 80
#define SEMI 81
#define LCURBR 82
#define RCURBR 83
#define LBRACK 84
#define RBRACK 85
#define LPAREN 86
#define RPAREN 87
#define STRING 88
#define RESWORD 89
#define APTR 90
#define PERIOD 91
#define SIZEOF 92
#define MPARENS 93
#define FRETURN 94
#define STACKEND 100
/*data types*/
#define TYPELESS 0
#define CHAR 1
#define SHORT 2
#define INT 3
#define LONG 4
#define UCHAR 5
#define USHORT 6
#define UNSIGNED 7
#define ULONG 8
#define FLOAT 9
#define DOUBLE 10
/*data types local to parser*/
#define STRUCT 11
#define FRSTRUCT 12
#define LLABEL 13
/*type flags and definitions*/
#define TYPE 017
#define SUPTYP 060
#define ALLTYPE 077
#define POINTER 020
#define FUNCTION 040
#define ARRAY 060
#define SUTYPLEN 2
/*data registers*/
#define DREG0 0
#define DREG2 2
#define DREG3 3
#define DREG4 4
#define DREG5 5
#define DREG6 6
#define DREG7 7
#define AREG3 11
#define AREG4 12
#define AREG5 13
/*storage classes*/
#define AUTO 1
#define REGISTER 2
#define EXTERNAL 3
#define STATIC 4
#define REGOFF 5
#define EXTOFF 6
#define STATOFF 7
#define INDEXED 8
/*exclusively code generator storage classes*/
#define CINDR 9
#define CLINDR 10
#define CFINDR 11 /* [vlh] 3.4 */
/*exclusively parser storage classes*/
#define STRPROTO 9
#define PDECLIST 10
#define PARMLIST 11
#define BFIELDCL 12
#define UNELCL 13
#define STELCL 14
/*opinfo table bits*/
#define OPPRI 077
#define OPBIN 0100
#define OPLVAL 0200
#define OPREL 0400
#define OPASSIGN 01000
#define OPLWORD 02000
#define OPRWORD 04000
#define OPCOM 010000
#define OPRAS 020000
#define OPTERM 040000
#define OPCONVS 0100000
/*68000 definitions*/
#define PTRSIZE 4
#define INTSIZE 2
#define LONGSIZE 4
#define TRUE 1
#define FALSE 0
#define TABC '\t' /* tab character */
#define EOLC '\n' /* end of line character */
#define BITSPBYTE 8
/*operator class priorities*/
#define TRMPRI 0 /* terminal nodes */
#define RPNPRI 1 /* ) and ] */
#define CALPRI 2 /* in-stack call, ( or [ */
#define COLPRI 3 /* init or case priority for : or , */
#define STKPRI 4 /* priority of end of stack */
#define COMPRI 5 /* normal priority for , */
#define ASGPRI 6 /* =, +=, -=, *=, /=, %=, ... */
#define QMKPRI 7 /* ?: */
#define LORPRI 8 /* || */
#define LNDPRI 9 /* && */
#define ORPRI 10 /* |, ! */
#define ANDPRI 11 /* & */
#define EQLPRI 12 /* ==, != */
#define RELPRI 13 /* >, <, >=, <= */
#define SHFPRI 14 /* <<, >> */
#define ADDPRI 15 /* +, - */
#define MULPRI 16 /* *, /, % */
#define UNOPRI 17 /* ++, --, &, *, -, ~, sizeof */
#define LPNPRI 18 /* ., ->, [, (, function call */
#define PSTPRI 19 /* in-stack post--, post++ */
struct io_buf {
int io_fd;
int io_nc;
char *io_p;
char io_b[512];
};
struct { int hiword; int loword; };
#define EXPSIZE 1024
int exprarea[EXPSIZE]=0;
/* v6io buffer declaration */
#define BLEN 512
struct iobuf {
int fildes;
int nunused;
char *xfree;
char buff[BLEN];
};
struct io_buf ibuf={0}, obuf={0};
int bol=0;
int errflg=0;
int level=0;
int onepass=0;
char *opap=0;

View File

@@ -0,0 +1,134 @@
/*
Copyright 1982
Alcyon Corporation
8716 Production Ave.
San Diego, Ca. 92121
*/
#include "cgen.h"
int bol;
int onepass;
/* outexpr - output expression*/
outexpr(tp) /* returns - none*/
struct tnode *tp; /* pointer to tree node*/
{
if( dflag )
outline();
if( exprok(tp) )
scodegen(canon(tp),FOREFF,0);
}
outifgoto(tp,dir,lab)
struct tnode *tp;
int dir;
int lab;
{
if( dflag )
outline();
if( exprok(tp) )
condbr(canon(tp),dir,lab,0);
}
outcforreg(tp)
struct tnode *tp;
{
if( dflag )
outline();
if( exprok(tp) )
outmovr(scodegen(canon(tp),FORREG,0),0,tp);
}
outinit(tp) /* returns - none*/
struct tnode *tp;
{
register int typeout;
if( dflag )
outline();
if( exprok(tp) ) {
typeout = tp->t_type;
tp = canon(tp);
if( tp->t_op == ADDR )
tp = tp->t_left;
if( tp->t_op == CINT || tp->t_op == SYMBOL ) {
if( tp->t_op != CINT )
printf(".dc.l ");
else {
printf(".dc");
outtype(typeout);
putchar(' ');
}
outaexpr(tp,NOTIMMED); /* [vlh] 4.0 not immed... */
}
else
error("invalid initialization");
putchar('\n');
}
}
/* snalloc - code generator symbol node allocation*/
/* This might be coalesced into parser snalloc.*/
char *snalloc(type,sc,offset,dp,ssp) /* returns ptr to node alloced*/
int type; /* type of symbol*/
int sc; /* storage class*/
int offset; /* offset from Local Environment Ptr*/
int dp; /*for compatability with parser*/
int ssp; /*for compatability with parser*/
{
register struct symnode *sp;
sp = talloc(sizeof(*sp));
sp->t_op = SYMBOL;
sp->t_type = type;
sp->t_su = dp;
sp->t_ssp = ssp;
sp->t_sc = sc;
switch( sc ) {
case STATIC:
sp->t_offset = 0;
sp->t_reg = 0;
sp->t_label = offset;
break;
case REGISTER:
sp->t_offset = 0;
sp->t_reg = offset;
sp->t_label = 0;
break;
case AUTO:
sp->t_sc = REGOFF;
sp->t_offset = offset;
sp->t_reg = LEP;
sp->t_label = 0;
break;
default:
sp->t_offset = offset;
sp->t_reg = 0;
sp->t_label = 0;
break;
}
return(sp);
}
exprok(tp)
struct tnode *tp;
{
if( tp < exprarea || tp > &exprarea[EXPSIZE] )
return(0);
if( leafop(tp->t_op) )
return(1);
if( binop(tp->t_op) && !exprok(tp->t_right) )
return(0);
return( exprok(tp->t_left) );
}
outline()
{
if( onepass && !bol )
putchar('\n');
printf("*line %d\n",lineno);
}

View File

@@ -0,0 +1,12 @@
ren u.o=util.o
ren t.o=tabl.o
ren c.o=codegen.o
ren i.o=interf.o
ren m.o=main.o
ren p.o=putexpr.o
$1lo68 -r -f $1 -unofloat 0$1s.o canon.o c.o cskels.o i.o m.o optab.o p.o smatch.o sucomp.o t.o u.o 0$1lib6.a 0$1clib
era c168.rel
ren c168.rel=c.out
era *.o
user 0!make $1

View File

@@ -0,0 +1,51 @@
$ num
CANON.C
CANON.lis
$ num
CODEGEN.C
CODEGEN.lis
$ num
CSKELS.C
CSKELS.lis
$ num
INIT.C
INIT.lis
$ num
INTERF.C
INTERF.lis
$ num
MAIN.C
MAIN.lis
$ num
OPTAB.C
OPTAB.lis
$ num
PUTEXPR.C
PUTEXPR.lis
$ num
SMATCH.C
SMATCH.lis
$ num
SUCOMP.C
SUCOMP.lis
$ num
TABL.C
TABL.lis
$ num
UTIL.C
UTIL.lis
$ num
VERSION.C
VERSION.lis
$ num
CGEN.H
CGEN.lst
$ num
CSKEL.H
CSKEL.lst
$ num
ICODE.H
ICODE.lst
$ num
MACHINE.H
MACHINE.lst

View File

@@ -0,0 +1,10 @@
/*
* Use this file to determine what kind of machine you want the
* Alcyon stuff to run on ....
*/
/*#define MC68000 1*/ /* 68000 version */
/*#define VAX 1*/ /* VAX Version */
#define PDP11 1 /* PDP-11 Version*/
/*#define CPM 1*/ /* CP/M Operating System*/
#define UNIX 1 /* UNIX Operating System*/
/*#define VMS 1*/ /* VMS Operating System*/

View File

@@ -0,0 +1,10 @@
/*
* Use this file to determine what kind of machine you want the
* Alcyon stuff to run on ....
*/
#define MC68000 1 /* 68000 version */
/*#define VAX 1*/ /* VAX Version */
/*#define PDP11 1*/ /* PDP-11 Version*/
#define CPM 1 /* CP/M Operating System*/
/*#define UNIX 1*/ /* UNIX Operating System*/
/*#define VMS 1*/ /* VMS Operating System*/

View File

@@ -0,0 +1,10 @@
/*
* Use this file to determine what kind of machine you want the
* Alcyon stuff to run on ....
*/
/*#define MC68000 1*/ /* 68000 version */
#define VAX 1 /* VAX Version */
/*#define PDP11 1*/ /* PDP-11 Version*/
/*#define CPM 1*/ /* CP/M Operating System*/
/*#define UNIX 1*/ /* UNIX Operating System*/
#define VMS 1 /* VMS Operating System*/

View File

@@ -0,0 +1,10 @@
/*
* Use this file to determine what kind of machine you want the
* Alcyon stuff to run on ....
*/
/*#define MC68000 1*/ /* 68000 version */
#define VAX 1 /* VAX Version */
/*#define PDP11 1*/ /* PDP-11 Version*/
/*#define CPM 1*/ /* CP/M Operating System*/
/*#define UNIX 1*/ /* UNIX Operating System*/
#define VMS 1 /* VMS Operating System*/

View File

@@ -0,0 +1,429 @@
/*
Copyright 1982
Alcyon Corporation
8716 Production Ave.
San Diego, Ca. 92121
*/
char *version "@(#) c168 code generator 4.0 - Feb 10, 1983";
#include "cgen.h"
#include "cskel.h"
char *opap;
int errflg;
int nextlabel 10000;
char *readtree();
char *readsym();
/* main - main routine, handles arguments and files*/
main(argc,argv) /* returns - none*/
int argc; /* arg count*/
char **argv; /* arg pointers*/
{
register char *q;
register int i;
#ifdef VERSADOS
lflag++;
#endif
for( i = 3; i < argc; i++ ) {
q = argv[i];
if( *q++ != '-' )
usage(argc,argv,1);
while( 1 ) {
switch( *q++ ) {
case 'D':
case 'd':
dflag++;
continue;
case 'L':
case 'l':
lflag++;
continue;
case 'E':
case 'e':
eflag++;
continue;
case 'F':
case 'f':
fflag++;
continue;
case 'M':
case 'm':
mflag++;
continue;
case 'O':
case 'o':
oflag++;
continue;
case 'C':
case 'c':
cflag++;
continue;
case '\0':
break;
default:
usage(argc,argv,2);
}
break;
}
}
if( argc < 3 )
usage(argc,argv,3);
if( fopen(argv[1],&ibuf,0) < 0 ) /* 3rd arg for versados */
ferror("can't open %s\n",argv[1]);
if( fcreat(argv[2],&obuf,0) < 0 ) /* 3rd arg for versados */
ferror("can't create %s\n",argv[2]);
readicode();
v6flush(&obuf);
exit(errcnt!=0);
}
/* readicode - read intermediate code and dispatch output*/
/* This copies assembler lines beginning with '(' to assembler*/
/* output and builds trees starting with '.' line.*/
readicode() /*returns - none*/
{
register int c;
register struct tnode *tp;
while( (c=getc(&ibuf)) > 0 ) {
switch(c) {
case '.':
lineno = readint();
opap = exprarea;
if( tp = readtree() ) {
#ifndef NODEBUG
if( cflag )
putexpr("readicode",tp);
#endif
switch( tp->t_op ) {
case INIT:
outinit(tp->t_left);
break;
case CFORREG:
outcforreg(tp->t_left);
break;
case IFGOTO:
outifgoto(tp->t_left,tp->t_type,tp->t_su);
break;
default:
outexpr(tp);
break;
}
}
break;
case '(':
while( (c=getc(&ibuf)) != '\n' )
putchar(c);
putchar(c);
break;
default:
error("intermediate code error %c,%d",c,c);
break;
}
}
}
/* readtree - recursive intermediate code tree read*/
char *readtree() /* returns ptr to expression tree*/
{
register int op, type, sc;
register struct tnode *tp, *rtp;
char sym[SSIZE];
long l;
if( (op=readint()) <= 0 )
return(0);
type = readint();
switch( op ) {
case SYMBOL:
if( (sc=readint()) == EXTERNAL )
tp = cenalloc(type,sc,readsym(sym));
else
tp = snalloc(type,sc,readint(),0,0);
break;
case CINT:
tp = cnalloc(type,readint());
break;
case CLONG:
l.hiword = readint();
l.loword = readint();
tp = lcnalloc(type,l);
break;
case CFLOAT: /* [vlh] 3.4 */
l.hiword = readint();
l.loword = readint();
tp = fpcnalloc(type,l);
break;
case IFGOTO:
case BFIELD:
sc = readint();
if( tp = readtree() )
tp = tnalloc(op,type,sc,0,tp,null);
break;
default:
if( binop(op) ) {
if( !(tp=readtree()) )
return(0);
if( !(rtp=readtree()) )
return(0);
tp = tnalloc(op,type,0,0,tp,rtp);
}
else if( tp = readtree() )
tp = tnalloc(op,type,0,0,tp,null);
break;
}
return(tp);
}
/* readint - reads an integer value from intermediate code*/
readint()
{
register int i, c;
i = 0;
while(1) {
switch( c = getc(&ibuf) ) {
case '.':
case '\n':
return(i);
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
i =<< 4;
i =+ (c-'0');
break;
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
i =<< 4;
i =+ (c-('a'-10));
break;
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
i =<< 4;
i =+ (c-('A'-10));
break;
default:
error("intermediate code error - %c,%d",c,c);
}
}
}
/* readsym - read a symbol from intermediate code*/
char *readsym(sym)
char *sym;
{
register int i, c;
register char *s;
for( i = SSIZE, s = sym; (c=getc(&ibuf)) != '\n'; )
if( --i >= 0 )
*s++ = c;
if( i > 0 )
*s = '\0';
return(sym);
}
/* error - output an error message*/
error(s,x1,x2,x3,x4,x5,x6)
char *s;
int x1, x2, x3, x4, x5, x6;
{
errcnt++;
errflg++;
if( lineno != 0 )
printf("** %d: ",lineno);
printf(s,x1,x2,x3,x4,x5,x6);
putchar('\n');
errflg--;
}
/* ferror - output error message and die*/
ferror(s,x1,x2,x3,x4,x5,x6)
char *s;
int x1, x2, x3, x4, x5, x6;
{
error(s,x1,x2,x3,x4,x5,x6);
exit(1);
}
/* tnalloc - allocate binary expression tree node*/
/* returns ptr to node made.*/
char *tnalloc(op,type,info,dummy,left,right)
int op; /* operator*/
int type; /* resultant node type*/
int info; /* info field*/
int dummy; /* dummy field - used to match pass1 args*/
struct tnode *left; /* left sub-tree*/
struct tnode *right; /* righst sub-tree*/
{
register struct tnode *tp;
tp = talloc(sizeof(*tp));
tp->t_op = op;
tp->t_type = type;
tp->t_su = info; /* info for bit-field & condbr's*/
tp->t_left = left;
tp->t_right = right;
return(tp);
}
/* cnalloc - allocate constant expression tree node*/
char *cnalloc(type,value) /* returns pointer to node alloced*/
int type; /* type of constant*/
int value; /* value of constant*/
{
register struct conode *cp;
cp = talloc(sizeof(*cp));
cp->t_op = CINT;
cp->t_type = type;
cp->t_value = value;
return(cp);
}
/* lcnalloc - allocate constant expression tree node*/
char *lcnalloc(type,value) /* returns pointer to node alloced*/
int type; /* type of constant*/
long value; /* value of constant*/
{
register struct lconode *cp;
cp = talloc(sizeof(*cp));
cp->t_op = CLONG;
cp->t_type = type;
cp->t_lvalue = value;
return(cp);
}
/* fpcnalloc - allocate constant expression tree node*/
char *fpcnalloc(type,value) /* returns pointer to node alloced*/
int type; /* type of constant*/
long value; /* value of constant*/
{ /* [vlh] 3.4 */
register struct lconode *cp;
cp = talloc(sizeof(*cp));
cp->t_op = CFLOAT;
cp->t_type = type;
cp->t_lvalue = value;
return(cp);
}
/* talloc - allocate expression tree area*/
char *talloc(size) /* returns pointer to area alloced*/
int size; /* number of bytes to alloc*/
{
register char *p;
p = opap;
if( p + size >= &exprarea[EXPSIZE] )
ferror("expression too complex");
opap = p + size;
return(p);
}
/* symcopy - copy symbol*/
symcopy(sym1,sym2) /* returns - none*/
char *sym1; /* from symbol*/
char *sym2; /* to symbol*/
{
register char *p, *q;
register int i;
for( p = sym1, q = sym2, i = SSIZE; --i >= 0; )
*q++ = (*p ? *p++ : '\0');
}
/* usage - ouput usage message*/
usage(argc,argv,n)
char *argv[];
{
register int i;
error("usage call #%d:\n",n);
for (i=0; i<argc; i++) error(" argv[%d] = %s\n",i,argv[i]);
ferror("usage: c168 icode asm [-DLmec]");
}
/* putchar - special version*/
/* This allows the use of printf for error messages, debugging*/
/* output and normal output.*/
putchar(c) /* returns - none*/
char c; /* character to output*/
{
if( errflg ) /*error message?*/
write(1,&c,1); /*write to standard output*/
else {
if( dflag > 1 )
write(1,&c,1); /*to standard output*/
putc(c,&obuf); /*put to assembler file*/
}
}
v6flush(v6b)
struct iobuf *v6b;
{
register i;
i = BLEN - v6b->nunused;
v6b->nunused = BLEN;
v6b->xfree = &(v6b->buff[0]);
if(write(v6b->fildes,v6b->xfree,i) != i)
return(-1);
return(0);
}
printf(string,a,b,c,d,e,f,g)
char *string;
int a,b,c,d,e,f,g;
{
char area[256];
register char *p;
sprintf(area,string,a,b,c,d,e,f,g);
for(p = &area[0]; *p; p++)
putchar(*p);
}

View File

@@ -0,0 +1,103 @@
$1stat machine.h=rw
$1pip machine.h=machine.68k
$1cp68 -i 0$1 CANON.c $1x.i
$1c068 $1x.i $1x.ic $1x.st
$1c168 $1x.ic CANON.s -LD
era $1x.i
era $1x.ic
era $1x.st
$1as68 -s 0$1 -f $1 -l -u CANON.s
era CANON.s
$1cp68 -i 0$1 CODEGEN.c $1x.i
$1c068 $1x.i $1x.ic $1x.st
$1c168 $1x.ic CODEGEN.s -LD
era $1x.i
era $1x.ic
era $1x.st
$1as68 -s 0$1 -f $1 -l -u CODEGEN.s
era CODEGEN.s
$1cp68 -i 0$1 CSKELS.c $1x.i
$1c068 $1x.i $1x.ic $1x.st
$1c168 $1x.ic CSKELS.s -LD
era $1x.i
era $1x.ic
era $1x.st
$1as68 -s 0$1 -f $1 -l -u CSKELS.s
era CSKELS.s
$1cp68 -i 0$1 INTERF.c $1x.i
$1c068 $1x.i $1x.ic $1x.st
$1c168 $1x.ic INTERF.s -LD
era $1x.i
era $1x.ic
era $1x.st
$1as68 -s 0$1 -f $1 -l -u INTERF.s
era INTERF.s
$1cp68 -i 0$1 MAIN.c $1x.i
$1c068 $1x.i $1x.ic $1x.st
$1c168 $1x.ic MAIN.s -LD
era $1x.i
era $1x.ic
era $1x.st
$1as68 -s 0$1 -f $1 -l -u MAIN.s
era MAIN.s
$1cp68 -i 0$1 OPTAB.c $1x.i
$1c068 $1x.i $1x.ic $1x.st
$1c168 $1x.ic OPTAB.s -LD
era $1x.i
era $1x.ic
era $1x.st
$1as68 -s 0$1 -f $1 -l -u OPTAB.s
era OPTAB.s
$1cp68 -i 0$1 PUTEXPR.c $1x.i
$1c068 $1x.i $1x.ic $1x.st
$1c168 $1x.ic PUTEXPR.s -LD
era $1x.i
era $1x.ic
era $1x.st
$1as68 -s 0$1 -f $1 -l -u PUTEXPR.s
era PUTEXPR.s
$1cp68 -i 0$1 SMATCH.c $1x.i
$1c068 $1x.i $1x.ic $1x.st
$1c168 $1x.ic SMATCH.s -LD
era $1x.i
era $1x.ic
era $1x.st
$1as68 -s 0$1 -f $1 -l -u SMATCH.s
era SMATCH.s
$1cp68 -i 0$1 SUCOMP.c $1x.i
$1c068 $1x.i $1x.ic $1x.st
$1c168 $1x.ic SUCOMP.s -LD
era $1x.i
era $1x.ic
era $1x.st
$1as68 -s 0$1 -f $1 -l -u SUCOMP.s
era SUCOMP.s
$1cp68 -i 0$1 TABL.c $1x.i
$1c068 $1x.i $1x.ic $1x.st
$1c168 $1x.ic TABL.s -LD
era $1x.i
era $1x.ic
era $1x.st
$1as68 -s 0$1 -f $1 -l -u TABL.s
era TABL.s
$1cp68 -i 0$1 UTIL.c $1x.i
$1c068 $1x.i $1x.ic $1x.st
$1c168 $1x.ic UTIL.s -LD
era $1x.i
era $1x.ic
era $1x.st
$1as68 -s 0$1 -f $1 -l -u UTIL.s
era UTIL.s
link $1

View File

@@ -0,0 +1,322 @@
/*
Copyright 1982
Alcyon Corporation
8716 Production Ave.
San Diego, Ca. 92121
*/
#include "cgen.h"
#define I_NULL 0
#define I_ADD 1
#define I_INC 2
#define I_SUB 3
#define I_DEC 4
#define I_MULS 5
#define I_MULU 6
#define I_DIVS 7
#define I_DIVU 8
#define I_ASR 9
#define I_LSR 10
#define I_ASL 11
#define I_LSL 12
#define I_AND 13
#define I_OR 14
#define I_EOR 15
#define I_NEG 16
#define I_NOT 17
#define I_MOVE 18
#define I_CLR 19
#define I_CMP 20
#define I_TST 21
#define I_LMUL 22
#define I_LDIV 23
#define I_LREM 24
#define I_LEML 25
#define I_LERM 27
#define I_BEQ 28
#define I_BNE 29
#define I_BGT 30
#define I_BGE 31
#define I_BLT 32
#define I_BLE 33
#define I_BLS 34
#define I_BLO 35
#define I_BCC 36
#define I_BHI 37
#define I_BRA 38
#define I_NOP 39
#define I_BTST 40
char *mnemonics[] {
"",
"add",
"inc",
"sub",
"dec",
"muls",
"mulu",
"divs",
"divu",
"asr",
"lsr",
"asl",
"lsl",
"and",
"or",
"eor",
"neg",
"not",
"move",
"clr",
"cmp",
"tst",
"lmul",
"_ldiv",
"lrem",
"almul",
"aldiv",
"alrem",
"beq",
"bne",
"bgt",
"bge",
"blt",
"ble",
"bls",
"blo",
"bcc",
"bhi",
"jmp",
"*nop",
"btst",
};
#define FE_EQOP 1
#define FE_ASSIGN 2
#define FE_EQSHFT 3
#define FE_EQXOR 4
#define FE_EQADDR 5
#define FC_FIX 6
#define FC_REL 7
#define FC_BTST 8
#define FS_OP 9
#define FS_ITL 10
#define FS_LD 11
#define FR_ADD 12
#define FR_MULT 13
#define FR_DIV 14
#define FR_SHFT 15
#define FR_XOR 16
#define FR_NEG 17
#define FR_EQOP 18
#define FR_POSTOP 19
#define FR_ASSIGN 20
#define FR_EQMULT 21
#define FR_EQDIV 22
#define FR_EQSHFT 23
#define FR_EQXOR 24
#define FR_CALL 25
#define FR_ITL 26
#define FR_LTI 27
#define FR_LD 28
#define FR_EQADDR 29
#define FR_EQNOT 30
#define FE_EQNOT 31
#define FR_DOCAST 32
#define FS_DOCAST 33
#define FR_FTOL 34
#define FR_LTOF 35
#define FR_FTOI 36
#define FR_ITOF 37
#define FE_EQMULT 38
#define FE_EQDIV 39
#define FE_EQMOD 40
#define FR_TOCHAR 41
char
fe_eqop[], /* 1=FE_EQOP */
fe_assign[], /* 2=FE_ASSIGN */
fe_eqshft[], /* 3=FE_EQSHFT */
fe_eqxor[], /* 4=FE_EQXOR */
fe_eqaddr[], /* 5=FE_EQADDR */
fc_fix[], /* 6=FC_FIX */
fc_rel[], /* 7=FC_REL */
fc_btst[], /* 8=FC_BTST */
fs_op[], /* 9=FS_OP */
fs_itl[], /* 10=FS_ITL */
fs_ld[], /* 11=FS_LD */
fr_op[], /* 12=FR_OP */
fr_mult[], /* 13=FR_MULT */
fr_div[], /* 14=FR_DIV */
fr_shft[], /* 15=FR_SHFT */
fr_xor[], /* 16=FR_XOR */
fr_neg[], /* 17=FR_NEG */
fr_eqop[], /* 18=FR_EQOP */
fr_postop[], /* 19=FR_POSTOP */
fr_assign[], /* 20=FR_ASSIGN */
fr_eqmult[], /* 21=FR_EQMULT */
fr_eqdiv[], /* 22=FR_EQDIV */
fr_eqshft[], /* 23=FR_EQSHFT */
fr_eqxor[], /* 23=FR_EQXOR */
fr_call[], /* 24=FR_CALL */
fr_itl[], /* 25=FR_ITL */
fr_lti[], /* 26=FR_LTI */
fr_ld[], /* 27=FR_LD */
fr_eqaddr[], /* 28=FR_EQADDR */
fr_eqnot[], /* 29=FR_EQNOT */
fe_eqnot[], /* 30=FE_EQNOT */
fr_docast[], /* 31=FR_DOCAST */
fs_docast[], /* 32=FS_DOCAST */
fr_ftol[], /* 34=FE_FTOL */
fr_ltof[], /* 35=FE_LTOF */
fr_ftoi[], /* 36=FE_FTOI */
fr_itof[], /* 37=FE_ITOF */
fe_eqmult[], /* 38=FE_EQMULT */
fe_eqdiv[], /* 39=FE_EQDIV */
fe_eqmod[], /* 40=FE_EQMOD */
fr_tochar[]; /* 41=FR_TOCHAR */
char *codeskels[] {
0, /*NULL*/
fe_eqop, /*1=FE_EQOP*/
fe_assign, /*2=FE_ASSIGN*/
fe_eqshft, /*3=FE_EQSHFT*/
fe_eqxor, /*4=FE_EQXOR*/
fe_eqaddr, /*5=FE_EQADDR*/
fc_fix, /*6=FC_FIX*/
fc_rel, /*7=FC_REL*/
fc_btst, /*8=FC_BTST*/
fs_op, /*9=FS_OP*/
fs_itl, /*10=FS_ITL*/
fs_ld, /*11=FS_LD*/
fr_op, /*12=FR_OP*/
fr_mult, /*13=FR_MULT*/
fr_div, /*14=FR_DIV*/
fr_shft, /*15=FR_SHFT*/
fr_xor, /*16=FR_XOR*/
fr_neg, /*17=FR_NEG*/
fr_eqop, /*18=FR_EQOP*/
fr_postop, /*19=FR_POSTOP*/
fr_assign, /*20=FR_ASSIGN*/
fr_eqmult, /*21=FR_EQMULT*/
fr_eqdiv, /*22=FR_EQDIV*/
fr_eqshft, /*23=FR_EQSHFT*/
fr_eqxor, /*24=FR_EQXOR*/
fr_call, /*25=FR_CALL*/
fr_itl, /*26=FR_ITL*/
fr_lti, /*27=FR_LTI*/
fr_ld, /*28=FE_LD*/
fr_eqaddr, /*29=FE_EQADDR*/
fr_eqnot, /*30=FE_EQNOT*/
fe_eqnot, /*31=FE_EQNOT*/
fr_docast, /*32=FE_DOCAST*/
fs_docast, /*33=FS_DOCAST*/
fr_ftol, /*34=FE_FTOL*/
fr_ltof, /*35=FE_LTOF*/
fr_ftoi, /*36=FE_FTOI*/
fr_itof, /*37=FE_ITOF*/
fe_eqmult, /*38=FE_EQMULT*/
fe_eqdiv, /*39=FE_EQDIV*/
fe_eqmod, /*40=FE_EQMOD*/
fr_tochar, /*41=FR_TOCHAR*/
};
/*
*This is the major table directing the code generation process.
*It is indexed by an O_op operator, which is obtained from the
*opinfo table for an intermediate code operator. The actual
*code skeleton macros are in cskels.c, which are in a linked
*list in order of decreasing order of difficulty.
*/
char optab[][6] {
/* I I2 effect cc's stack register*/
I_NULL, I_NULL, I_NULL, I_NULL, I_NULL, I_NULL, /*0=NULL*/
I_ADD, I_INC, I_NULL, FC_FIX, FS_OP, FR_ADD, /*1=ADD*/
I_SUB, I_DEC, I_NULL, FC_FIX, FS_OP, FR_ADD, /*2=SUB*/
I_MULS, I_MULU, I_NULL, FC_FIX, I_NULL, FR_MULT, /*3=MULT*/
I_DIVS, I_DIVU, I_NULL, FC_FIX, I_NULL, FR_DIV, /*4=DIV*/
I_DIVS, I_DIVU, I_NULL, I_NULL, I_NULL, FR_DIV, /*5=MOD*/
I_ASR, I_LSR, I_NULL, FC_FIX, I_NULL, FR_SHFT, /*6=RSH*/
I_ASL, I_LSL, I_NULL, FC_FIX, I_NULL, FR_SHFT, /*7=LSH*/
I_AND, I_AND, I_NULL, FC_FIX, FS_OP, FR_ADD, /*8=AND*/
I_OR, I_OR, I_NULL, FC_FIX, FS_OP, FR_ADD, /*9=OR*/
I_EOR, I_EOR, I_NULL, FC_FIX, I_NULL, FR_XOR, /*10=XOR*/
I_NULL, I_NULL, I_NULL, FC_FIX, I_NULL, I_NULL, /*11=NOT*/
I_NEG, I_NEG, I_NULL, FC_FIX, I_NULL, FR_NEG, /*12=NEG*/
I_NOT, I_NOT, I_NULL, I_NULL, I_NULL, FR_NEG, /*13=COMPL*/
I_SUB, I_DEC, FE_EQOP, FC_FIX, I_NULL, FR_EQOP, /*14=PREDEC*/
I_ADD, I_INC, FE_EQOP, FC_FIX, I_NULL, FR_EQOP, /*15=PREINC*/
I_SUB, I_DEC, FE_EQOP, I_NULL, I_NULL, FR_POSTOP, /*16=POSTDEC*/
I_ADD, I_INC, FE_EQOP, I_NULL, I_NULL, FR_POSTOP, /*17=POSTINC*/
I_MOVE, I_CLR, FE_ASSIGN, I_NULL, I_NULL, FR_ASSIGN, /*18=ASSIGN*/
I_ADD, I_INC, FE_EQOP, I_NULL, I_NULL, FR_EQOP, /*19=EQADD*/
I_SUB, I_DEC, FE_EQOP, I_NULL, I_NULL, FR_EQOP, /*20=EQSUB*/
I_MULS, I_MULU, FE_EQMULT, FC_FIX, I_NULL, FR_EQMULT, /*21=EQMULT*/
I_DIVS, I_DIVU, FE_EQDIV, FC_FIX, I_NULL, FR_EQDIV, /*22=EQDIV*/
I_DIVS, I_DIVU, FE_EQMOD, I_NULL, I_NULL, FR_EQDIV, /*23=EQMOD*/
I_ASR, I_LSR, FE_EQSHFT, I_NULL, I_NULL, FR_EQSHFT, /*24=EQRSH*/
I_ASL, I_LSL, FE_EQSHFT, I_NULL, I_NULL, FR_EQSHFT, /*25=EQLSH*/
I_AND, I_AND, FE_EQOP, I_NULL, I_NULL, FR_EQOP, /*26=EQAND*/
I_OR, I_OR, FE_EQOP, I_NULL, I_NULL, FR_EQOP, /*27=EQOR*/
I_EOR, I_EOR, FE_EQXOR, FC_FIX, I_NULL, FR_EQXOR, /*28=EQXOR*/
I_NULL, I_NULL, I_NULL, I_NULL, I_NULL, FR_CALL, /*29=FJSR*/
I_CMP, I_TST, I_NULL, FC_REL, I_NULL, I_NULL, /*30=EQUALS*/
I_CMP, I_TST, I_NULL, FC_REL, I_NULL, I_NULL, /*31=NEQUALS*/
I_CMP, I_TST, I_NULL, FC_REL, I_NULL, I_NULL, /*32=GREAT*/
I_CMP, I_TST, I_NULL, FC_REL, I_NULL, I_NULL, /*33=GREATEQ*/
I_CMP, I_TST, I_NULL, FC_REL, I_NULL, I_NULL, /*34=LESS*/
I_CMP, I_TST, I_NULL, FC_REL, I_NULL, I_NULL, /*35=LESSEQ*/
I_NULL, I_NULL, I_NULL, I_NULL, FS_ITL, FR_ITL, /*36=INT2L*/
I_NULL, I_NULL, I_NULL, I_NULL, I_NULL, FR_LTI, /*37=LONG2I*/
I_BTST, I_BTST, I_NULL, FC_BTST, I_NULL, I_NULL, /*38=BTST*/
I_CMP, I_TST, I_NULL, FC_REL, FS_LD, FR_LD, /*39=LOAD*/
I_MULS, I_MULU, I_NULL, I_NULL, I_NULL, FR_MULT, /*40=LMULT*/
I_DIVS, I_DIVU, I_NULL, I_NULL, I_NULL, FR_DIV, /*41=LDIV*/
I_DIVS, I_DIVU, I_NULL, I_NULL, I_NULL, FR_DIV, /*42=LMOD*/
I_NULL, I_NULL, I_NULL, I_NULL, I_NULL, I_NULL, /*43=NULL*/
I_NULL, I_NULL, I_NULL, I_NULL, I_NULL, I_NULL, /*44=NULL*/
I_NULL, I_NULL, I_NULL, I_NULL, I_NULL, I_NULL, /*45=NULL*/
I_NULL, I_NULL, FE_EQADDR, I_NULL, I_NULL, FR_EQADDR, /*46=EQADDR*/
I_NOT, I_NOT, FE_EQNOT, I_NULL, I_NULL, FR_EQNOT, /*47=EQNOT*/
I_NEG, I_NEG, FE_EQNOT, I_NULL, I_NULL, FR_EQNOT, /*48=EQNEG*/
I_NULL, I_NULL, I_NULL, I_NULL, FS_DOCAST, FR_DOCAST, /*49=DOCAST*/
I_NULL, I_NULL, I_NULL, I_NULL, I_NULL, I_NULL, /*50=STASSIGN*/
I_NULL, I_NULL, I_NULL, I_NULL, I_NULL, FR_LTOF, /*51=LONG2F*/
I_NULL, I_NULL, I_NULL, I_NULL, I_NULL, FR_FTOL, /*52=FLOAT2L*/
I_NULL, I_NULL, I_NULL, I_NULL, I_NULL, FR_ITOF, /*53=INT2F*/
I_NULL, I_NULL, I_NULL, I_NULL, I_NULL, FR_FTOI, /*54=FLOAT2I*/
I_NULL, I_NULL, I_NULL, I_NULL, I_NULL, FR_TOCHAR, /*55=TOCHAR*/
};
/*this maps comparison operators and comparison types into the*/
/*actual branch opcode used.*/
char brtab[][2] {
I_BEQ, I_BEQ, /*EQUALS*/
I_BNE, I_BNE, /*NEQUALS*/
I_BGT, I_BHI, /*GREAT*/
I_BGE, I_BCC, /*GREATEQ*/
I_BLT, I_BLO, /*LESS*/
I_BLE, I_BLS, /*LESSEQ*/
};
/*turns !x>y into x<=y*/
int invrel[] { NEQUALS, EQUALS, LESSEQ, LESS, GREATEQ, GREAT };
/*turns x>y into y<=x*/
int swaprel[] { EQUALS, NEQUALS, LESS, LESSEQ, GREAT, GREATEQ };
/*code skeleton built-in strings*/
char *strtab[] {
"move", /*MOV*/
"move.l", /*MOVL*/
"jsr", /*JSR*/
"clr", /*CLR*/
"clr.l", /*CLRL*/
"ext.w", /*EXTW*/
"ext.l", /*EXTL*/
"lea", /*LEA*/
"(sp)", /*STK*/
};

View File

@@ -0,0 +1,255 @@
/*
Copyright 1982
Alcyon Corporation
8716 Production Ave.
San Diego, Ca. 92121
*/
#include "cgen.h"
#ifndef NODEBUG
char invalid[] "INVALID";
char *opname[] {
invalid, /*0*/
"+", /*1*/
"-", /*2*/
"*", /*3*/
"/", /*4*/
"%", /*5*/
">>", /*6*/
"<<", /*7*/
"&", /*8*/
"|", /*9*/
"^", /*10*/
"!", /*11*/
"U-", /*12*/
"~", /*13*/
"--p", /*14*/
"++p", /*15*/
"p--", /*16*/
"p++", /*17*/
"=", /*18*/
"+=", /*19*/
"-=", /*20*/
"*=", /*21*/
"/=", /*22*/
"%=", /*23*/
">>=", /*24*/
"<<=", /*25*/
"&=", /*26*/
"|=", /*27*/
"^=", /*28*/
"jsr", /*29*/
"==", /*30*/
"!=", /*31*/
">", /*32*/
">=", /*33*/
"<", /*34*/
"<=", /*35*/
"int->long", /*36*/
"long->int", /*37*/
"btst", /*38*/
"load", /*39*/
"long*", /*40*/
"long/", /*41*/
"long%", /*42*/
"long*=", /*43*/
"long/=", /*44*/
"long%=", /*45*/
"=addr", /*46*/
"=not", /*47*/
"=neg", /*48*/
"docast", /*49*/
"st=", /*50*/
"long->float", /*51*/
"float->long", /*52*/
"int->float", /*53*/
"float->int", /*54*/
"tochar", /*55*/
invalid, /*56*/
invalid, /*57*/
invalid, /*58*/
invalid, /*59*/
"U&", /*60*/
"U*", /*61*/
"&&", /*62*/
"||", /*63*/
"?", /*64*/
":", /*65*/
",", /*66*/
"cint", /*67*/
"clong", /*68*/
"symbol", /*69*/
"++a", /*70*/
"a--", /*71*/
"call", /*72*/
"call()", /*73*/
"bitfield", /*74*/
"if", /*75*/
"init", /*76*/
"loadR0", /*77*/
"divlong", /*78*/
};
char *types[] {
invalid, /*0=TYPELESS*/
"char", /*1=CHAR*/
invalid, /*2=SHORT*/
"int", /*3=INT*/
"long", /*4=LONG*/
invalid, /*5=UCHAR*/
invalid, /*6=USHORT*/
"uint", /*7=UINT*/
invalid, /*8=ULONG*/
"float", /*9=FLOAT*/
invalid, /*10=DOUBLE*/
"struct", /*11=STRUCT*/
invalid, /*12=undefined*/
invalid, /*13=undefined*/
invalid, /*14=undefined*/
invalid, /*15=undefined*/
};
char *suvals[] {
"zero",
"one",
"quick",
"small",
"constant",
"Areg",
"Dreg",
"addressable",
"loadable",
"easy",
"hard",
"veryhard",
};
int level;
putexpr(name,tp)
char *name;
struct tnode *tp;
{
printf("%s\n",name);
putsexpr(tp);
}
putsexpr(tp)
struct tnode *tp;
{
register struct tnode *ltp;
level++;
ltp = tp->t_left;
outlevel();
printf("%s ",opname[tp->t_op]);
if( tp->t_op == BFIELD || tp->t_op == IFGOTO ) {
if( tp->t_op == BFIELD )
printf("off=%d len=%d\n",(tp->t_su>>8)&0377,tp->t_su&0377);
else
printf("%s goto L%d\n",tp->t_type?"TRUE":"FALSE",tp->t_su);
putsexpr(tp->t_left);
level--;
return;
}
puttsu(tp);
switch( tp->t_op ) {
case DCLONG:
case CLONG:
case CFLOAT: /*[vlh] 3.4 */
printf(" %x.%x\n",tp->t_lvalue.hiword,tp->t_lvalue.loword);
break;
case CINT:
printf(" %d\n",tp->t_value);
break;
case AUTODEC:
case AUTOINC:
printf(" R%d\n",tp->t_reg);
break;
case SYMBOL:
switch( tp->t_sc ) {
case REGISTER:
printf(" R%d",tp->t_reg);
break;
case CINDR:
printf(" %d\n",tp->t_offset);
break;
case CLINDR:
case CFINDR: /* [vlh] 3.4 */
printf(" %x.%x\n",tp->t_offset,tp->t_ssp);
break;
case REGOFF:
printf(" %d(R%d)",tp->t_offset,tp->t_reg);
break;
case EXTERNAL:
case EXTOFF:
printf(" %s+%d",tp->t_symbol,tp->t_offset);
if( tp->t_sc == EXTOFF )
printf("(R%d)",tp->t_reg);
break;
case STATIC:
case STATOFF:
printf(" L%d+%d",tp->t_label,tp->t_offset);
if( tp->t_sc == STATOFF )
printf("(R%d)",tp->t_reg);
break;
case INDEXED:
printf(" %d(R%d,R%d)",tp->t_offset,tp->t_reg,tp->t_xreg);
break;
}
putchar('\n');
break;
case IFGOTO:
putsexpr(tp->t_left);
break;
default:
putchar('\n');
putsexpr(tp->t_left);
if( binop(tp->t_op) )
putsexpr(tp->t_right);
break;
}
level--;
}
outlevel()
{
register int i;
for( i = 0; i < level; i++ )
putchar('\t');
}
puttsu(tp)
struct tnode *tp;
{
register int i;
if( suptype(tp->t_type) )
putchar('*');
printf("%s ",types[btype(tp->t_type)]);
if( tp->t_su != 0 || (tp->t_op == CINT && tp->t_value == 0) ) {
i = tp->t_su >> 8;
if( i > 15 || i < 0 )
printf("INVALID");
else
printf("%s",suvals[tp->t_su>>8]);
}
}
#endif

View File

@@ -0,0 +1,20 @@
E:SEND CANON.C
E:SEND CODEGEN.C
E:SEND CSKELS.C
E:SEND INTERF.C
E:SEND MAIN.C
E:SEND OPTAB.C
E:SEND PUTEXPR.C
E:SEND SMATCH.C
E:SEND SUCOMP.C
E:SEND TABL.C
E:SEND UTIL.C
E:SEND VERSION.C
E:SEND CGEN.H
E:SEND CSKEL.H
E:SEND ICODE.H
E:SEND MACHINE.68K
E:SEND LINK.SUB
E:SEND MAKE.SUB
E:SEND MACHINE.H
E:SEND SEND13.SUB

View File

@@ -0,0 +1,517 @@
/*
Copyright 1982
Alcyon Corporation
8716 Production Ave.
San Diego, Ca. 92121
*/
/* Code Skeleton expansion and matching */
#include "cgen.h"
#include "cskel.h"
#define SK_TYPE(x) (x&017)
/* expand - code skeleton expansion*/
/* Handles the expansion of code skeleton macros.*/
expand(tp,cookie,freg,skp) /* returns register result is in*/
struct tnode *tp; /* pointer to expression tree*/
int cookie; /* goal of expression tree*/
int freg; /* register to leave results in*/
struct skeleton *skp; /* pointer to code skeleton*/
{
register int op, nreg, reg;
register int c;
register int extf, i2f;
register struct tnode *ltp, *rtp;
register char *p;
register int i, inaddreg, sreg, flag, subtrees, scookie;
register char *macro;
#ifndef NODEBUG
if( eflag )
printf("expand op=%d left=%x right=%x skp=%o\n",tp->t_op,
skp->sk_left,skp->sk_right,skp);
#endif
if( ((op=tp->t_op) >= MULT && op <= XOR) || tp->t_type == CHAR )
freg = dreg(freg);
macro = skp->sk_def;
extf = 0;
i2f = 0;
rtp = ltp = tp->t_left;
subtrees = 1;
if( binop(op) ) {
subtrees++;
rtp = tp->t_right;
if( (longorptr(tp->t_type)) && (op == DIV || op == MOD ||
(op != MULT && (isdreg(freg)) &&
!(longorptr(ltp->t_type)) && !(longorptr(rtp->t_type)))) )
extf++;
switch( op ) {
case RSH:
case LSH:
case EQLSH:
case EQRSH:
if( unsign(ltp->t_type) )
i2f++;
break;
case MULT:
case EQMULT:
case DIV:
case MOD:
case EQDIV:
case EQMOD:
if( unsign(ltp->t_type) || unsign(rtp->t_type) )
i2f++;
break;
}
}
nreg = freg + 1;
while( c = *macro++ ) {
c =& 0xff;
switch( c ) {
default:
putchar(c);
break;
case POP:
stacksize--;
printf("(sp)+");
break;
case POP4:
stacksize--;
popstack(4);
break;
case POP8:
stacksize =- 2;
popstack(8);
break;
case PSH:
if( cookie == FORSP ) /*don't affect sp*/
printf("(sp)");
else
printf("-(sp)");
stacksize++;
break;
case MOV:
case MOVL:
case JSR:
case CLR:
case CLRL:
case EXTW:
case EXTL:
case LEA:
case STK:
printf("%s",strtab[c-128]);
break;
case OPCALL:
if( isfloat(tp->t_type) || isfloat(ltp->t_type) ) {
switch( op ) {
case ADD:
case EQADD:
printf("_fpadd");
break;
case SUB:
case EQSUB:
printf("_fpsub");
break;
case MULT:
case EQMULT:
printf("_fpmult");
break;
case DIV:
case EQDIV:
printf("_fpdiv");
break;
case UMINUS:
case EQNEG:
printf("_fpneg");
break;
case FLOAT2L:
case FLOAT2I:
printf("_fpftol");
break;
case LONG2F:
case INT2F:
printf("_fpltof");
break;
case EQUALS:
case NEQUALS:
case GREAT:
case GREATEQ:
case LESS:
case LESSEQ:
printf("_fpcmp");
break;
default:
error("invalid floating op %d\n",op);
break;
}
}
else {
switch( op ) {
case MULT:
case LMULT:
printf("lmul");
break;
case DIV:
case LDIV:
printf("ldiv");
break;
case MOD:
case LMOD:
printf("lrem");
break;
default:
error("opcall bad op %d",op);
break;
}
}
break;
case TLEFT:
outtype( leafop(op) ? tp->t_type : ltp->t_type );
break;
case TLEFTL:
outatype( leafop(op) ? tp->t_type : ltp->t_type );
break;
case TEITHER:
if( longorptr(rtp->t_type) || longorptr(ltp->t_type) )
outtype(LONG);
break;
case TRIGHT:
outtype(rtp->t_type);
break;
case OP:
case AOP:
if( c == AOP || i2f )
i = optab[op][1];
else
i = optab[op][0];
printf(mnemonics[i]);
break;
case LADDR:
case RADDR:
p = (c==RADDR?rtp:ltp);
outaexpr(p,IMMED);
break;
case CR:
outcreg(freg);
break;
case NR:
outcreg(nreg);
break;
case CAR:
outcreg(areg(freg));
break;
case NAR:
outcreg(areg(nreg));
break;
case EXL:
outextend(ltp,LONG,freg);
break;
case EXRL:
case EXRLN:
outextend(rtp,ltp->t_type,c==EXRL?freg:nreg);
break;
case EXLR:
case EXLRN:
outextend(ltp,rtp->t_type,c==EXLR?freg:nreg);
break;
case LEFT:
case RIGHT:
subtrees--;
case TREE:
p = (c==LEFT?ltp:c==RIGHT?rtp:tp);
flag = *macro++;
scookie = FORREG;
if( flag & S_STACK ) {
if( cookie == FORSP )
scookie = FORSP;
else
scookie = FORSTACK;
}
else if( flag & S_FORCC )
scookie = FORCC;
if( flag & S_NEXT )
reg = nreg;
else
reg = freg;
if( flag & S_INDR ) {
if( p->t_op != INDR )
error("code skeleton error: %d\n",op);
p = p->t_left; /*skip INDR*/
if( coffset(p) ) {
p = p->t_left;
if( longorptr(p->t_type) == 0 && (flag&S_STACK) != 0 )
p = tnalloc(INT2L,LONG,0,0,p);
}
reg = areg(reg);
}
sreg = codegen(p,scookie,reg); /*code for subtree*/
if( scookie == FORREG ) {
if( flag & S_INDR ) {
if( isdreg(sreg) )
outmovr(sreg,areg(reg),p);
}
else if( flag & S_NEXT )
nreg = sreg;
else if( sreg != reg ) {
/*
* result was not in expected register, if remaining sub-tree can be
* compiled using the remaining registers, update current and next
* registers, saving us the trouble of moving the register.
*/
if( c == TREE || ((isdreg(sreg)) && subtrees > 0 &&
((c == LEFT &&
sucomp(rtp,sreg,0) <= skp->sk_right &&
sucomp(rtp,sreg,1) <= SU_ANY) ||
( c == RIGHT &&
sucomp(ltp,sreg,0) <= skp->sk_left &&
sucomp(ltp,sreg,1) <= SU_ANY))) ) {
freg = dreg(sreg);
nreg = freg + 1;
}
else
outmovr(sreg,dreg(freg),p);
}
}
break;
case LOFFSET:
case ROFFSET:
p = (c==LOFFSET) ? ltp->t_left : rtp->t_left;
if((p=coffset(p)) != 0 && (p->t_op != CINT || p->t_value != 0))
outaexpr(p,NOTIMMED);
break;
case MODSWAP:
switch( op ) {
case MOD:
case EQMOD:
case LMOD:
case LEQMOD:
outswap(freg);
}
break;
}
}
if( extf && cookie == FORREG && (isdreg(freg)) ) {
if( unsign(ltp->t_type) || unsign(rtp->t_type) )
outuext(freg);
else
outext(freg);
}
#ifndef NODEBUG
if( eflag )
printf("ending expand skp=%o\n",skp);
#endif
return(freg);
}
/*
* match - try to match expression tree with code skeleton
* Given the expression tree, tries to match the given tree with
* the appropriate code skeleton. The code skeleton list is
* gotten from the root operator and the cookie value. The code
* skeleton list is then searched, checking the Sethy-Ullman numbers
* of the sub-trees against the Sethy-Ullman numbers in the code
* skeleton list. If the Sethy-Ullman numbers are OK, then the
* left and right sub-trees are checked for compatability, e.g.
* integer pointers, etc. If a match is found, the code skeleton
* list pointer is returned.
*/
char *match(tp,cookie,reg) /* returns ptr to code skeleton*/
/* or 0 if no skeleton*/
struct tnode *tp; /* pointer to tree*/
int cookie; /* goal for code expansion*/
int reg; /* register to use*/
{
register struct skeleton *skp;
register int op, bop, opndx;
int i;
register struct tnode *ltp, *rtp;
#ifndef NODEBUG
if( mflag )
printf("match op=%d cookie=%d reg=%d\n",tp->t_op,cookie,reg);
#endif
if( (op=tp->t_op) >= LCGENOP )
return(0);
if( leafop(op) )
ltp = tp;
else
ltp = tp->t_left;
if( (bop=binop(op)) ) {
rtp = tp->t_right;
if( convop(ltp->t_op) ) {
if( op != LSH && notconvop(rtp->t_op) ) {
if( !(unsign(ltp->t_left->t_type)) || op == ASSIGN ) {
tp->t_left = ltp->t_left;
if( (skp=match(tp,cookie,reg)) != 0 )
return(skp);
tp->t_left = ltp;
}
}
}
else if( convop(rtp->t_op) ) {
if( !(unsign(rtp->t_left->t_type)) || op == ASSIGN ) {
tp->t_right = rtp->t_left;
if( (skp=match(tp,cookie,reg)) != 0 )
return(skp);
tp->t_right = rtp;
}
}
}
switch( cookie ) {
case FORCC:
i = 3;
break;
case FOREFF:
i = 2;
break;
case FORSTACK:
case FORSP:
i = 4;
break;
case FORREG:
i = 5;
break;
default:
error("match cookie=%d\n",cookie);
return(0);
}
#ifndef NODEBUG
if( mflag )
printf("match op=%d i=%d ",op,i);
#endif
if( !(i=optab[op][i]) )
return(0);
skp = codeskels[i];
#ifndef NODEBUG
if( mflag )
printf("codeskels[%d]=%o\n",i,skp);
#endif
#ifndef NODEBUG
if(mflag) {
printf("match LEFT ");
puttsu(ltp);
if(bop) {
printf(" RIGHT ");
puttsu(rtp);
}
putchar('\n');
}
#endif
for( ; skp->sk_left != 0; skp++ ) {
#ifndef NODEBUG
if( mflag > 1 )
printf("sk_left=%x sk_right=%x\n",skp->sk_left,skp->sk_right);
#endif
if( !(skelmatch(ltp,skp->sk_left)) )
continue;
if( bop && !(skelmatch(rtp,skp->sk_right)) )
continue;
#ifndef NODEBUG
if( mflag )
printf("match found skp=%o left=%x right=%x\n",skp,
skp->sk_left,skp->sk_right);
#endif
return(skp);
}
return(0);
}
/* skelmatch - sub-tree type matching for match*/
/* This checks a subtree for type compatability in match.*/
skelmatch(tp,skinfo) /* returns 1 if matched, else 0*/
struct tnode *tp; /* pointer to expression tree*/
int skinfo;
{
register int type, unsignf, const, stype;
if( tp->t_su > skinfo || ((skinfo&T_INDR) && tp->t_op != INDR) )
return(0);
stype = SK_TYPE(skinfo);
type = tp->t_type;
if( function(type) )
type = btype(type);
if( unsignf = unsign(type) )
type = basetype(type);
const = 0;
switch( tp->t_op ) {
case CFLOAT: /* [vlh] 3.4 */
case CLONG:
if( tp->t_su > SU_CONST )
break;
case CINT:
const++;
break;
}
switch( stype ) {
case T_CHAR:
return( type == CHAR );
case T_ANY: /*either int or char*/
if( type == CHAR )
return(1);
case T_INT:
return( type == INT || const );
case T_UNSN:
return( unsignf );
case T_LONG:
return( longorptr(type) );
case T_FLOAT:
return( isfloat(type) );
default:
error("skelmatch type: %x",stype);
return(0);
}
}

View File

@@ -0,0 +1,110 @@
/*
Copyright 1982
Alcyon Corporation
8716 Production Ave.
San Diego, Ca. 92121
*/
#include "cgen.h"
#include "cskel.h"
/* sucomp - Sethy-Ullman expression complexity measure computation*/
/* This is a heuristic computation of the Sethy-Ullman numbers*/
/* for expressions. This gives an approximation of the complexity*/
/* of the expression. The code generation scheme works best if*/
/* the most complex expressions are done first.*/
sucomp(tp,nregs,flag) /* returns - none*/
struct tnode *tp; /* pointer to tree*/
int nregs; /* number of registers left*/
int flag; /* 1=>set values in tree, 0=>return*/
{
register int su, sur, op, i;
register struct tnode *ltp, *rtp;
nregs = dreg(nregs);
if( binop(op=tp->t_op) ) {
ltp = tp->t_left;
rtp = tp->t_right;
}
else if( unaryop(op) )
ltp = tp->t_left;
switch( op ) {
case CLONG:
if( tp->t_lvalue >= 0x8000L || tp->t_lvalue <= 0xffff8000L ) {
su = SU_ADDR;
break;
}
i = tp->t_lvalue;
case CINT:
if( op == CINT )
i = tp->t_value;
if( i == 0 )
su = SU_ZERO;
else if( i == 1 )
su = SU_ONE;
else if( i >= 1 && i <= QUICKVAL )
su = SU_SMALL;
else if( i >= -128 && i <= 127 )
su = SU_QUICK;
else
su = SU_CONST;
break;
case COMMA:
su = max(sucomp(rtp,nregs,flag),sucomp(ltp,nregs,flag));
su = max(su,SU_EASY);
break;
case ADDR:
su = sucomp(ltp,nregs,flag);
break;
case CFLOAT:
case DCLONG:
case AUTOINC:
case AUTODEC:
su = SU_ADDR;
break;
case SYMBOL:
if( tp->t_sc != REGISTER )
su = SU_ADDR;
else if( isdreg(tp->t_reg) )
su = SU_REG;
else
su = SU_AREG;
break;
case LDIV:
case LMOD:
case LMULT:
case CALL:
sucomp(rtp,nregs,flag);
case NACALL:
sucomp(ltp,nregs,flag);
su = SU_VHARD; /*very hard*/
break;
default:
su = sucomp(ltp,nregs,flag);
if( binop(op) ) {
if( su <= SU_ADDR )
su = max(su,sucomp(rtp,nregs,flag));
else {
sur = sucomp(rtp,nregs+1,flag);
if( sur > SU_ADDR && nregs > HICREG )
su = max(su,SU_HARD);
}
su = max(SU_EASY,su);
}
else if( su <= SU_XREG )
su = max(SU_EASY,su);
if( isfloat(tp->t_type) )
su = SU_VHARD;
break;
}
if( flag )
tp->t_su = su;
return(su);
}

View File

@@ -0,0 +1,118 @@
/*
Copyright 1982
Alcyon Corporation
8716 Production Ave.
San Diego, Ca. 92121
*/
#include "cgen.h"
#define ASGOP OPRAS|OPASSIGN|OPLVAL|OPBIN
/*info on operators:*/
/*000077-- OPPRI - priority*/
/*000100-- OPBIN - binary operator*/
/*000200-- OPLVAL - left operand must be lvalue*/
/*000400-- OPREL - relational operator*/
/*001000-- OPASSIGN - assignment operator*/
/*002000-- OPLWORD - int required on left*/
/*004000-- OPRWORD - int required on right*/
/*010000-- OPCOM commutative*/
/*020000-- OPRAS - right associative*/
/*040000-- OPTERM - termination node*/
/*100000 - OPCONVS - conversion operator*/
int opinfo[] {
TRMPRI, /*EOF*/
ADDPRI|OPCOM|OPBIN, /*ADD - expr + expr*/
ADDPRI|OPBIN, /*SUB - expr - expr*/
MULPRI|OPCOM|OPBIN, /*MULT - expr * expr*/
MULPRI|OPBIN, /*DIV - expr / expr*/
MULPRI|OPBIN, /*MOD - expr % expr*/
SHFPRI|OPLWORD|OPRWORD|OPBIN, /*RSH - expr >> expr*/
SHFPRI|OPLWORD|OPRWORD|OPBIN, /*LSH - expr << expr*/
ANDPRI|OPCOM|OPLWORD|OPRWORD|OPBIN, /*AND - expr & expr*/
ORPRI|OPCOM|OPLWORD|OPRWORD|OPBIN, /*OR - expr | expr*/
ORPRI|OPCOM|OPLWORD|OPRWORD|OPBIN, /*XOR - expr ^ expr*/
UNOPRI|OPRAS|OPLWORD, /*NOT - ! expr*/
UNOPRI|OPRAS, /*UMINUS - - expr*/
UNOPRI|OPRAS|OPLWORD, /*COMPL - ~ expr*/
UNOPRI|OPRAS|OPLVAL|OPBIN, /*PREDEC - --lvalue*/
UNOPRI|OPRAS|OPLVAL|OPBIN, /*PREINC - ++lvalue*/
UNOPRI|OPRAS|OPLVAL|OPBIN, /*POSTDEC - lvalue--*/
UNOPRI|OPRAS|OPLVAL|OPBIN, /*POSTINC - lvalue++*/
ASGPRI|ASGOP, /*ASSIGN - lvalue = expr*/
ASGPRI|ASGOP, /*EQADD - lvalue += expr*/
ASGPRI|ASGOP, /*EQSUB - lvalue -= expr*/
ASGPRI|ASGOP, /*EQMULT - lvalue *= expr*/
ASGPRI|ASGOP, /*EQDIV - lvalue /= expr*/
ASGPRI|ASGOP, /*EQMOD - lvalue %= expr*/
ASGPRI|ASGOP|OPLWORD|OPRWORD, /*EQRSH - lvalue >>= expr*/
ASGPRI|ASGOP|OPLWORD|OPRWORD, /*EQLSH - lvalue <<= expr*/
ASGPRI|ASGOP|OPLWORD|OPRWORD, /*EQAND - lvalue &= expr*/
ASGPRI|ASGOP|OPLWORD|OPRWORD, /*EQOR - lvalue |= expr*/
ASGPRI|ASGOP|OPLWORD|OPRWORD, /*EQXOR - lvalue ^= expr*/
TRMPRI, /*FJSR - generate function jsr*/
EQLPRI|OPREL|OPBIN, /*EQUALS - expr == expr*/
EQLPRI|OPREL|OPBIN, /*NEQUALS - expr != expr*/
RELPRI|OPREL|OPBIN, /*GREAT - expr > expr*/
RELPRI|OPREL|OPBIN, /*GREATEQ - expr >= expr*/
RELPRI|OPREL|OPBIN, /*LESS - expr < expr*/
RELPRI|OPREL|OPBIN, /*LESSEQ - expr <= expr*/
TRMPRI|OPCONVS, /*INT2L*/
TRMPRI|OPCONVS, /*LONG2I*/
TRMPRI|OPBIN, /*BTST*/
TRMPRI, /*LOAD*/
TRMPRI|OPBIN, /*LMULT*/
TRMPRI|OPBIN, /*LDIV*/
TRMPRI|OPBIN, /*LMOD*/
TRMPRI|OPBIN, /*LEQMULT*/
TRMPRI|OPBIN, /*LEQDIV*/
TRMPRI|OPBIN, /*LEQMOD*/
TRMPRI|ASGOP, /*EQADDR*/
TRMPRI, /*EQNOT*/
TRMPRI, /*EQNEG*/
TRMPRI|OPBIN, /*DOCAST*/
ASGPRI|ASGOP, /*STASSIGN [vlh]*/
TRMPRI|OPCONVS, /*LONG2F [vlh] 3.4*/
TRMPRI|OPCONVS, /*FLOAT2L [vlh] 3.4*/
TRMPRI|OPCONVS, /*INT2F [vlh] 3.4*/
TRMPRI|OPCONVS, /*FLOAT2I [vlh] 3.4*/
UNOPRI|OPRAS, /*TOCHAR [vlh] 4.0*/
TRMPRI, /*unused - 56*/
TRMPRI, /*unused - 57*/
TRMPRI, /*unused - 58*/
TRMPRI, /*unused - 59*/
UNOPRI|OPRAS|OPLVAL, /*ADDR - & expr*/
UNOPRI|OPRAS|OPLWORD, /*INDR - * expr*/
LNDPRI|OPBIN, /*LAND - expr && expr*/
LORPRI|OPBIN, /*LOR - expr || expr*/
QMKPRI|OPRAS|OPBIN, /*QMARK - expr ? expr : expr*/
QMKPRI|OPRAS|OPBIN, /*COLON*/
COMPRI|OPBIN, /*COMMA*/
TRMPRI|OPTERM, /*CINT*/
TRMPRI|OPTERM, /*CLONG*/
TRMPRI|OPTERM, /*SYMBOL*/
TRMPRI|OPTERM, /*AUTOINC*/
TRMPRI|OPTERM, /*AUTODEC*/
LPNPRI|OPBIN, /*CALL - call with arguments*/
LPNPRI, /*NACALL - no argument call*/
TRMPRI, /*BFIELD - field selection*/
TRMPRI, /*CONDBR*/
TRMPRI, /*INIT*/
TRMPRI, /*LOADREG*/
TRMPRI|OPTERM, /*DCLONG - divide const long*/
TRMPRI|OPTERM, /*CFLOAT [vlh] 3.4*/
UNOPRI|OPRAS|OPASSIGN|OPBIN, /*CAST*/
TRMPRI, /*SEMI*/
TRMPRI, /*LCURBR - {*/
TRMPRI, /*RCURBR - }*/
LPNPRI, /*LBRACK - [*/
RPNPRI, /*RBRACK - ]*/
LPNPRI, /*LPAREN - )*/
RPNPRI, /*RPAREN - )*/
TRMPRI|OPTERM, /*STRING*/
TRMPRI, /*RESWORD*/
LPNPRI|OPBIN, /*APTR - expr -> symbol*/
LPNPRI|OPBIN, /*PERIOD - expr . symbol*/
UNOPRI|OPRAS, /*SIZEOF - sizeof expr*/
LPNPRI|OPBIN, /*MPARENS - matching parens ()*/
};

View File

@@ -0,0 +1,21 @@
e:vax CANON.C s
e:vax CODEGEN.C s
e:vax CSKELS.C s
e:vax INTERF.C s
e:vax MAIN.C s
e:vax OPTAB.C s
e:vax PUTEXPR.C s
e:vax SMATCH.C s
e:vax SUCOMP.C s
e:vax TABL.C s
e:vax UTIL.C s
e:vax VERSION.C s
e:vax CGEN.H s
e:vax CSKEL.H s
e:vax ICODE.H s
e:vax MACHINE.68K s
e:vax LINK.SUB s
e:vax MAKE.SUB s
e:vax MACHINE.H s
e:vax SEND13.SUB s
e:vax up13.sub s

View File

@@ -0,0 +1,357 @@
/*
Copyright 1982
Alcyon Corporation
8716 Production Ave.
San Diego, Ca. 92121
*/
#include "cgen.h"
#include "cskel.h"
/* xnalloc - allocate address-indexed node*/
char *xnalloc(type,ar,off,xr,xt) /* returns ptr to node alloced*/
int type; /* data type*/
int ar; /* address register*/
int off; /* 8-bit offset*/
int xr; /* index register*/
int xt; /* index register type*/
{
register struct indexnode *xp;
xp = talloc(sizeof(*xp));
xp->t_op = SYMBOL;
xp->t_type = type;
xp->t_sc = INDEXED;
xp->t_reg = ar;
xp->t_su = SU_ADDR;
xp->t_offset = off;
xp->t_xreg = xr;
xp->t_xtype = xt;
return(xp);
}
/* tcopy - expression tree copy*/
char *tcopy(tp) /* returns ptr to copied tree*/
struct tnode *tp;
{
register char *p;
switch( tp->t_op ) {
case SYMBOL:
if( tp->t_sc == EXTERNAL || tp->t_sc == EXTOFF )
p = cenalloc(tp->t_type,tp->t_sc,tp->t_symbol);
else {
p = snalloc(tp->t_type,tp->t_sc,tp->t_offset,0,0);
p->t_label = tp->t_label;
}
p->t_offset = tp->t_offset;
p->t_reg = tp->t_reg;
return(p);
case CINT:
return(cnalloc(tp->t_type,tp->t_value));
case CLONG:
return(lcnalloc(tp->t_type,tp->t_lvalue));
case CFLOAT: /*[vlh] 3.4 */
return(fpcnalloc(tp->t_type,tp->t_lvalue));
case DCLONG:
p = lcnalloc(tp->t_type,tp->t_lvalue);
p->t_op = DCLONG;
return(p);
default:
if( binop(tp->t_op) )
return(tnalloc(tp->t_op,tp->t_type,0,0,tcopy(tp->t_left),
tcopy(tp->t_right)));
if( unaryop(tp->t_op) )
return(tnalloc(tp->t_op,tp->t_type,0,0,tcopy(tp->t_left),
null));
error("tcopy op=%d",tp->t_op);
return(tp);
}
}
/* outaexpr - output address expression*/
outaexpr(tp,flags) /* returns - none*/
struct tnode *tp; /* pointer to tree*/
int flags; /* flags (IMMED,LOFFSET,...)*/
{
register int off, reg, lab;
long l;
if( tp->t_op == ADDR ) {
tp = tp->t_left;
putchar('#');
}
off = tp->t_offset;
reg = tp->t_reg;
lab = tp->t_label;
switch( tp->t_op ) {
case AUTOINC:
printf("(R%d)+",reg);
break;
case AUTODEC:
printf("-(R%d)",reg);
break;
case CINT:
if( flags & IMMED )
putchar('#');
printf("%d",tp->t_value);
break;
case DCLONG:
case CLONG:
case CFLOAT: /*[vlh] 3.4 */
if( flags & IMMED )
putchar('#');
outlval(tp->t_lvalue);
break;
case SYMBOL:
if( off ) {
switch( tp->t_sc ) {
default:
printf("%d+",off);
break;
case REGOFF:
printf("%d",off);
case CINDR:
case CLINDR:
case CFINDR: /* [vlh] 3.4 */
case INDEXED:
break;
case REGISTER:
error("invalid register expression");
break;
}
}
switch( tp->t_sc ) {
case REGISTER:
printf("R%d",reg);
break;
case REGOFF:
printf("(R%d)",reg);
break;
case EXTERNAL:
printf("_%.8s",tp->t_symbol);
break;
case EXTOFF:
printf("_%.8s(R%d)",tp->t_symbol,reg);
break;
case STATIC:
printf("L%d",lab);
break;
case STATOFF:
printf("L%d(R%d)",lab,reg);
break;
case INDEXED:
printf("%d(R%d,R%d",off,reg,tp->t_xreg);
outatype(tp->t_xtype);
putchar(')');
break;
case CINDR:
printf("%d",off);
break;
/*
* the following will work on: PDP-11, 68000, IBM-360, VAX, etc.
* it will not work on word machines or on machines where either
* longs two ints or two shorts.
*/
case CLINDR:
case CFINDR: /* [vlh] 3.4 */
l.hiword = tp->t_offset;
l.loword = tp->t_ssp;
outlval(l);
break;
default:
error("invalid storage class %d\n",tp->t_sc);
break;
}
break;
default:
error("invalid operator %d\n",tp->t_op);
break;
}
}
/* outlval - output long value*/
/* This is a big pain because the PDP-11 doesn't do long divides*/
/* in hardware.*/
outlval(lval)
long lval;
{
char digs[8];
register int i, c;
i = 0;
do {
digs[i++] = lval & 0xf;
lval =>> 4;
lval =& 0xfffffff;
} while ( lval );
putchar('$');
while( --i >= 0 ) {
c = digs[i];
putchar(c>=10?c+('a'-10):c+'0');
}
}
/* outtype - output 68000 type (null, .b, .l) depending on data type*/
outtype(type)
int type;
{
if( isfloat(type) )
printf(".l");
else if( longorptr(type) )
printf(".l");
else if( type == CHAR )
printf(".b");
}
/* outatype - output address type (.l or null) depending on data type*/
outatype(type)
int type;
{
if( longorptr(type) || isfloat(type) )
printf(".l");
}
/* outextend - output register extension to long depending on type*/
outextend(tp,type,reg) /* returns - none*/
struct tnode *tp; /* tree to convert from*/
int type; /* type to convert to*/
int reg; /* register to convert*/
{
if( (isdreg(reg)) && !(longorptr(tp->t_type)) && (longorptr(type)) ) {
if( unsign(tp->t_type) )
outuext(reg);
else
outext(reg);
}
}
/* outrr - output register to register instruction*/
outrr(ins,r1,r2,tp)
char *ins;
int r1;
int r2;
struct tnode *tp;
{
printf("%s",ins);
if( isareg(r1) || isareg(r2) )
outatype(tp->t_type);
else
outtype(tp->t_type);
printf(" R%d,R%d\n",r1,r2);
}
/* outmovr - output "move[type] R1,R2" instruction*/
outmovr(r1,r2,tp)
int r1;
int r2;
struct tnode *tp;
{
if( r1 != r2 )
outrr("move",r1,r2,tp);
}
/* outcmpm - output "cmpm[type] (R1)+,(R2)+"*/
outcmpm(tp)
struct tnode *tp;
{
printf("cmpm");
outtype(tp->t_left->t_type);
printf(" (R%d)+,(R%d)+\n",tp->t_left->t_reg,tp->t_right->t_reg);
}
/* outcreg - output reference to compiler temp register*/
outcreg(reg)
int reg;
{
if( (dreg(reg)) > HICREG )
error("expression too complex");
printf("R%d",reg);
}
/* outcmp0 - output a compare with 0, special for address register*/
outcmp0(reg,tp)
int reg;
struct tnode *tp;
{
if( isareg(reg) ) {
printf("cmp");
outatype(tp->t_type);
printf(" #0,R%d\n",reg);
}
else {
printf("tst");
outtype(tp->t_type);
printf(" R%d\n",reg);
}
}
/* outrpush - output "move[type] R1,[-](sp)"*/
outrpush(reg,tp,pflag)
int reg;
struct tnode *tp;
int pflag;
{
printf("move");
outatype(tp->t_type);
printf(" R%d,%c(sp)\n",reg,pflag?'-':'\0');
}
outdbra(reg,lab)
int reg;
int lab;
{
printf("dbra R%d,L%d\n",reg,lab);
}
/* cenalloc - code generator external node allocation*/
/* This may be coalesced into enalloc in parser.*/
char *cenalloc(type,sc,sym) /* returns ptr to node alloced*/
int type; /* type of symbol*/
int sc; /* storage class*/
char *sym; /* symbol name*/
{
register struct extnode *ep;
ep = talloc(sizeof(*ep));
ep->t_op = SYMBOL;
ep->t_type = type;
ep->t_sc = sc;
ep->t_su = 0;
ep->t_offset = 0;
symcopy(sym,ep->t_symbol);
return(ep);
}
/*popstack - clear off the stack after a call if necessary */
popstack(nb)
{
if (nb > 0 && nb <= 8)
printf("addq.l #%d,sp\n",nb);
else if (nb > 0)
printf("adda.l #%d,sp\n",nb);
}

View File

@@ -0,0 +1 @@
char *compiled "@(#) code generator - Fri Mar 18 12:02 1983";

View File

@@ -0,0 +1,20 @@
$ cgen
$ set noon
$ !
$ ! C168 make file for VMS
$ !
$ copy machine.vax machine.h
$ pur machine.h
$ cx CANON
$ cx CODEGEN
$ cx CSKELS
$ cx INIT
$ cx INTERF
$ cx MAIN
$ cx OPTAB
$ cx PUTEXPR
$ cx SMATCH
$ cx SUCOMP
$ cx TABL
$ cx UTIL
$ clink canon,codegen,cskels,interf,main,optab,putexpr,smatch,sucomp,tabl,util,init,lib:klib/lib c168

View File

@@ -0,0 +1,340 @@
/*
Copyright 1982
Alcyon Corporation
8716 Production Ave.
San Diego, Ca. 92121
*/
#include "preproc.h"
#define OPPRI 077
#define OPBIN 0100
#define STKLEN 64
int oprstk[STKLEN]; /*operator stack*/
int opnstk[STKLEN]; /*operand stack*/
int pristk[STKLEN]; /*operator priority stack*/
int *oprptr; /*pointer to operator stack*/
int *opnptr; /*pointer to operand stack*/
int *priptr; /*pointer to priority stack*/
int cvalue;
int opinfo[] {
0, /*EOF=0*/
16|OPBIN, /*SUB=1*/
16|OPBIN, /*ADD=2*/
20, /*NOT=3*/
20, /*NEG=4*/
22, /*LPAREN=5*/
2, /*RPAREN=6*/
6|OPBIN, /*QMARK=7*/
6|OPBIN, /*COLON=8*/
8|OPBIN, /*OR=9*/
10|OPBIN, /*AND=10*/
8|OPBIN, /*XOR=11*/
12|OPBIN, /*EQUAL=12*/
12|OPBIN, /*NEQUAL=13*/
14|OPBIN, /*LESS=14*/
14|OPBIN, /*LSEQUAL=15*/
14|OPBIN, /*GREAT=16*/
14|OPBIN, /*GREQUAL=17*/
4|OPBIN, /*LSHIFT=18*/
4|OPBIN, /*RSHIFT=19*/
18|OPBIN, /*MULT=20*/
18|OPBIN, /*DIV=21*/
18|OPBIN, /*MOD=22*/
20, /*COMPL=23*/
};
/* cexpr - constant expression evaluation*/
/* Does priority-driven operator/operand stack evaluation of*/
/* constant expressions.*/
cexpr() /* returns constant evaluated*/
{
register int lop, type;
oprptr = &oprstk[0];
opnptr = &opnstk[0];
priptr = &pristk[0];
*priptr = 0;
lop = -1;
while(1) {
switch( type = getctok() ) {
case CONST:
if( !lop ) /*last was not operator*/
goto syntax;
if( opnptr >= &opnstk[STKLEN] ) {
error("expression stack overflow");
cexit();
}
lop = FALSE;
*++opnptr = cvalue;
continue;
case SUB:
if( lop )
type = NEG; /*unary minus*/
break;
case ADD:
if( lop )
continue; /*ignore unary +*/
break;
case COMPL:
case LPAREN:
case NOT:
if( !lop )
goto syntax;
break;
case RPAREN:
if( lop )
goto syntax;
lop = FALSE;
if( !stkop(type) )
goto syntax;
continue;
case NEWL:
case EOF:
if( lop || !stkop(EOF) || opnptr != &opnstk[1] )
goto syntax;
type = opnstk[1];
putback('\n');
return(type);
default:
if( lop || type > LASTOP )
goto syntax;
break;
}
lop = TRUE;
if( !stkop(type) )
goto syntax;
}
syntax:
error("expression syntax");
if( type == NEWL )
putback('\n');
return(0);
}
/* getctok - get a constant expression token*/
/* Handles conversion of quoted character strings and numbers.*/
getctok()
{
register int type, c, count;
register char *p;
char token[TOKSIZE];
while( 1 ) {
switch( type = getntok(token) ) {
case DIGIT:
cvalue = const(token);
return(CONST);
case SQUOTE:
for( cvalue = 0, p = &token[1], count = 2; --count >= 0; ) {
if( (c= *p++) == '\'' )
break;
if( c == '\\' ) {
if( *p >= '0' && *p <= '7' ) {
for( c = 0; *p >= '0' && *p <= '7'; )
c = (c<<3) + (*p++ - '0');
}
else switch( c = *p++ ) {
case 'n':
c = '\n';
break;
case 't':
c = '\t';
break;
case 'b':
c = '\b';
break;
case 'r':
c = '\r';
break;
case 'f':
c = '\f';
break;
}
}
cvalue = (cvalue<<8) | c;
}
return(CONST);
case ALPHA:
if( p = lookup(token) )
expand(p);
else
return(ALPHA);
break;
default:
return(type);
}
}
}
/* stkop - stack an operator on the operand stack*/
/* Unstack all operators of lower priority, evaluating them as*/
/* they are unstacked.*/
stkop(opr) /* returns 1 if ok, 0 otherwise*/
int opr; /* operator to stack*/
{
register int i, j, op1, op2, pri;
for( pri = opinfo[opr]&OPPRI; pri < *priptr; ) {
if( *oprptr == LPAREN ) {
if( opr == RPAREN ) {
oprptr--;
priptr--;
return(1);
}
break;
}
op1 = *opnptr;
if( (i=opinfo[*oprptr]) & OPBIN ) {
op2 = op1;
op1 = *--opnptr;
}
switch(*oprptr) { /*operator*/
case ADD:
op1 =+ op2;
break;
case SUB:
op1 =- op2;
break;
case COLON:
priptr--;
if( *--oprptr != QMARK )
return(0);
op1 = (*--opnptr ? op1 : op2);
break;
case QMARK:
return(0);
case XOR:
op1 =^ op2;
break;
case OR:
op1 =| op2;
break;
case AND:
op1 =& op2;
break;
case EQUAL:
op1 = (op1 == op2);
break;
case NEQUAL:
op1 = (op1 != op2);
break;
case LESS:
op1 = (op1 < op2);
break;
case LSEQUAL:
op1 = (op1 <= op2);
break;
case GREAT:
op1 = (op1 > op2);
break;
case GREQUAL:
op1 = (op1 >= op2);
break;
case LSHIFT:
op1 = (op1 << op2);
break;
case RSHIFT:
op1 = (op1 >> op2);
break;
case NEG:
op1 = -op1;
break;
case NOT:
op1 = !op1;
break;
case COMPL:
op1 = ~ op1;
break;
case MULT:
op1 =* op2;
break;
case DIV:
op1 =/ op2;
break;
case MOD:
op1 =% op2;
break;
}
*opnptr = op1;
priptr--;
oprptr--;
}
if( priptr >= &pristk[STKLEN-1] ) {
error("expression operator stack overflow");
cexit();
}
*++oprptr = opr; /*operator value*/
*++priptr = pri; /*operator priority*/
return(1);
}
#define toupper(c) ((c) & ~32)
/* const - alpha to int conversion, handles octal and hexidecimal*/
/* Uses Horner's method to evaluate number.*/
const(str) /* returns number evaluated*/
char *str; /* pointer to string to convert*/
{
register int c, ch, i, radix;
i = 0;
radix = 10;
if( *str == '0' ) {
radix = 8;
if( *++str == 'x' || *str == 'X' ) {
radix = 16;
str++;
}
}
while( c = *str++ ) {
if( (ch=toupper(c)) >= 'A' && ch <= 'F' )
c = ch - ('A'-10);
else if( c >= '0' && c <= '9' )
c =- '0';
else
break;
if( c >= radix )
break;
i = i*radix + c;
}
return(i);
}

View File

@@ -0,0 +1,251 @@
/*
Copyright 1982
Alcyon Corporation
8716 Production Ave.
San Diego, Ca. 92121
*/
#include "machine.h"
/*
* intermediate code operators
* 0=>EOF, special operator
*/
#define EOF 0
/*1-59=>operators that generate code (entries in code gen optab)*/
#define ADD 1
#define SUB 2
#define MULT 3
#define DIV 4
#define MOD 5
#define RSH 6
#define LSH 7
#define AND 8
#define OR 9
#define XOR 10
#define NOT 11
#define UMINUS 12
#define COMPL 13
#define PREDEC 14
#define PREINC 15
#define POSTDEC 16
#define POSTINC 17
#define ASSIGN 18
#define EQADD 19
#define EQSUB 20
#define EQMULT 21
#define EQDIV 22
#define EQMOD 23
#define EQRSH 24
#define EQLSH 25
#define EQAND 26
#define EQOR 27
#define EQXOR 28
#define FJSR 29
#define EQUALS 30
#define NEQUALS 31
#define GREAT 32
#define GREATEQ 33
#define LESS 34
#define LESSEQ 35
#define INT2L 36
#define LONG2I 37
/*machine dependent operators that generate code*/
#define BTST 38
#define LOAD 39
#define LMULT 40
#define LDIV 41
#define LMOD 42
#define LEQMULT 43
#define LEQDIV 44
#define LEQMOD 45
#define EQADDR 46
#define EQNOT 47
#define EQNEG 48
#define DOCAST 49
#define STASSIGN 50 /*[vlh]*/
#define LONG2F 51 /*[vlh] 3.4*/
#define FLOAT2L 52 /*[vlh] 3.4*/
#define INT2F 53 /*[vlh] 3.4*/
#define FLOAT2I 54 /*[vlh] 3.4*/
#define LCGENOP 55 /*change if adding more operators...*/
/*intermediate code operators that do not generate code*/
#define ADDR 60
#define INDR 61
#define LAND 62
#define LOR 63
#define QMARK 64
#define COLON 65
#define COMMA 66
#define CINT 67
#define CLONG 68
#define SYMBOL 69
#define AUTOINC 70
#define AUTODEC 71
#define CALL 72
#define NACALL 73
#define BFIELD 74
#define IFGOTO 75
#define INIT 76
#define CFORREG 77
#define DCLONG 78
#define CFLOAT 79 /*[vlh] 3.4*/
/*operators local to parser*/
#define CAST 80
#define SEMI 81
#define LCURBR 82
#define RCURBR 83
#define LBRACK 84
#define RBRACK 85
#define LPAREN 86
#define RPAREN 87
#define STRING 88
#define RESWORD 89
#define APTR 90
#define PERIOD 91
#define SIZEOF 92
#define MPARENS 93
#define FRETURN 94
#define STACKEND 100
/*data types*/
#define TYPELESS 0
#define CHAR 1
#define SHORT 2
#define INT 3
#define LONG 4
#define UCHAR 5
#define USHORT 6
#define UNSIGNED 7
#define ULONG 8
#define FLOAT 9
#define DOUBLE 10
/*data types local to parser*/
#define STRUCT 11
#define FRSTRUCT 12
#define LLABEL 13
/*type flags and definitions*/
#define TYPE 017
#define SUPTYP 060
#define ALLTYPE 077
#define POINTER 020
#define FUNCTION 040
#define ARRAY 060
#define SUTYPLEN 2
/*data registers*/
#define DREG0 0
#define DREG2 2
#define DREG3 3
#define DREG4 4
#define DREG5 5
#define DREG6 6
#define DREG7 7
#define AREG3 11
#define AREG4 12
#define AREG5 13
/*storage classes*/
#define AUTO 1
#define REGISTER 2
#define EXTERNAL 3
#define STATIC 4
#define REGOFF 5
#define EXTOFF 6
#define STATOFF 7
#define INDEXED 8
/*exclusively code generator storage classes*/
#define CINDR 9
#define CLINDR 10
#define CFINDR 11 /* [vlh] 3.4 */
/*exclusively parser storage classes*/
#define STRPROTO 9
#define PDECLIST 10
#define PARMLIST 11
#define BFIELDCL 12
#define UNELCL 13
#define STELCL 14
/*opinfo table bits*/
#define OPPRI 077
#define OPBIN 0100
#define OPLVAL 0200
#define OPREL 0400
#define OPASSIGN 01000
#define OPLWORD 02000
#define OPRWORD 04000
#define OPCOM 010000
#define OPRAS 020000
#define OPTERM 040000
#define OPCONVS 0100000
/*68000 definitions*/
#define PTRSIZE 4
#define INTSIZE 2
#define LONGSIZE 4
#define SSIZE 8 /* chars per symbol */
#define TRUE 1
#define FALSE 0
#define TABC '\t' /* tab character */
#define EOLC '\n' /* end of line character */
#define BITSPBYTE 8
/*operator class priorities*/
#define TRMPRI 0 /* terminal nodes */
#define RPNPRI 1 /* ) and ] */
#define CALPRI 2 /* in-stack call, ( or [ */
#define COLPRI 3 /* init or case priority for : or , */
#define STKPRI 4 /* priority of end of stack */
#define COMPRI 5 /* normal priority for , */
#define ASGPRI 6 /* =, +=, -=, *=, /=, %=, ... */
#define QMKPRI 7 /* ?: */
#define LORPRI 8 /* || */
#define LNDPRI 9 /* && */
#define ORPRI 10 /* |, ! */
#define ANDPRI 11 /* & */
#define EQLPRI 12 /* ==, != */
#define RELPRI 13 /* >, <, >=, <= */
#define SHFPRI 14 /* <<, >> */
#define ADDPRI 15 /* +, - */
#define MULPRI 16 /* *, /, % */
#define UNOPRI 17 /* ++, --, &, *, -, ~, sizeof */
#define LPNPRI 18 /* ., ->, [, (, function call */
#define PSTPRI 19 /* in-stack post--, post++ */
struct io_buf {
int io_fd;
int io_nc;
char *io_p;
char io_b[512];
};
#ifdef PDP11
struct { short hiword; short loword; };
#endif
#ifdef MC68000
struct { short hiword; short loword; };
#endif
#ifdef VAX
struct { short loword; short hiword; };
#endif
#define EXPSIZE 1024
int exprarea[EXPSIZE];
/* v6io buffer declaration */
#define BLEN 512
struct iobuf{
int fildes;
int nunused;
char *xfree;
char buff[BLEN];
};

View File

@@ -0,0 +1,163 @@
/*
Copyright 1982
Alcyon Corporation
8716 Production Ave.
San Diego, Ca. 92121
*/
#include "icode.h"
#include "machine.h"
/*cexpr operators*/
#define EOF 0
#define SUB 1
#define ADD 2
#define NOT 3
#define NEG 4
#define LPAREN 5
#define RPAREN 6
#define QMARK 7
#define COLON 8
#define OR 9
#define AND 10
#define XOR 11
#define EQUAL 12
#define NEQUAL 13
#define LESS 14
#define LSEQUAL 15
#define GREAT 16
#define GREQUAL 17
#define LSHIFT 18
#define RSHIFT 19
#define MULT 20
#define DIV 21
#define MOD 22
#define COMPL 23
#define CONST 24
#define LASTOP COMPL /*up to here used by cexpr*/
#define SQUOTE 25
#define DQUOTE 26
#define ANYC 27
#define BADC 28
#define COMMA 29
#define NEWL 30
#define POUND 31
#define ALPHA 32
#define DIGIT 33
#define BSLASH 34
#define WHITE 35
#define BUFSIZE 512
#define LINESIZE 512
#define ARG -1
#define NEWLABEL -2
#define LABEL -3
#define NOARGS -4
#define MAXARGS 60
#define ARGBSIZE 1000
#define TOKSIZE 300 /*BUG 4/20/82 was 128*/
#define DEFSIZE 1024
#define PBSIZE 1000
#define DEFINE 1
#define UNDEF 2
#define INCLUDE 3
#define IFDEF 4
#define IFNDEF 5
#define ELSE 6
#define ENDIF 7
#define IF 8
#define SKIP 0
#define NOSKIP 1
#define SOH '\01'
#define SSIZE 8
#define HSIZE 517 /* 3.4 made prime */
#define FSTACK 10
#define TRUE 1
#define FALSE 0
#define NDEFS 20
struct symbol {
char s_name[SSIZE];
char *s_def;
} symtab[HSIZE]=0;
/*buffered I/O structure*/
struct ibuf {
int fd;
int nc;
char *bp;
char buffer[BUFSIZE];
} outbuf=0;
/* command line define structure */
struct defstruc {
char *ptr;
char *value;
} defs[NDEFS]=0;
struct stackstruc { /* [vlh] */
int ifd;
char ifile[13];
int lineno;
struct ibuf inbuf;
} filestack[FSTACK]=0, *filep=0; /* stack of incl files, ptr to... */
#ifdef BULLSHIT /* Bullshit, bullshit, bullshit!!!*/
#ifdef VERSADOS
#define NONEST 1
#define NOFORKS 1
#endif
#ifdef VMS
#define NONEST 1
#endif
#ifdef NONEST
struct ibuf holdbuf=0; /* alternate buffer, hold main file info */
#endif
#endif
int mfail=0; /*macro error flag*/
int skip=0; /*skipping current line*/
char *defap=0; /*pointer to available define area*/
char *defp=0; /*pointer to next avail define byte*/
int defcount=0; /*bytes left in define area*/
int defused=0; /*number of bytes used in define area*/
int defmax=0; /*maximum define area used*/
int pflag=0;
int asflag=0;
/*line to output after macro substitution*/
char line[LINESIZE+2]=0; /*line buffer*/
char *linep=0; /*current line pointer*/
int loverflow=0; /*line overflow flag*/
int lineno=0;
/*push back buffer*/
char pbbuf[PBSIZE]=0; /*push back buffer*/
char *pbp=0; /*push back pointer*/
int pbflag=0; /*checks for recursive definition*/
char *lookup();
char *setend();
char *makecopy();
char *makecopy();
char *maketemp();
char *sbrk();
struct symbol *getsp();
#define STKLEN 64
int oprstk[STKLEN]=0;
int opnstk[STKLEN]=0;
int pristk[STKLEN]=0;
int *oprptr=0;
int *opnptr=0;
int *priptr=0;
int nincl=0;
char *incl[10]=0;
char tmp[6]=0;
#define CSTKSIZE 20
char cstack[CSTKSIZE]=0;
char *cstkptr=0;
char inclname[TOKSIZE]=0;
int cvalue=0;
#define EXPSIZE 1024
int exprarea[EXPSIZE]=0;

View File

@@ -0,0 +1,328 @@
/*
Copyright 1982
Alcyon Corporation
8716 Production Ave.
San Diego, Ca. 92121
*/
#include "preproc.h"
char null[] "";
char ctype[] {
EOF, ANYC, ANYC, ANYC, ANYC, ANYC, ANYC, ANYC, /*BUG 2*/
ANYC, WHITE, NEWL, ANYC, ANYC, ANYC, ANYC, ANYC, /*BUG 2*/
ANYC, ANYC, ANYC, ANYC, NEWL, ANYC, ANYC, ANYC, /*BUG 2*/
ANYC, ANYC, ANYC, ANYC, ANYC, ANYC, ANYC, ANYC, /*BUG 2*/
WHITE, NOT, DQUOTE, POUND, ANYC, MOD, AND, SQUOTE, /*BUG 2*/
LPAREN, RPAREN, MULT, ADD, COMMA, SUB, ANYC, DIV,
DIGIT, DIGIT, DIGIT, DIGIT, DIGIT, DIGIT, DIGIT, DIGIT,
DIGIT, DIGIT, COLON, ANYC, LESS, EQUAL, GREAT, QMARK,
ANYC, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, /*BUG 2*/
ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA,
ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA,
ALPHA, ALPHA, ALPHA, ANYC, BSLASH, ANYC, XOR, ALPHA,
ANYC, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, /*BUG 2*/
ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA,
ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA,
ALPHA, ALPHA, ALPHA, ANYC, OR, ANYC, COMPL, ANYC /*BUG 2*/
};
/* symhash - compute hash value for symbol*/
/* Sums the symbols characters and takes that modulus the hash table*/
/* size.*/
symhash(sym) /* returns hash value for symbol*/
char *sym; /* pointer to symbol*/
{
register char *p;
register int hashval, i;
for( p = sym, i = SSIZE, hashval = 0; *p != '\0' && i > 0; i-- )
hashval =+ *p++;
return( hashval % HSIZE );
}
/* symequal - check for symbol equality*/
/* Does comparison between two symbols.*/
symequal(sym1,sym2) /* returns 1 if equal, 0 otherwise*/
char *sym1; /* pointer to first symbol*/
char *sym2; /* pointer to second symbol*/
{
register char *p, *q;
register int i;
q = sym2;
i = SSIZE;
for( p = sym1; *p == *q++; )
if( *p++ == '\0' || --i == 0 )
return(1);
return(0);
}
/* symcopy - symbol copy*/
/* Copies one symbol to another.*/
symcopy(sym1,sym2) /* returns - none*/
char *sym1; /* pointer to symbol to copy*/
char *sym2; /* pointer to area to copy to*/
{
register char *p, *q;
register int i;
for( p = sym1, q = sym2, i = SSIZE; --i >= 0; )
if( *p )
*q++ = *p++;
else
*q++ = '\0';
}
/* error - output error message*/
/* Outputs line number and error message and keeps track of errors.*/
error(s,x1,x2,x3,x4,x5,x6) /* returns - none*/
char *s; /* printf string*/
int x1, x2, x3, x4, x5, x6; /* printf args*/
{
if (filep == &filestack[0]) /* [vlh] 3.4 not in include */
printf("# %d: ",lineno);
else
printf("%s : # %d: ",(filep)->ifile,(filep)->lineno);
printf(s,x1,x2,x3,x4,x5,x6);
putchar('\n');
mfail++;
}
/* putback - puts back a single character*/
/* Checks for push back buffer overflow.*/
putback(c)
int c;
{
if( pbp >= &pbbuf[PBSIZE] ) {
error("too many characters pushed back");
cexit();
}
*pbp++ = c;
}
/* pbtok - push back a token*/
/* Reverses token as its pushing it back.*/
pbtok(s)
char *s;
{
register char *p;
for( p = s + strlen(s); p > s ; )
putback(*--p);
}
/* ngetch - get a (possibly) pushed back character*/
/* This handles the include file stack and incrementing the line*/
/* number for the lowest level file.*/
ngetch() /* returns character or EOF*/
{
register int c, i;
register char *p, *q;
if( pbp > &pbbuf[0] )
return(*--pbp);
pbflag = 0;
while( (c=getc(&(filep->inbuf))) < 0 ) {
if( filep == &filestack[0] )
return(EOF);
close(filep->inbuf.fd);
filep--;
if( filep == &filestack[0] ) { /*need line for #include...*/
putc('\n',&outbuf);
lineno++;
}
}
return( c );
}
/* getsp - get symbol pointer*/
/* Calculates the symbol table pointer for a given symbol, if symbol*/
/* is not defined, will point to appropriate place to insert symbol.*/
struct symbol *getsp(name)
char *name;
{
register int wrap;
register struct symbol *sp, *asp;
wrap = 0;
asp = 0;
for( sp = &symtab[symhash(name)]; sp->s_def != null; ) {
if( symequal(sp->s_name,name) )
return(sp);
if( !asp && sp->s_def == null )
asp = sp;
if( ++sp >= &symtab[HSIZE] ) {
if( wrap++ ) {
error("symbol table overflow");
cexit();
}
sp = &symtab[0];
}
}
return( asp ? asp : sp );
}
/* lookup - looks up a symbol to see if it is defined*/
/* Returns pointer to definition if found.*/
char *lookup(name) /* returns 0 or ptr to symbol*/
char *name; /* symbol name*/
{
register struct symbol *sp;
sp = getsp(name);
if( sp->s_def == 0 || sp->s_def == null )
return(0);
return(sp);
}
/* gettok - gets next token from input*/
/* Collects character string in token and handles special tokens for*/
/* the expression evaluator.*/
gettok(token) /* returns token type*/
char *token;
{
register char *p, c;
register int type, count, t, l;
p = token;
c = ngetch();
*p++ = c;
switch( type = ctype[c] ) {
case SQUOTE:
case DQUOTE:
getstr(token,TOKSIZE,c);
return(type);
case DIGIT:
case ALPHA:
for( ; p < &token[TOKSIZE]; p++ ) {
*p = ngetch();
if( (t=ctype[*p]) != ALPHA && t != DIGIT )
break;
}
putback(*p);
break;
case NOT:
if( peekis('=') ) {
type = NEQUAL;
*p++ = '=';
}
break;
case GREAT:
if( peekis('>') ) {
type = RSHIFT;
*p++ = '>';
}
else if( peekis('=') ) {
type = GREQUAL;
*p++ = '=';
}
break;
case LESS:
if( peekis('<') ) {
type = LSHIFT;
*p++ = '<';
}
else if( peekis('=') ) {
type = LSEQUAL;
*p++ = '=';
}
break;
case EQUAL:
if( peekis('=') )
*p++ = '=';
else
type = ANYC;
break;
case DIV:
if( peekis('*') ) {
l = lineno;
while( (c=ngetch()) != EOF )
if( c == '\n' ) {
if( filep == &filestack[0] && pbp == &pbbuf[0] ) {
lineno++;
putc('\n',&outbuf);
}
}
else if( c == '*' && peekis('/') )
break;
if( c == EOF ) {
lineno = l;
error("no */ before EOF");
}
type = WHITE;
token[0] = ' ';
}
else if( peekis('/') ) {
while( (c=ngetch()) != EOF && c != '\n' )
;
type = NEWL;
token[0] = '\n';
}
break;
case BADC:
error("bad character 0%o",c);
break;
}
*p = '\0';
return(type);
}
/* getstr - get a quoted (single or double) character string*/
/* Gets specified number of characters, handling escapes.*/
getstr(str,nchars,endc) /* returns - none*/
char *str; /* pointer to string buffer*/
int nchars; /* max number of characters*/
char endc; /* ending string character*/
{
register char *p;
register int i;
register int c;
register int j;
p = str;
*p++ = endc;
for( i = nchars-2; (c=ngetch()) != endc; ) {
if( c == EOF || c == '\n' ) {
error("string cannot cross line");
break;
}
if( --i > 0 ) /*BUG 1*/
*p++ = c;
else if( !i )
error("string too long");
if( c == '\\' ) {
c = ngetch();
if( --i > 0 ) /*BUG 1*/
*p++ = c;
else if( !i )
error("string too long");
}
}
*p++ = endc;
*p = '\0';
}
/* peekis - peeks at next character for specific character*/
/* Gets next (possibly pushed back) character, if it matches*/
/* the given character 1 is returned, otherwise the character*/
/* is put back.*/
peekis(tc) /* returns 1 if match, 0 otherwise*/
int tc; /* test character*/
{
register int c;
if( (c=ngetch()) == tc )
return(1);
putback(c);
return(0);
}

View File

@@ -0,0 +1,4 @@
$1lo68 -f $1 -r -o cp68.rel -unofloat 0$1s.o cexpr.o lex.o macro.o main.o util.o 0$1lib6.a 0$1clib
era *.o
user 12!make $1

View File

@@ -0,0 +1,27 @@
$ num
CEXPR.C
CEXPR.lis
$ num
INIT.C
INIT.lis
$ num
LEX.C
LEX.lis
$ num
MACRO.C
MACRO.lis
$ num
MAIN.C
MAIN.lis
$ num
UTIL.C
UTIL.lis
$ num
ICODE.H
ICODE.lst
$ num
MACHINE.H
MACHINE.lst
$ num
PREPROC.H
PREPROC.lst

View File

@@ -0,0 +1,10 @@
/*
* Use this file to determine what kind of machine you want the
* Alcyon stuff to run on ....
*/
/*#define MC68000 1*/ /* 68000 version */
/*#define VAX 1*/ /* VAX Version */
#define PDP11 1 /* PDP-11 Version*/
/*#define CPM 1*/ /* CP/M Operating System*/
#define UNIX 1 /* UNIX Operating System*/
/*#define VMS 1*/ /* VMS Operating System*/

View File

@@ -0,0 +1,10 @@
/*
* Use this file to determine what kind of machine you want the
* Alcyon stuff to run on ....
*/
#define MC68000 1 /* 68000 version */
/*#define VAX 1*/ /* VAX Version */
/*#define PDP11 1*/ /* PDP-11 Version*/
#define CPM 1 /* CP/M Operating System*/
/*#define UNIX 1*/ /* UNIX Operating System*/
/*#define VMS 1*/ /* VMS Operating System*/

View File

@@ -0,0 +1,10 @@
/*
* Use this file to determine what kind of machine you want the
* Alcyon stuff to run on ....
*/
/*#define MC68000 1*/ /* 68000 version */
#define VAX 1 /* VAX Version */
/*#define PDP11 1*/ /* PDP-11 Version*/
/*#define CPM 1*/ /* CP/M Operating System*/
/*#define UNIX 1*/ /* UNIX Operating System*/
#define VMS 1 /* VMS Operating System*/

View File

@@ -0,0 +1,10 @@
/*
* Use this file to determine what kind of machine you want the
* Alcyon stuff to run on ....
*/
/*#define MC68000 1*/ /* 68000 version */
#define VAX 1 /* VAX Version */
/*#define PDP11 1*/ /* PDP-11 Version*/
/*#define CPM 1*/ /* CP/M Operating System*/
/*#define UNIX 1*/ /* UNIX Operating System*/
#define VMS 1 /* VMS Operating System*/

View File

@@ -0,0 +1,673 @@
/*
Copyright 1982
Alcyon Corporation
8716 Production Ave.
San Diego, Ca. 92121
*/
#include "preproc.h"
#define CSTKSIZE 20
#define FILESEP '/'
#define NINCL 10
#ifdef UNIX
char *stdincl "/usr/include/"; /*standard include directory*/
#endif
#ifdef VMS
char *stdincl "lib:";
#endif
#ifdef CPM
char *stdincl "";
#endif
int clabel 1000;
int nlabel 1001;
int nincl;
char *incl[10];
char tmp[6];
struct builtin {
char *b_name;
int b_type;
} btab[] {
"define", DEFINE,
"include", INCLUDE,
"undef", UNDEF,
"ifdef", IFDEF,
"ifndef", IFNDEF,
"else", ELSE,
"endif", ENDIF,
"if", IF,
0,
};
char *getinclude();
char cstack[CSTKSIZE];
char *cstkptr, inclname[TOKSIZE];
/* domacro - do macro processing*/
/* Does the macro pre-processing on the input file and leaves the*/
/* result on the output file.*/
domacro(infile,outfile,nd) /* returns 1 if ok, 0 otherwise*/
char *infile; /* input file name*/
char *outfile; /* output file name*/
int nd; /* number of defines*/
{
register struct builtin *bp;
register char *l;
register struct symbol *sp;
register int x, nonewline; /* handle empty new lines with SOH */
register char *p;
filep = &filestack[0];
if( fopen(infile,&(filep->inbuf),0) < 0 ) { /* 3rd arg for versados */
error("can't open source file %s\n",infile);
return(0);
}
if( fcreat(outfile,&outbuf,0) < 0 ) { /* 3rd arg for versados */
error("can't creat %s\n",outfile);
return(0);
}
for (sp= &symtab[0]; sp<= &symtab[HSIZE-1]; sp++) /*3.4*/
sp->s_def = null; /* clear out symbol table */
if( !defap ) {
defp = defap = sbrk(1024);
defmax = defcount = 1024;
}
else { /* multiple files, define area already exists */
defcount = defmax;
for (x = defmax, defp = defap; x>0; x--)
*defp++ = 0;
defp = defap;
}
lineno = 1;
nonewline = defused = mfail = 0;
pbp = &pbbuf[0];
cstkptr = &cstack[0];
install("Newlabel",NEWLABEL);
install("Label",LABEL);
while( --nd >= 0 )
dinstall(defs[nd].ptr,defs[nd].value);
while( getline(infile) ) {
l = line;
if( filep == &filestack[0] && pbp == &pbbuf[0] )
lineno++;
else if ( !pflag && !asflag ) { /*[vlh] add fname & line#*/
if (*l) {
putc(SOH,&outbuf);
for (p = (filep)->ifile; *p; p++)
putc(*p,&outbuf);
putc(SOH,&outbuf);
itoa((filep)->lineno,tmp,5);
for (p = tmp; *p==' '; ) p++;
for ( ; *p; p++)
putc(*p,&outbuf);
putc(' ',&outbuf);
if (!(*l)) putc(' ',&outbuf);
}
else nonewline++;
(filep)->lineno++;
}
while( *l )
putc(*l++,&outbuf);
if (!nonewline) putc('\n',&outbuf);
else nonewline = 0;
}
if( cstkptr != &cstack[0] )
error("unmatched conditional");
if( defused > defmax )
defmax = defused;
v6flush(&outbuf);
close(outbuf.fd);
close(filep->inbuf.fd);
return(mfail==0);
}
install(name,def)
char *name;
int def;
{
register struct symbol *sp;
sp = getsp(name);
symcopy(name,sp->s_name);
sp->s_def = defp;
putd(def);
putd('\0');
}
dinstall(name,def) /* returns - none*/
char *name; /* macro name*/
char *def; /* pointer to definition*/
{
register struct symbol *sp;
sp = getsp(name);
symcopy(name,sp->s_name);
sp->s_def = defp;
putd(NOARGS);
if (def) /* [vlh] character strings... */
while(*def) putd(*def++);
else putd('1'); /* [vlh] default define value */
putd('\0');
}
/* kwlook - look up the macro built-in names*/
/* Searches thru the built-in table for the name.*/
kwlook(name) /* returns keyword index or 0*/
char *name; /* keyword name to lookup*/
{
register struct builtin *bp;
for( bp = &btab[0]; bp->b_name; bp++ )
if( strcmp(bp->b_name,name) == 0 )
return(bp->b_type);
return(0);
}
/*
* getline - get input line handling macro statements
* Checks for a preprocessor statement on the line and if there
* is one there, it processes it. Note that most of the work is
* in determining whether we need to skip the current line or not.
* This is all handled with the condition stack and the skip variable.
* The skip variable is non-zero if any condition on the condition
* stack is SKIP.
*/
getline(infile) /* returns 0 for EOF, 1 otherwise*/
char *infile; /* [vlh] for quoted include files */
{
char token[TOKSIZE];
register int type, i;
register char *p;
initl();
if( (type=gettok(token)) == EOF )
return(0);
if( type == POUND ) {
if( (type=getntok(token)) == NEWL )
return(1);
switch( kwlook(token) ) {
case IFDEF:
if( getntok(token) == ALPHA && lookup(token) )
push(NOSKIP);
else {
push(SKIP);
skip++;
}
break;
case IFNDEF:
if( getntok(token) == ALPHA && lookup(token) ) {
push(SKIP);
skip++;
}
else
push(NOSKIP);
break;
case ENDIF:
if( (i=pop()) == SKIP )
skip--;
else if( i != NOSKIP )
error("invalid #endif");
break;
case ELSE:
if( (i=pop()) == SKIP ) {
skip--;
push(NOSKIP);
}
else if( i == NOSKIP ) {
skip++;
push(SKIP);
}
else
error("invalid #else");
break;
case DEFINE:
if( !skip ) /*if in skip, don't do define*/
dodefine();
break;
case UNDEF:
if( !skip ) { /*if in skip, don't undef*/
if( (type=getntok(token)) == ALPHA )
undefine(token);
}
break;
case INCLUDE:
if( !skip ) /*if in skip, don't do include*/
doinclude(infile);
break;
case IF:
if( cexpr() ) /*evaluate constant expression*/
push(NOSKIP); /*non-zero, so don't skip*/
else {
push(SKIP);
skip++;
}
break;
default:
error("invalid preprocessor command");
break;
}
eatup();
}
else if( type == NEWL )
;
else if( skip )
eatup();
else {
for( ; type != NEWL && type != EOF ; type = gettok(token) ) {
if( type == ALPHA && (p=lookup(token)) )
expand(p);
else {
for( p = token; *p ; )
putl(*p++);
}
}
}
putl('\0');
return(1);
}
/* eatup - eat up the rest of the input line until a newline or EOF*/
/* Does gettok calls.*/
eatup() /* returns - none*/
{
register int type;
char etoken[TOKSIZE];
while( (type=gettok(etoken)) != NEWL && type != EOF )
;
}
/* putl - put a character to the current output line*/
/* Checks for line overflow.*/
putl(c) /* returns - none*/
int c; /* character to put on line*/
{
if( linep < &line[LINESIZE] )
*linep++ = c;
else if ( !loverflow ) {
loverflow++;
error("line overflow");
}
}
/* initl - initialize current line*/
/* Sets the line pointer and the line overflow flag.*/
initl() /* returns - none*/
{
*(linep= &line[0]) = '\0';
loverflow = 0;
}
/* putd - put a character to the define buffer*/
/* Does dynamic allocation for define buffer*/
putd(c) /* returns - none*/
int c; /* character to put in buffer*/
{
if( !defcount ) {
if( sbrk(DEFSIZE) == -1 ) {
error("define table overflow");
cexit();
}
defcount = DEFSIZE;
}
defused++;
defcount--;
*defp++ = c;
}
/* undefine - does undef command*/
/* Sets the symbols definition to the null pointer*/
undefine(name) /* returns - none*/
char *name; /* pointer to name to undef*/
{
register struct symbol *sp;
sp = getsp(name);
if( sp->s_def )
sp->s_def = null;
}
/* dodefine - do #define processing*/
/* Checks the define name, collects formal arguements and saves*/
/* macro definition, substituting for formal arguments as it goes.*/
dodefine() /* returns - none*/
{
char token[TOKSIZE], *args[MAXARGS], argbuf[ARGBSIZE];
register char *abp, *p;
register int type, nargs, i;
register struct symbol *sp;
if( (type=getntok(token)) != ALPHA ) {
error("bad define name: %s",token);
return;
}
sp = getsp(token);
symcopy(token,sp->s_name);
sp->s_def = defp;
nargs = 0;
abp = argbuf;
if( (type=gettok(token)) == LPAREN ) {
for( ; (type=getfarg(token)) != RPAREN; nargs++ ) {
if( nargs >= MAXARGS ) {
error("too many arguments");
break;
}
args[nargs] = abp;
for( p = token; *abp++ = *p++; ) {
if( abp >= &argbuf[ARGBSIZE] ) {
error("argument buffer overflow");
break;
}
}
}
putd(nargs);
}
else {
pbtok(token);
putd(NOARGS);
}
type = getntok(token); /*get next non-white token*/
for( ; type != NEWL && type != EOF; type = gettok(token) ) {
if( type == ALPHA ) {
for( i = 0; i < nargs; i++ ) {
if( strcmp(args[i],token) == 0 )
break;
}
if( i < nargs ) { /*sub ARG marker for formal arg*/
putd(i+1);
putd(ARG);
continue;
}
}
else if( type == BSLASH ) {
if( (i=ngetch()) == '\n' ) { /*multi-line macro?*/
if( filep == &filestack[0] && pbp == &pbbuf[0] ) {
lineno++;
putc('\n',&outbuf);
}
}
putd(i);
continue;
}
for( p = token; *p ; )
putd(*p++);
}
pbtok(token);
putd('\0');
}
/* expand - expands the macro definition*/
/* Checks for define recursion and #define x x problems, collects*/
/* the actual arguments using getaarg, and then expands the macro*/
/* by pushing it onto the push back buffer, substituting arguments*/
/* as it goes.*/
expand(sp) /* returns - none*/
struct symbol *sp; /* pointer to macro to expand*/
{
char argbuf[ARGBSIZE], *args[MAXARGS], token[TOKSIZE];
register char *p, *abp, *mdef;
register int i, j, nargs, type;
if( pbflag++ > 100 ) {
error("define recursion");
return;
}
if( strcmp(sp->s_name,mdef=sp->s_def) == 0 ) { /*handle #define x x*/
while( *mdef )
putl(*mdef++);
return;
}
nargs = 0;
if( *mdef == NOARGS ) /*suppress grabbing of args*/
;
else if( gettok(token) != LPAREN )
pbtok(token);
else {
abp = &argbuf[0];
while( (type=getaarg(token)) != EOF ) {
if( nargs >= MAXARGS ) {
error("too many arguments");
return;
}
args[nargs++] = abp;
for( p = token; *abp++ = *p++; ) {
if( abp >= &argbuf[ARGBSIZE] ) {
error("argument buffer overflow");
return;
}
}
if( type == RPAREN )
break;
}
}
if( *mdef == NEWLABEL ) {
clabel = nlabel;
if( !nargs )
nlabel++;
else
nlabel =+ atoi(args[0]);
}
else if( *mdef == LABEL ) {
if( !nargs )
i = clabel;
else
i = clabel + atoi(args[0]);
pbnum(i);
pbtok("_L");
}
else {
mdef++; /*skip no. of args*/
for( p = mdef + strlen(mdef) - 1; p >= mdef; p-- ) {
if( *p == ARG ) {
if( (j= *--p) <= nargs )
pbtok(args[j-1]);
}
else
putback(*p);
}
}
}
/* getfarg - get macro formal parameters*/
/* Skips blanks and handles "," and ")".*/
getfarg(token) /* returns token type*/
char *token; /* token returned*/
{
register int type;
if( (type=getntok(token)) == RPAREN || type == ALPHA )
return(type);
if( type != COMMA || (type=getntok(token)) != ALPHA )
error("bad argument:%s",token);
return(type);
}
/* getntok - get next token, suppressing white space*/
/* Merely gettok's until non-white space is there*/
getntok(token) /* returns token type*/
char *token; /* token returned*/
{
register int type;
while( (type=gettok(token)) == WHITE )
;
return(type);
}
/* getaarg - get macro actual argument*/
/* This handles the collecting of the macro's call arguments.*/
/* Note that you may have parenthesis as part of the macro argument,*/
/* hence you need to keep track of them.*/
getaarg(argp) /* returns token type*/
char *argp; /* argument returned*/
{
int type, plevel, i;
register char *p, *ap;
char token[TOKSIZE];
ap = argp;
*ap = '\0';
plevel = 0;
i = TOKSIZE;
while( ((type=gettok(token)) != COMMA && type != RPAREN) || plevel ) {
for( p = token; *ap = *p++; ap++ )
if( --i <= 0 ) {
error("macro argument too long");
return(EOF);
}
if( type == LPAREN )
plevel++;
else if( type == RPAREN )
plevel--;
else if( type == EOF ) {
error("unexpected EOF");
cexit();
}
}
if( ap == argp )
type = EOF;
return(type);
}
/* push - push a #ifdef condition value on condition stack*/
/* Checks for stack overflow.*/
push(val) /* returns - none*/
int val; /* value to push*/
{
if( cstkptr >= &cstack[CSTKSIZE] ) {
error("condition stack overflow");
cexit();
}
*cstkptr++ = val;
}
/* pop - pop the #ifdef, etc. condition stack*/
/* Checks for stack undeflow.*/
pop() /* returns - top of condition stack*/
{
if( cstkptr <= &cstack[0] )
return(-1);
return( *--cstkptr );
}
/* doinclude - handle #include command*/
/* Checks for file name or library file name and pushes file on*/
/* include file stack.*/
doinclude(infile) /* returns - none*/
char *infile; /* [vlh] for quoted include files */
{
register int type, fd;
char token[TOKSIZE], fname[TOKSIZE];
register char *p, *q, c, *ptr1, *ptr2;
int i, j;
p = fname;
if( (type=getntok(token)) == SQUOTE || type == DQUOTE ) {
for( c = token[0], q = &token[1]; *q != c; )
*p++ = *q++;
*p = '\0';
p = getinclude(fname,infile);
}
else if( type != LESS ) {
error("bad include file");
return;
}
else {
while( (type=gettok(token))!=GREAT && type!=NEWL && type!=EOF )
for( q = token; *p = *q++; p++ )
;
if( type != GREAT ) {
error("bad include file name");
pbtok(token);
return;
}
p = getinclude(fname,0L);
}
eatup(); /*need here...*/
filep++;
if( filep >= &filestack[FSTACK] )
error("includes nested too deeply");
else {
if( fopen(p,&(filep->inbuf),0) < 0 )/* 3rd arg for versados */
error("can't open include file %s\n",p);
else {
filep->ifd = fd;
filep->lineno = 0; /* [vlh] */
doifile(p);
}
}
putback('\n'); /*for eatup in domacro*/
}
doifile(p) /* [vlh] */
char *p;
{
register char *iptr;
register int ndx;
while ((ndx = index(p,FILESEP)) >= 0) p =+ ndx+1;
for( iptr = filep->ifile; *p; ) *iptr++ = *p++;
*iptr = 0;
}
/* getinclude - get include file full pathname */
char *
getinclude(fname,parent) /* [vlh] */
char *fname;
char *parent; /* search parent-file home directory ? */
{
register char *q, *t;
register int i, fd, ndx;
if (parent) { /* include filename surrounded by quotes */
q = (filep == &filestack[0]) ? parent : (filep)->ifile;
t = &inclname;
while ((ndx = index(q,FILESEP)) >= 0) {
ndx++;
while (ndx--) *t++ = *q++;
}
for (q=fname; *t++ = *q++; );
*t = 0;
if ((fd = open(inclname,0)) >= 0) { /* found it */
close(fd);
return(&inclname);
}
}
for (i=0; i<nincl; i++) {
for(t=inclname, q=incl[i]; *t++ = *q++; ) ;
for(q=fname, --t; *t++ = *q++; ) ;
*t = 0;
if ((fd = open(inclname,0)) >= 0) {
close(fd);
return(&inclname);
}
}
for(t=inclname, q=stdincl; *t++ = *q++; ) ;
for(q=fname, --t; *t++ = *q++; ) ;
*t = 0;
return(&inclname);
}
pbnum(num) /* returns - none*/
int num;
{
register int digit;
do {
digit = num % 10;
num =/ 10;
putback(digit+'0');
} while( num > 0 );
}

View File

@@ -0,0 +1,141 @@
#
/*
Copyright 1981
Alcyon Corporation
8474 Commerce Av.
San Diego, Ca. 92121
*/
#include "preproc.h"
int status = 0;
char *stdincl; /* Include prefix for macro processor */
/* cexit - exit from C compiler driver*/
/* This deletes any existing temps and exits with the error status.*/
cexit() /* returns - none*/
{
exit(status);
}
/* main - main routine for C68 Compiler system*/
/* Handles the C68 arguments. For each C file given, the macro*/
/* pre-processor is called, then the parser, code generator and*/
/* assember are fexec'd. The loader arguments are collected and*/
/* the loader is fexec'd.*/
main(argc,argv)
int argc;
char **argv;
{
if(argc < 3)
usage();
if (*argv[1] == '-')
{
if(argc != 5 || argv[1][1] != 'i')
usage();
stdincl = argv[2];
domacro(argv[3],argv[4],0,0L);
cexit();
}
if(argc != 3)
usage();
domacro(argv[1],argv[2],0,0L);
cexit();
}
usage()
{
error("usage: c68 [-i x:] inputfile outputfile\n");
exit();
}
/* strcmp - string comparison*/
/* Compares two strings for equality, less or greater.*/
strcmp(s,t) /* returns 0 for equality,*/
/* neg for < and pos for >.*/
char *s; /* first string*/
char *t; /* second string*/
{
for( ; *s == *t; s++, t++ )
if( *s == '\0' )
return(0);
return( *s - *t );
}
/* strlen - string length*/
/* Computes number of bytes in string.*/
strlen(s) /* returns string length*/
char *s; /* string to compute length*/
{
register int n;
for( n = 0; *s++ != '\0'; )
n++;
return(n);
}
/* itoa - integer to ASCII conversion*/
/* Converts integer to ASCII string, handles '-'.*/
itoa(n,s,w) /* returns - none*/
int n; /* number to convert*/
char *s; /* resulting string*/
int w; /* minimum width of string*/
{
register int sign, i;
char temp[6];
if( (sign=n) < 0 )
n = -n;
i = 0;
do {
temp[i++] = n % 10 + '0';
} while( (n =/ 10) > 0 );
if( sign < 0 )
temp[i++] = '-';
while( --w >= i ) /*pad on left with blanks*/
*s++ = ' ';
while( --i >= 0 ) /*move chars reversed*/
*s++ = temp[i];
*s = '\0';
}
/* strend - set string end*/
/* This is used to compare the endings of file names for ".c", etc.*/
strend(s,t) /* returns 1 if match, 0 otherwise*/
char *s; /* string to compare*/
char *t; /* string ending*/
{
int ls, lt;
if( (ls=strlen(s)) < (lt=strlen(t)) )
return(0);
if( strcmp(&s[ls-lt],t) == 0 )
return(1);
return(0);
}
/* index - find the index of a character in a string*/
/* This is identical to Software Tools index.*/
index(str,chr) /* returns index of c in str or -1*/
char *str; /* pointer to string to search*/
char chr; /* character to search for*/
{
register char *s;
register int i;
for( s = str, i = 0; *s != '\0'; i++ )
if( *s++ == chr )
return(i);
return(-1);
}
v6flush(v6buf)
struct iobuf *v6buf;
{
register i;
i = BLEN - v6buf->nunused;
v6buf->nunused = BLEN;
v6buf->xfree = &(v6buf->buff[0]);
if(write(v6buf->fildes,v6buf->xfree,i) != i)
return(-1);
return(0);
}

View File

@@ -0,0 +1,49 @@
$1stat machine.h=rw
$1pip machine.h=machine.68k
$1cp68 -i 0$1 CEXPR.c $1x.i
$1c068 $1x.i $1x.ic $1x.st
$1c168 $1x.ic CEXPR.s -LD
era $1x.i
era $1x.ic
era $1x.st
$1as68 -s 0$1 -f $1 -l -u CEXPR.s
era CEXPR.s
$1cp68 -i 0$1 LEX.c $1x.i
$1c068 $1x.i $1x.ic $1x.st
$1c168 $1x.ic LEX.s -LD
era $1x.i
era $1x.ic
era $1x.st
$1as68 -s 0$1 -f $1 -l -u LEX.s
era LEX.s
$1cp68 -i 0$1 MACRO.c $1x.i
$1c068 $1x.i $1x.ic $1x.st
$1c168 $1x.ic MACRO.s -LD
era $1x.i
era $1x.ic
era $1x.st
$1as68 -s 0$1 -f $1 -l -u MACRO.s
era MACRO.s
$1cp68 -i 0$1 MAIN.c $1x.i
$1c068 $1x.i $1x.ic $1x.st
$1c168 $1x.ic MAIN.s -LD
era $1x.i
era $1x.ic
era $1x.st
$1as68 -s 0$1 -f $1 -l -u MAIN.s
era MAIN.s
$1cp68 -i 0$1 UTIL.c $1x.i
$1c068 $1x.i $1x.ic $1x.st
$1c168 $1x.ic UTIL.s -LD
era $1x.i
era $1x.ic
era $1x.st
$1as68 -s 0$1 -f $1 -l -u UTIL.s
era UTIL.s
link $1

View File

@@ -0,0 +1,150 @@
/*
Copyright 1982
Alcyon Corporation
8716 Production Ave.
San Diego, Ca. 92121
*/
#include <stdio.h>
#include <klib.h>
#include "icode.h"
#include "machine.h"
/*cexpr operators*/
#define EOF 0
#define SUB 1
#define ADD 2
#define NOT 3
#define NEG 4
#define LPAREN 5
#define RPAREN 6
#define QMARK 7
#define COLON 8
#define OR 9
#define AND 10
#define XOR 11
#define EQUAL 12
#define NEQUAL 13
#define LESS 14
#define LSEQUAL 15
#define GREAT 16
#define GREQUAL 17
#define LSHIFT 18
#define RSHIFT 19
#define MULT 20
#define DIV 21
#define MOD 22
#define COMPL 23
#define CONST 24
#define LASTOP COMPL /*up to here used by cexpr*/
#define SQUOTE 25
#define DQUOTE 26
#define ANYC 27
#define BADC 28
#define COMMA 29
#define NEWL 30
#define POUND 31
#define ALPHA 32
#define DIGIT 33
#define BSLASH 34
#define WHITE 35
#define BUFSIZE 512
#define LINESIZE 512
#define ARG -1
#define NEWLABEL -2
#define LABEL -3
#define NOARGS -4
#define MAXARGS 60
#define ARGBSIZE 1000
#define TOKSIZE 300 /*BUG 4/20/82 was 128*/
#define DEFSIZE 1024
#define PBSIZE 1000
#define DEFINE 1
#define UNDEF 2
#define INCLUDE 3
#define IFDEF 4
#define IFNDEF 5
#define ELSE 6
#define ENDIF 7
#define IF 8
#define SKIP 0
#define NOSKIP 1
#define SOH '\01'
#define SSIZE 8
#define HSIZE 517 /* 3.4 made prime */
#define FSTACK 10
#define TRUE 1
#define FALSE 0
#define NDEFS 20
struct symbol {
char s_name[SSIZE];
char *s_def;
} symtab[HSIZE];
/*buffered I/O structure*/
struct ibuf {
int fd;
int nc;
char *bp;
char buffer[BUFSIZE];
} outbuf;
/* command line define structure */
struct defstruc {
char *ptr;
char *value;
} defs[NDEFS];
struct stackstruc { /* [vlh] */
int ifd;
char ifile[13];
int lineno;
struct ibuf inbuf;
} filestack[FSTACK], *filep; /* stack of incl files, ptr to... */
#ifdef BULLSHIT /* Bullshit, bullshit, bullshit!!!*/
#ifdef VERSADOS
#define NONEST 1
#define NOFORKS 1
#endif
#ifdef VMS
#define NONEST 1
#endif
#ifdef NONEST
struct ibuf holdbuf; /* alternate buffer, hold main file info */
#endif
#endif
int mfail; /*macro error flag*/
int skip; /*skipping current line*/
char *defap; /*pointer to available define area*/
char *defp; /*pointer to next avail define byte*/
int defcount; /*bytes left in define area*/
int defused; /*number of bytes used in define area*/
int defmax; /*maximum define area used*/
int pflag;
int asflag;
/*line to output after macro substitution*/
char line[LINESIZE+2]; /*line buffer*/
char *linep; /*current line pointer*/
int loverflow; /*line overflow flag*/
int lineno;
/*push back buffer*/
char pbbuf[PBSIZE]; /*push back buffer*/
char *pbp; /*push back pointer*/
int pbflag; /*checks for recursive definition*/
char null[]; /*used for undef'd symbols*/
char *lookup();
#ifdef BULLSHIT
char *maketemp();
char *setend();
char *makecopy();
#endif
char *sbrk();
struct symbol *getsp();

View File

@@ -0,0 +1,12 @@
e:send MACHINE.H
e:send CEXPR.C
e:send LEX.C
e:send MACRO.C
e:send MAIN.C
e:send UTIL.C
e:send ICODE.H
e:send PREPROC.H
e:send LINK.SUB
e:send MAKE.SUB
e:send MACHINE.68K
e:send SEND11.SUB

View File

@@ -0,0 +1,16 @@
atoi(as)
char *as;
{
register int n, sign;
register char *s;
s = as;
while( *s==' ' || *s=='\n' || *s == '\t')
s++;
sign = 1;
if( *s == '+' || *s == '-' )
sign = (*s++=='+') ? 1 : -1;
for( n = 0; *s >= '0' && *s <= '9'; s++ )
n = (n * 10) + (*s - '0');
return( sign * n );
}

View File

@@ -0,0 +1,14 @@
$ preproc
$ set noon
$ !
$ ! Build file for VMS version of CP68
$ !
$ copy machine.vax machine.h
$ pur machine.h
$ cx CEXPR
$ cx INIT
$ cx LEX
$ cx MACRO
$ cx MAIN
$ cx UTIL
$ clink cexpr,init,lex,macro,main,util,lib:klib/lib cp68

View File

@@ -0,0 +1,613 @@
/*
* flxtp keys [name ...]
* keys are:
* w write to beginning of tape
* a append to end of tape
* r read named files from tape; if no names, extract all
* t table named files; or table all
* also may add:
* v verbose
* i wait for user 'y' before performing function
* u leave extracted filenames in upper case (usually
* filenames are mapped to lower case)
* n don't rewind tape before performing action
* [x,y] specify uic for tape
* pooo use protection ooo on tape
* bddd use blocksize ddd to write on tape
* (tape read automagically determines blksize)
* ddddd use density dddd (800 or 1600)
* o ok to overwrite existing files when extracting
* (default will not overwrite existing files)
* m make a new directory for each uic found on tape and
* put the extracted files in them
*
* name is a unix path name (for writing tapes) or the name of
* a file on the tape. When writing tapes, a name may be a uic
* in the same form as above. This causes all following files
* to be written on the tape in that uic.
*/
#include <stdio.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#define FLXHD 14
#define FLXDATA 512
/*
* len of longest unpacked filename, including the null at end
* and one extra space for version 'number'
*/
#define FLXNM 15
#define MAXBASE (9+1)
#define MAXEXT (3+1)
/* note byte swap for DEC machines */
#define OFFNAME 0
#define OFFEXT 4
#define OFFUIC2 6
#define OFFUIC1 7
#define OFFPROT2 8
#define OFFPROT1 9
#define OFFDATE2 10
#define OFFDATE1 11
#define OFFOVER 12
#define DEFUIC1 '\001'
#define DEFUIC2 '\001'
#define DEFPROT1 '\000'
#define DEFPROT2 '\233'
#define CR '\015'
#define LF '\012'
#define NL '\012'
#define TPWRITE 'w'
#define TPAPPEND 'a'
#define TPREAD 'r'
#define TPTABLE 't'
#define IOPT 'i'
#define VOPT 'v'
#define UOPT 'u'
#define NOPT 'n'
#define POPT 'p'
#define BOPT 'b'
#define DOPT 'd'
#define OOPT 'o'
#define MOPT 'm'
#define NOCMD '\0'
struct parsehdr {
char phname[FLXNM];
char phuic1;
char phuic2;
char phprot1;
char phprot2;
char phdate[11];
};
int verbose, mkdirs, overwrite, inquire, allfiles, uicfiles, upcase, norewind = 0;
int argsleft, filenbr, actnbr = 0;
char tp1600[] = "/dev/nrmt0";
char tp1600rw[] = "/dev/rmt0";
char bsr1600[] = "mt -t /dev/nrmt0 bsr 1";
char tp800[] = "/dev/nrmt0";
char tp800rw[] = "/dev/rmt0";
char bsr800[] = "mt -t /dev/nrmt0 bsr 1";
char *devtp = tp1600;
char *devtprw = tp1600rw;
char *bsrcmd = bsr1600;
int tpfd;
FILE *dfd;
char uic1 = DEFUIC1;
char uic2 = DEFUIC2;
char prot1 = DEFPROT1;
char prot2 = DEFPROT2;
char date1 = '\000';
char date2 = '\000';
#define BIGBLK 32768
unsigned tpblksiz = FLXDATA;
char *tpbuf, *malloc();
char cmd = NOCMD;
/*
* flxtp - read or write flx format tape
*/
main (argc, argv)
int argc;
char **argv;
{
int k;
int density;
char c = '\0';
if (argc < 2) usage();
if (argc == 2) allfiles++;
else argsleft = argc - 2;
argv++; /* skip over command name */
k=0;
while ( (c=(*argv)[k++]) != '\0') {
switch (c) {
case TPAPPEND:
#ifndef PICKLE
error ("append function not implemented");
#endif
/* fall thru to write */
case TPWRITE:
if (cmd != NOCMD) error ("Only one of rwat may be selected");
if (allfiles) error ("Name(s) must be given for w or a");
cmd = c;
break;
case TPREAD:
/* fall thru */
case TPTABLE:
if (cmd != NOCMD) error ("Only one of rwat may be selected");
cmd = c;
break;
case MOPT: mkdirs++; break;
case OOPT: overwrite++; break;
case NOPT: norewind++; break;
case IOPT: inquire++; break;
case VOPT: verbose++; break;
case UOPT: upcase++; break;
case '[':
if(sscanf(&(*argv)[k],"%3o,%3o]",&uic1,&uic2)==2 ) {
while ( (*argv)[k++] != ']');
}
else error ("Uic must be given as [xxx,yyy]");
uicfiles++;
break;
case POPT:
if(sscanf(&(*argv)[k],"%3o",&prot2) == 1 ) {
while ( isdigit ( (*argv)[k]) )
k++;
}
else error ("Protection must be given as pooo");
break;
case BOPT:
if (sscanf(&(*argv)[k],"%d",&tpblksiz) == 1) {
while ( isdigit ( (*argv)[k] ) )
k++;
}
else error ("Tape blocksize must be given as bddd");
break;
case DOPT:
if (sscanf(&(*argv)[k],"%d",&density) == 1) {
while ( isdigit ( (*argv)[k] ) )
k++;
if (density==1600) {/* already set */}
else if (density==800) {
devtp=tp800;
devtprw=tp800rw;
bsrcmd=bsr800;
}
else error ("Density must be given as d800 or d1600");
}
else error ("Density must be given as d800 or d1600");
break;
case '-': /* ignore */ break;
default:
usage();
} /* switch */
} /* while */
if (cmd == TPREAD | cmd == TPTABLE) tpblksiz = BIGBLK;
if ( (tpbuf=malloc(tpblksiz)) == (char *) 0)
error ("Sorry, can't get buffer for your blocksize");
argv++; /* skip over keys */
if ( !norewind) {
if((tpfd=open(devtprw,0)) == -1)
error ("Can't access tape");
close(tpfd);
}
switch (cmd) {
case TPAPPEND:
seekeot();
/* fall thru to put files */
case TPWRITE:
putfiles (argv);
break;
case TPREAD:
getfiles (argv);
break;
case TPTABLE:
tblfiles (argv);
break;
default:
error ("Pgm error; see sys msg");
} /* switch */
exit (0);
} /* flxtp */
error (msg)
char *msg;
{
fprintf (stderr,"%s\n",msg);
exit (-1);
} /* error */
usage ()
{
fprintf (stderr,"Usage: flxtp (rwat)[vilnupOOObDDDdDDDD] [name ...]\nwhere u = [x,y]\n");
exit (-1);
} /* usage */
int tblfiles (list)
char **list;
{
char hdr[FLXHD];
struct parsehdr phdr;
int nr, nbrblk, totblks = 0;
if ( (tpfd=open(devtp,0)) == -1) error ("Can't open tape");
while (allfiles | argsleft) {
if ((nr=read(tpfd,hdr,FLXHD)) == 0) break;
expandhdr (hdr, &phdr);
filenbr++;
if (amatch (&phdr, list)) {
nbrblk = gobblefile();
totblks += nbrblk;
fprintf(stdout,"File %4d: %-13s %5d <%3o> [%3o,%3o]\n",
filenbr, phdr.phname, nbrblk,
phdr.phprot2&0xff, phdr.phuic1&0xff, phdr.phuic2&0xff);
actnbr++;
if (!allfiles) argsleft--;
}
else nbrblk = gobblefile();
}
if(allfiles) fprintf (stdout,"Total %d data blocks in %d files listed\n",
totblks,actnbr);
if (!allfiles & argsleft) fprintf (stderr,"Other files not found\n");
close (tpfd);
} /* tblfiles */
int gobblefile ()
{
int nr, nbrblk = 0;
while ((nr=read(tpfd,tpbuf,tpblksiz)) > 0)
nbrblk++;
return (nbrblk);
} /* gobblefile */
int getfiles (list)
char **list;
{
char wuic1, wuic2 = 0;
char hdr[FLXHD], reply[2], *pfull, *p, *q, *v, *fname, overname[FLXNM];
static char versions[] = "!@#$%^&*()";
static char mkdircmd [] = "mkdir 000,000.dir";
static char *pathname = &mkdircmd[6];
static char fullname[27];
struct parsehdr phdr;
int nr, ip, jp, nbrblk = 0;
if ( (tpfd=open(devtp,0)) == -1) error ("Can't open tape");
while (allfiles | argsleft) {
if ((nr=read(tpfd,hdr,FLXHD)) == 0)
break;
expandhdr ( hdr, &phdr);
filenbr++;
if (amatch (&phdr, list) ) {
if (!allfiles) argsleft--;
if (inquire) {
fprintf (stdout,"Extract %s? (y/n) ",phdr.phname);
fread(reply,1, 2, stdin);
if (*reply != 'y') goto skip;
}
if (mkdirs) {
if (phdr.phuic1 != wuic1 | phdr.phuic2 != wuic2) {
wuic1=phdr.phuic1;
wuic2=phdr.phuic2;
sprintf(pathname,
"%03o,%03o.dir",
wuic1&0xff, wuic2&0xff);
if (access(pathname,0) != 0) {
if (system(mkdircmd) != 0)
error ("Can't make directory");
}
}
pfull = fullname;
p = pathname;
while ( *pfull++ = *p++ );
pfull[-1] = '/';
p = phdr.phname;
while ( *pfull++ = *p++);
fname = fullname;
}
else fname = phdr.phname;
if (verbose) fprintf (stdout,
"get [%3o,%3o] %s file # %d\n",
phdr.phuic1&0xff, phdr.phuic2&0xff, fname, filenbr);
if (!overwrite && (access(fname,0 /* exists */) == 0)) {
/* try adding 'version' char at end of name */
v=versions;
p=fname; q=overname;
while (*p) *q++ = *p++;
*(q+1) = '\0';
while (*v) {
*q = *v;
if (access(overname,0)) break;
v++; /* try next 'version' nbr */
}
if (*v == 0) { /*already 10 versions */
printf("Can't overwrite %s\n",
overname);
goto skip;
}
printf("Duplicate filename; %s used\n",
overname);
fname = overname;
}
if ( (dfd=fopen(fname, "w")) == NULL)
error ("Can't open disk file");
while ( (nr=read(tpfd, tpbuf, tpblksiz)) > 0){
ip = jp = 0;
while (ip<nr) {
tpbuf[jp] = tpbuf[ip];
if (tpbuf[jp] == CR
|| tpbuf[jp] == '\0')
jp--;
ip++; jp++;
} /* while */
if (fwrite(tpbuf, 1, jp, dfd) != jp)
error ("Disk write error");
} /* while */
if (nr == -1) error ("Tape read error");
fclose(dfd);
actnbr++;
continue;
}
skip: nbrblk=gobblefile();
}
if (allfiles | verbose) fprintf (stdout,"Total %d files extracted\n",actnbr);
if ((!allfiles) & argsleft) fprintf (stderr,"%d files not found\n",argsleft);
close (tpfd);
} /* getfiles */
seekeot () {
int nr, stat;
if ( (tpfd=open(devtp,0)) == -1) error ("Can't open tape");
if (verbose) fprintf (stdout,"Seeking to end of tape\n");
while (1) {
stat = read(tpfd,tpbuf,tpblksiz);
if(stat <= 0) break;
nr = gobblefile ();
filenbr++;
}
if (stat == -1) error ("Can't find end of tape");
close (tpfd);
/* back up before second eot mark */
if (system(bsrcmd)) error ("Can't find end of tape");
} /* seekeot */
putfiles (list)
char **list;
{
int n, nbrblk = 0;
char reply[2];
struct stat sbuf;
while ( *list != NULL) {
actnbr++;
filenbr++;
if (**list == '[') {
/* set new uic for writing */
if (sscanf(*list, "[%3o,%3o]", &uic1, &uic2) != 2)
error ("Uic must be given as [xxx,yyy]");
list++;
actnbr--;
filenbr--;
continue;
}
if ( (stat(*list,&sbuf) == 0) &&
(sbuf.st_mode & S_IFDIR) ) {
printf("Directory %s ignored\n", *list);
list++;
actnbr--;
filenbr--;
continue;
}
if (inquire) {
fprintf (stdout, "%c File # %d %s? (y/n) ",cmd, actnbr, *list);
fread (reply, 1, 2, stdin);
if (*reply != 'y') continue;
actnbr--;
filenbr--;
}
if (verbose)
fprintf (stdout,"%c File #%4d [%3o,%3o] %s ",
cmd, filenbr, uic1&0xff, uic2&0xff, *list);
if ( (dfd=fopen(*list, "r")) != NULL) {
if ( (tpfd=open(devtp,2)) == -1)
error ("Can't open tape");
if (puthdr(*list)) error ("Can't write tape");
nbrblk=0;
while ( n=buildbuf()) {
if (write(tpfd,tpbuf,n) != n)
error ("Tape write error");
nbrblk++;
}
close(tpfd);
fclose(dfd);
if (verbose) fprintf (stdout,"%d data blocks\n",nbrblk);
}
else fprintf (stderr,"Can't open diskfile %s\n", *list);
list++;
} /* while */
if (verbose) fprintf (stdout, "Total %d files written to tape\n",actnbr);
} /* putfiles */
int puthdr (name)
char *name;
{
char buf[FLXHD], base[MAXBASE], ext[MAXEXT], *nend;
int i;
/* get parts of filename */
fnparts(name,base,MAXBASE,ext,MAXEXT);
/* pad both parts with blanks */
nend=base;
i=0;
while (*nend) {nend++; i++;}
while ( i < MAXBASE ) base[i++] = ' ';
nend=ext;
i=0;
while (*nend) {nend++; i++;}
while ( i < MAXEXT ) ext[i++] = ' ';
/* convert both parts to rad50 */
ator50 (base, 6, &buf[OFFNAME]);
ator50 (&base[6], 3, &buf[OFFOVER]);
ator50 (ext, 3, &buf[OFFEXT]);
buf[OFFUIC1] = uic1;
buf[OFFUIC2] = uic2;
buf[OFFPROT1] = prot1;
buf[OFFPROT2] = prot2;
buf[OFFDATE1] = date1;
buf[OFFDATE2] = date2;
if (write(tpfd,buf,FLXHD) != FLXHD) return (-1);
return (0);
} /* puthdr */
int buildbuf ()
{
static int crlf, deof = 0;
int n, c;
n = 0;
if (crlf) {
tpbuf[n++] = LF;
crlf = 0;
}
if (deof) {deof=0; return(0);}
while (n <tpblksiz) {
c=getc(dfd);
if (c == EOF) {deof++; break;}
if (c == NL) {
tpbuf[n++] = CR;
if (n<tpblksiz) tpbuf[n++] = LF;
else {crlf++; break;}
}
else tpbuf[n++] = c;
}
if (n%2 != 0) tpbuf[n++] = '\0';
return (n);
} /* buildbuf */
char unmap (n)
unsigned n;
{
static char rm[] = " ABCDEFGHIJKLMNOPQRSTUVWXYZ$.!0123456789";
static char rml[]= " abcdefghijklmnopqrstuvwxyz$.!0123456789";
if (n<40) {
if (upcase) return (rm[n]);
else return (rml[n]);
}
return ('!'); /* error */
} /* unmap */
r50toa (s, slen, d)
char *s, *d;
int slen;
{
unsigned word;
int i, j, i2;
for (i=j=0; i<slen; i++) {
i2= i*2;
/* note byte swap for DEC machines */
word = ( (s[i2+1]<<8) | (s[i2]&0xff) ) & 0xffff;
d[j++]=unmap(word/1600);
d[j++]=unmap((word%1600)/40);
d[j++]=unmap((word%1600)%40);
} /* for */
d[j++]='\0';
} /* r50toa */
ator50 (s, slen, d)
char *s, *d;
int slen;
{
int i, word;
for (i=0; i<slen; i+=3) {
word = radmap(s[i])*1600 + radmap(s[i+1])*40 + radmap(s[i+2]);
/* note byte swap for DEC machine */
*d++ = word;
*d++ = word>>8;
} /* for */
} /* ator50 */
int radmap (c)
char c;
{
if (islower(c)) return (c-96);
if (isupper(c)) return (c-64);
if (isdigit(c)) return (c-18);
if (c==' ') return (0);
if (c=='$') return (27);
if (c=='.') return (28);
return (29);
} /* radmap */
#define MATCH 1
#define NOMATCH 0
int amatch (ph, list)
struct parsehdr *ph;
char **list;
{
if (allfiles) {
if (uicfiles) {
if (ph->phuic1 == uic1 & ph->phuic2 == uic2)
return (MATCH);
else return (NOMATCH);
}
else return (MATCH);
}
if (uicfiles)
if (ph->phuic1 != uic1 | ph->phuic2 != uic2) return (NOMATCH);
while (*list) {
if (strncmp (ph->phname, *list, FLXNM) == 0)
return (MATCH);
list++;
} /* while */
return (NOMATCH);
} /* amatch */
expandhdr (hdr, ph)
char *hdr;
struct parsehdr *ph;
{
char *nm;
nm = ph->phname;
r50toa(&hdr[OFFNAME], 2 /* words */, nm);
while (*nm > ' ') nm++;
r50toa(&hdr[OFFOVER], 1 /* word */, nm);
while (*nm > ' ') nm++;
*nm++ = '.';
r50toa (&hdr[OFFEXT], 1 /* word */, nm);
while (*nm > ' ') nm++;
/* if filename ends in '.', just drop it */
if ( *(nm - 1) == '.') nm--;
*nm = '\0';
ph->phuic1 = hdr[OFFUIC1];
ph->phuic2 = hdr[OFFUIC2];
ph->phprot1 = hdr[OFFPROT1];
ph->phprot2 = hdr[OFFPROT2];
ph->phdate[0] = '\0'; /* don't yet know how to parse date */
} /* expandhdr */

View File

@@ -0,0 +1,58 @@
#include <stdio.h>
#include <ctype.h>
#define PERIOD '.'
#define SLASH '/'
fnparts (origfn, base, maxbase, suffix, maxsuffix)
char *origfn, *base, *suffix;
int maxbase, maxsuffix;
{
char *end, *bp, *sp, *endbase;
int i;
/* point past last char of orignal filename */
end = origfn;
while (*end++);
/* find suffix by scanning backwards for '.'
* but don't backup before a pathname
*/
sp = end;
while ( *sp != PERIOD & *sp != SLASH & sp != origfn) sp--;
if ( *sp != PERIOD ) { /* no suffix found */
endbase = end;
*suffix = '\0';
}
else {
endbase = sp++; /* and skip the '.' */
i=0;
while ( i< (maxsuffix-1)) {
if (islower(*sp) | isdigit(*sp) | isupper(*sp) )
*suffix++ = *sp++;
else sp++; /* ignore other chars */
if ( *sp == '\0' ) break;
} /* while */
*suffix = '\0'; /* terminate with null */
} /* end of getting the suffix */
/* find base by scanning backwards from suffix */
bp=endbase;
while ( *bp != SLASH & bp != origfn ) bp--;
if ( *bp == SLASH ) bp++; /* skip slash, if found */
i=0;
while ( i < (maxbase-1) ) { /* save the base */
if (islower(*bp) | isdigit(*bp) | isupper(*bp))
*base++ = *bp++;
else bp++; /* ignore other chars */
if ( bp == endbase ) break;
} /* save the base */
*base = '\0'; /* terminate with null */
} /* fnparts */

View File

@@ -0,0 +1,6 @@
flxtp: flxtp.c /usr/carol/mylibc/mylib.a
cc -DPICKLE flxtp.c /usr/carol/mylibc/mylib.a -o flxtp
install:
mv /usr/tandy/flxtp /usr/tandy/old/
mv flxtp /usr/tandy

View File

@@ -0,0 +1,14 @@
CFLAGS=-O
h = tp.h tp_defs.h
o = tp0.o tp1.o tp2.o tp3.o
tp : $o
$(CC) -o tp $o
$o : $h
install : tp
install -s tp ${DESTDIR}/bin
clean :
rm -f *.o

View File

@@ -0,0 +1,958 @@
static char *sccsid = "@(#)tar.c 4.5 (Berkeley) 81/04/02";
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/dir.h>
#include <sys/mtio.h>
#include <signal.h>
char *sprintf();
char *strcat();
daddr_t bsrch();
#define TBLOCK 512
#define NBLOCK 20
#define NAMSIZ 100
union hblock {
char dummy[TBLOCK];
struct header {
char name[NAMSIZ];
char mode[8];
char uid[8];
char gid[8];
char size[12];
char mtime[12];
char chksum[8];
char linkflag;
char linkname[NAMSIZ];
} dbuf;
} dblock, tbuf[NBLOCK];
struct linkbuf {
ino_t inum;
dev_t devnum;
int count;
char pathname[NAMSIZ];
struct linkbuf *nextp;
} *ihead;
struct stat stbuf;
int rflag, xflag, vflag, tflag, mt, cflag, mflag, fflag, oflag, pflag;
int term, chksum, wflag, recno, first, linkerrok;
int freemem = 1;
int nblock = NBLOCK;
daddr_t low;
daddr_t high;
FILE *tfile;
char tname[] = "/tmp/tarXXXXXX";
char *usefile;
char magtape[] = "/dev/rmt8";
char *malloc();
main(argc, argv)
int argc;
char *argv[];
{
char *cp;
int onintr(), onquit(), onhup(), onterm();
if (argc < 2)
usage();
tfile = NULL;
usefile = magtape;
argv[argc] = 0;
argv++;
for (cp = *argv++; *cp; cp++)
switch(*cp) {
case 'f':
usefile = *argv++;
fflag++;
break;
case 'c':
cflag++;
rflag++;
break;
case 'o':
oflag++;
break;
case 'p':
pflag++;
break;
case 'u':
mktemp(tname);
if ((tfile = fopen(tname, "w")) == NULL) {
fprintf(stderr, "Tar: cannot create temporary file (%s)\n", tname);
done(1);
}
fprintf(tfile, "!!!!!/!/!/!/!/!/!/! 000\n");
/* FALL THROUGH */
case 'r':
rflag++;
break;
case 'v':
vflag++;
break;
case 'w':
wflag++;
break;
case 'x':
xflag++;
break;
case 't':
tflag++;
break;
case 'm':
mflag++;
break;
case '-':
break;
case '0':
case '1':
case '4':
case '5':
case '7':
case '8':
magtape[8] = *cp;
usefile = magtape;
break;
case 'b':
nblock = atoi(*argv++);
if (nblock > NBLOCK || nblock <= 0) {
fprintf(stderr, "Invalid blocksize. (Max %d)\n", NBLOCK);
done(1);
}
break;
case 'l':
linkerrok++;
break;
default:
fprintf(stderr, "tar: %c: unknown option\n", *cp);
usage();
}
if (rflag) {
if (cflag && tfile != NULL) {
usage();
done(1);
}
if (signal(SIGINT, SIG_IGN) != SIG_IGN)
signal(SIGINT, onintr);
if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
signal(SIGHUP, onhup);
if (signal(SIGQUIT, SIG_IGN) != SIG_IGN)
signal(SIGQUIT, onquit);
/*
if (signal(SIGTERM, SIG_IGN) != SIG_IGN)
signal(SIGTERM, onterm);
*/
if (strcmp(usefile, "-") == 0) {
if (cflag == 0) {
fprintf(stderr, "Can only create standard output archives\n");
done(1);
}
mt = dup(1);
nblock = 1;
}
else if ((mt = open(usefile, 2)) < 0) {
if (cflag == 0 || (mt = creat(usefile, 0666)) < 0) {
fprintf(stderr, "tar: cannot open %s\n", usefile);
done(1);
}
}
dorep(argv);
}
else if (xflag) {
if (strcmp(usefile, "-") == 0) {
mt = dup(0);
nblock = 1;
}
else if ((mt = open(usefile, 0)) < 0) {
fprintf(stderr, "tar: cannot open %s\n", usefile);
done(1);
}
doxtract(argv);
}
else if (tflag) {
if (strcmp(usefile, "-") == 0) {
mt = dup(0);
nblock = 1;
}
else if ((mt = open(usefile, 0)) < 0) {
fprintf(stderr, "tar: cannot open %s\n", usefile);
done(1);
}
dotable();
}
else
usage();
done(0);
}
usage()
{
fprintf(stderr, "tar: usage tar -{txru}[cvfblm] [tapefile] [blocksize] file1 file2...\n");
done(1);
}
dorep(argv)
char *argv[];
{
register char *cp, *cp2;
char wdir[60];
if (!cflag) {
getdir();
do {
passtape();
if (term)
done(0);
getdir();
} while (!endtape());
if (tfile != NULL) {
char buf[200];
sprintf(buf, "sort +0 -1 +1nr %s -o %s; awk '$1 != prev {print; prev=$1}' %s >%sX; mv %sX %s",
tname, tname, tname, tname, tname, tname);
fflush(tfile);
system(buf);
freopen(tname, "r", tfile);
fstat(fileno(tfile), &stbuf);
high = stbuf.st_size;
}
}
getwdir(wdir);
while (*argv && ! term) {
cp2 = *argv;
if (!strcmp(cp2, "-C") && argv[1]) {
argv++;
if (chdir(*argv) < 0)
perror(*argv);
else
getwdir(wdir);
argv++;
continue;
}
for (cp = *argv; *cp; cp++)
if (*cp == '/')
cp2 = cp;
if (cp2 != *argv) {
*cp2 = '\0';
chdir(*argv);
*cp2 = '/';
cp2++;
}
putfile(*argv++, cp2);
chdir(wdir);
}
putempty();
putempty();
flushtape();
if (linkerrok == 1)
for (; ihead != NULL; ihead = ihead->nextp)
if (ihead->count != 0)
fprintf(stderr, "Missing links to %s\n", ihead->pathname);
}
endtape()
{
if (dblock.dbuf.name[0] == '\0') {
backtape();
return(1);
}
else
return(0);
}
getdir()
{
register struct stat *sp;
int i;
readtape( (char *) &dblock);
if (dblock.dbuf.name[0] == '\0')
return;
sp = &stbuf;
sscanf(dblock.dbuf.mode, "%o", &i);
sp->st_mode = i;
sscanf(dblock.dbuf.uid, "%o", &i);
sp->st_uid = i;
sscanf(dblock.dbuf.gid, "%o", &i);
sp->st_gid = i;
sscanf(dblock.dbuf.size, "%lo", &sp->st_size);
sscanf(dblock.dbuf.mtime, "%lo", &sp->st_mtime);
sscanf(dblock.dbuf.chksum, "%o", &chksum);
if (chksum != checksum()) {
fprintf(stderr, "directory checksum error\n");
done(2);
}
if (tfile != NULL)
fprintf(tfile, "%s %s\n", dblock.dbuf.name, dblock.dbuf.mtime);
}
passtape()
{
long blocks;
char buf[TBLOCK];
if (dblock.dbuf.linkflag == '1')
return;
blocks = stbuf.st_size;
blocks += TBLOCK-1;
blocks /= TBLOCK;
while (blocks-- > 0)
readtape(buf);
}
putfile(longname, shortname)
char *longname;
char *shortname;
{
int infile;
long blocks;
char buf[TBLOCK];
register char *cp, *cp2;
struct direct dbuf;
int i, j;
infile = open(shortname, 0);
if (infile < 0) {
fprintf(stderr, "tar: %s: cannot open file\n", longname);
return;
}
fstat(infile, &stbuf);
if (tfile != NULL && checkupdate(longname) == 0) {
close(infile);
return;
}
if (checkw('r', longname) == 0) {
close(infile);
return;
}
if ((stbuf.st_mode & S_IFMT) == S_IFDIR) {
for (i = 0, cp = buf; *cp++ = longname[i++];);
*--cp = '/';
*++cp = 0 ;
i = 0;
if (!oflag) {
if( (cp - buf) >= NAMSIZ) {
fprintf(stderr, "%s: file name too long\n", longname);
close(infile);
return;
}
stbuf.st_size = 0;
tomodes(&stbuf);
strcpy(dblock.dbuf.name,buf);
sprintf(dblock.dbuf.chksum, "%6o", checksum());
writetape( (char *) &dblock);
}
chdir(shortname);
while (read(infile, (char *)&dbuf, sizeof(dbuf)) > 0 && !term) {
if (dbuf.d_ino == 0) {
i++;
continue;
}
if (strcmp(".", dbuf.d_name) == 0 || strcmp("..", dbuf.d_name) == 0) {
i++;
continue;
}
cp2 = cp;
for (j=0; j < DIRSIZ; j++)
*cp2++ = dbuf.d_name[j];
*cp2 = '\0';
close(infile);
putfile(buf, cp);
infile = open(".", 0);
i++;
lseek(infile, (long) (sizeof(dbuf) * i), 0);
}
close(infile);
chdir("..");
return;
}
if ((stbuf.st_mode & S_IFMT) != S_IFREG) {
fprintf(stderr, "tar: %s is not a file. Not dumped\n", longname);
return;
}
tomodes(&stbuf);
cp2 = longname;
for (cp = dblock.dbuf.name, i=0; (*cp++ = *cp2++) && i < NAMSIZ; i++);
if (i >= NAMSIZ) {
fprintf(stderr, "%s: file name too long\n", longname);
close(infile);
return;
}
if (stbuf.st_nlink > 1) {
struct linkbuf *lp;
int found = 0;
for (lp = ihead; lp != NULL; lp = lp->nextp) {
if (lp->inum == stbuf.st_ino && lp->devnum == stbuf.st_dev) {
found++;
break;
}
}
if (found) {
strcpy(dblock.dbuf.linkname, lp->pathname);
dblock.dbuf.linkflag = '1';
sprintf(dblock.dbuf.chksum, "%6o", checksum());
writetape( (char *) &dblock);
if (vflag) {
fprintf(stderr, "a %s ", longname);
fprintf(stderr, "link to %s\n", lp->pathname);
}
lp->count--;
close(infile);
return;
}
else {
lp = (struct linkbuf *) malloc(sizeof(*lp));
if (lp == NULL) {
if (freemem) {
fprintf(stderr, "Out of memory. Link information lost\n");
freemem = 0;
}
}
else {
lp->nextp = ihead;
ihead = lp;
lp->inum = stbuf.st_ino;
lp->devnum = stbuf.st_dev;
lp->count = stbuf.st_nlink - 1;
strcpy(lp->pathname, longname);
}
}
}
blocks = (stbuf.st_size + (TBLOCK-1)) / TBLOCK;
if (vflag) {
fprintf(stderr, "a %s ", longname);
fprintf(stderr, "%ld blocks\n", blocks);
}
sprintf(dblock.dbuf.chksum, "%6o", checksum());
writetape( (char *) &dblock);
while ((i = read(infile, buf, TBLOCK)) > 0 && blocks > 0) {
writetape(buf);
blocks--;
}
close(infile);
if (blocks != 0 || i != 0)
fprintf(stderr, "%s: file changed size\n", longname);
while (blocks-- > 0)
putempty();
}
doxtract(argv)
char *argv[];
{
long blocks, bytes;
char buf[TBLOCK];
char **cp;
int ofile;
for (;;) {
getdir();
if (endtape())
break;
if (*argv == 0)
goto gotit;
for (cp = argv; *cp; cp++)
if (prefix(*cp, dblock.dbuf.name))
goto gotit;
passtape();
continue;
gotit:
if (checkw('x', dblock.dbuf.name) == 0) {
passtape();
continue;
}
if(checkdir(dblock.dbuf.name))
continue;
if (dblock.dbuf.linkflag == '1') {
unlink(dblock.dbuf.name);
if (link(dblock.dbuf.linkname, dblock.dbuf.name) < 0) {
fprintf(stderr, "%s: cannot link\n", dblock.dbuf.name);
continue;
}
if (vflag)
fprintf(stderr, "%s linked to %s\n",
dblock.dbuf.name, dblock.dbuf.linkname);
continue;
}
if ((ofile = creat(dblock.dbuf.name, stbuf.st_mode & 07777)) < 0) {
fprintf(stderr, "tar: %s - cannot create\n", dblock.dbuf.name);
passtape();
continue;
}
chown(dblock.dbuf.name, stbuf.st_uid, stbuf.st_gid);
blocks = ((bytes = stbuf.st_size) + TBLOCK-1)/TBLOCK;
if (vflag)
fprintf(stderr, "x %s, %ld bytes, %ld tape blocks\n",
dblock.dbuf.name, bytes, blocks);
while (blocks-- > 0) {
readtape(buf);
if (bytes > TBLOCK) {
if (write(ofile, buf, TBLOCK) < 0) {
fprintf(stderr, "tar: %s: HELP - extract write error\n", dblock.dbuf.name);
done(2);
}
} else
if (write(ofile, buf, (int) bytes) < 0) {
fprintf(stderr, "tar: %s: HELP - extract write error\n", dblock.dbuf.name);
done(2);
}
bytes -= TBLOCK;
}
close(ofile);
if (mflag == 0) {
time_t timep[2];
timep[0] = time(NULL);
timep[1] = stbuf.st_mtime;
utime(dblock.dbuf.name, timep);
}
if (pflag)
chmod(dblock.dbuf.name, stbuf.st_mode & 07777);
}
}
dotable()
{
for (;;) {
getdir();
if (endtape())
break;
if (vflag)
longt(&stbuf);
printf("%s", dblock.dbuf.name);
if (dblock.dbuf.linkflag == '1')
printf(" linked to %s", dblock.dbuf.linkname);
printf("\n");
passtape();
}
}
putempty()
{
char buf[TBLOCK];
char *cp;
for (cp = buf; cp < &buf[TBLOCK]; )
*cp++ = '\0';
writetape(buf);
}
longt(st)
register struct stat *st;
{
register char *cp;
char *ctime();
pmode(st);
printf("%3d/%1d", st->st_uid, st->st_gid);
printf("%7D", st->st_size);
cp = ctime(&st->st_mtime);
printf(" %-12.12s %-4.4s ", cp+4, cp+20);
}
#define SUID 04000
#define SGID 02000
#define ROWN 0400
#define WOWN 0200
#define XOWN 0100
#define RGRP 040
#define WGRP 020
#define XGRP 010
#define ROTH 04
#define WOTH 02
#define XOTH 01
#define STXT 01000
int m1[] = { 1, ROWN, 'r', '-' };
int m2[] = { 1, WOWN, 'w', '-' };
int m3[] = { 2, SUID, 's', XOWN, 'x', '-' };
int m4[] = { 1, RGRP, 'r', '-' };
int m5[] = { 1, WGRP, 'w', '-' };
int m6[] = { 2, SGID, 's', XGRP, 'x', '-' };
int m7[] = { 1, ROTH, 'r', '-' };
int m8[] = { 1, WOTH, 'w', '-' };
int m9[] = { 2, STXT, 't', XOTH, 'x', '-' };
int *m[] = { m1, m2, m3, m4, m5, m6, m7, m8, m9};
pmode(st)
register struct stat *st;
{
register int **mp;
for (mp = &m[0]; mp < &m[9];)
select(*mp++, st);
}
select(pairp, st)
int *pairp;
struct stat *st;
{
register int n, *ap;
ap = pairp;
n = *ap++;
while (--n>=0 && (st->st_mode&*ap++)==0)
ap++;
printf("%c", *ap);
}
checkdir(name)
register char *name;
{
register char *cp;
int i;
for (cp = name; *cp; cp++) {
if (*cp == '/') {
*cp = '\0';
if (access(name, 01) < 0) {
register int pid, rp;
if ((pid = fork()) == 0) {
execl("/bin/mkdir", "mkdir", name, 0);
execl("/usr/bin/mkdir", "mkdir", name, 0);
fprintf(stderr, "tar: cannot find mkdir!\n");
done(0);
}
while ((rp = wait(&i)) >= 0 && rp != pid)
;
chown(name, stbuf.st_uid, stbuf.st_gid);
if (pflag)
chmod(dblock.dbuf.name,
stbuf.st_mode & 0777);
}
*cp = '/';
}
}
return(cp[-1]=='/');
}
onintr()
{
signal(SIGINT, SIG_IGN);
term++;
}
onquit()
{
signal(SIGQUIT, SIG_IGN);
term++;
}
onhup()
{
signal(SIGHUP, SIG_IGN);
term++;
}
onterm()
{
signal(SIGTERM, SIG_IGN);
term++;
}
tomodes(sp)
register struct stat *sp;
{
register char *cp;
for (cp = dblock.dummy; cp < &dblock.dummy[TBLOCK]; cp++)
*cp = '\0';
sprintf(dblock.dbuf.mode, "%6o ", sp->st_mode & 07777);
sprintf(dblock.dbuf.uid, "%6o ", sp->st_uid);
sprintf(dblock.dbuf.gid, "%6o ", sp->st_gid);
sprintf(dblock.dbuf.size, "%11lo ", sp->st_size);
sprintf(dblock.dbuf.mtime, "%11lo ", sp->st_mtime);
}
checksum()
{
register i;
register char *cp;
for (cp = dblock.dbuf.chksum; cp < &dblock.dbuf.chksum[sizeof(dblock.dbuf.chksum)]; cp++)
*cp = ' ';
i = 0;
for (cp = dblock.dummy; cp < &dblock.dummy[TBLOCK]; cp++)
i += *cp;
return(i);
}
checkw(c, name)
char *name;
{
if (wflag) {
printf("%c ", c);
if (vflag)
longt(&stbuf);
printf("%s: ", name);
if (response() == 'y'){
return(1);
}
return(0);
}
return(1);
}
response()
{
char c;
c = getchar();
if (c != '\n')
while (getchar() != '\n');
else c = 'n';
return(c);
}
checkupdate(arg)
char *arg;
{
char name[100];
long mtime;
daddr_t seekp;
daddr_t lookup();
rewind(tfile);
for (;;) {
if ((seekp = lookup(arg)) < 0)
return(1);
fseek(tfile, seekp, 0);
fscanf(tfile, "%s %lo", name, &mtime);
if (stbuf.st_mtime > mtime)
return(1);
else
return(0);
}
}
done(n)
{
unlink(tname);
exit(n);
}
prefix(s1, s2)
register char *s1, *s2;
{
while (*s1)
if (*s1++ != *s2++)
return(0);
if (*s2)
return(*s2 == '/');
return(1);
}
getwdir(s)
char *s;
{
int i;
int pipdes[2];
pipe(pipdes);
if ((i = fork()) == 0) {
close(1);
dup(pipdes[1]);
execl("/bin/pwd", "pwd", 0);
execl("/usr/bin/pwd", "pwd", 0);
fprintf(stderr, "pwd failed!\n");
printf("/\n");
exit(1);
}
while (wait((int *)NULL) != -1)
;
read(pipdes[0], s, 50);
while(*s != '\n')
s++;
*s = '\0';
close(pipdes[0]);
close(pipdes[1]);
}
#define N 200
int njab;
daddr_t
lookup(s)
char *s;
{
register i;
daddr_t a;
for(i=0; s[i]; i++)
if(s[i] == ' ')
break;
a = bsrch(s, i, low, high);
return(a);
}
daddr_t
bsrch(s, n, l, h)
daddr_t l, h;
char *s;
{
register i, j;
char b[N];
daddr_t m, m1;
njab = 0;
loop:
if(l >= h)
return(-1L);
m = l + (h-l)/2 - N/2;
if(m < l)
m = l;
fseek(tfile, m, 0);
fread(b, 1, N, tfile);
njab++;
for(i=0; i<N; i++) {
if(b[i] == '\n')
break;
m++;
}
if(m >= h)
return(-1L);
m1 = m;
j = i;
for(i++; i<N; i++) {
m1++;
if(b[i] == '\n')
break;
}
i = cmp(b+j, s, n);
if(i < 0) {
h = m;
goto loop;
}
if(i > 0) {
l = m1;
goto loop;
}
return(m);
}
cmp(b, s, n)
char *b, *s;
{
register i;
if(b[0] != '\n')
exit(2);
for(i=0; i<n; i++) {
if(b[i+1] > s[i])
return(-1);
if(b[i+1] < s[i])
return(1);
}
return(b[i+1] == ' '? 0 : -1);
}
readtape(buffer)
char *buffer;
{
register int i;
if (recno >= nblock || first == 0) {
if ((i = read(mt, tbuf, TBLOCK*nblock)) < 0) {
fprintf(stderr, "Tar: tape read error\n");
done(3);
}
if (first == 0) {
if ((i % TBLOCK) != 0) {
fprintf(stderr, "Tar: tape blocksize error\n");
done(3);
}
i /= TBLOCK;
if (i != nblock) {
fprintf(stderr, "Tar: blocksize = %d\n", i);
nblock = i;
}
}
recno = 0;
}
first = 1;
copy(buffer, &tbuf[recno++]);
return(TBLOCK);
}
writetape(buffer)
char *buffer;
{
first = 1;
if (recno >= nblock) {
if (write(mt, tbuf, TBLOCK*nblock) < 0) {
fprintf(stderr, "Tar: tape write error\n");
done(2);
}
recno = 0;
}
copy(&tbuf[recno++], buffer);
if (recno >= nblock) {
if (write(mt, tbuf, TBLOCK*nblock) < 0) {
fprintf(stderr, "Tar: tape write error\n");
done(2);
}
recno = 0;
}
return(TBLOCK);
}
backtape()
{
static int mtdev = 1;
static struct mtop mtop = {MTBSR, 1};
struct mtget mtget;
if (mtdev == 1)
mtdev = ioctl(mt, MTIOCGET, &mtget);
if (mtdev == 0) {
if (ioctl(mt, MTIOCTOP, &mtop) < 0) {
fprintf(stderr, "Tar: tape backspace error\n");
done(4);
}
} else
lseek(mt, (long) -TBLOCK*nblock, 1);
recno--;
}
flushtape()
{
write(mt, tbuf, TBLOCK*nblock);
}
copy(to, from)
register char *to, *from;
{
register i;
i = TBLOCK;
do {
*to++ = *from++;
} while (--i);
}

View File

@@ -0,0 +1,85 @@
/* c-version of tp?.s
*
* M. Ferentz
* August 1976
*
* revised July 1977 BTL
*/
#define MDIRENT 496 /* must be zero mod 8 */
#define DIRSZ sizeof(struct dent)
#define MAPSIZE 4096
#define MAPMASK 07777
#define NAMELEN 32
#define BSIZE 512
#define TCSIZ 578
#define TCDIRS 192
#define MTSIZ 32767
#define TPB (BSIZE/sizeof(struct tent))
#define OK 0100000
#define BRKINCR 512
#define tapeblk &tpentry[0]
#define tapeb &tpentry[0]
struct tent { /* Structure of a tape directory block */
char pathnam[NAMELEN];
short mode;
char uid;
char gid;
char spare;
char size0;
unsigned short size1;
long time;
unsigned short tapea; /* tape address */
short unused[8];
short cksum;
} tpentry[TPB];
struct dent { /* in core version of tent with "unused" removed
* and pathname replaced by pointer to same in a
* packed area (nameblock).
*/
char *d_namep;
int d_mode;
int d_uid;
int d_gid;
long d_size;
long d_time;
int d_tapea;
} dir[MDIRENT];
char map[MAPSIZE];
char name[NAMELEN];
char name1[NAMELEN];
extern char mt[];
extern char tc[];
char *tname;
extern char mheader[];
extern char theader[];
int narg, rnarg;
char **parg;
int wseeka,rseeka;
int tapsiz;
int fio;
short ndirent, ndentb;
struct dent *edir;
struct dent *lastd; /* for improvement */
char *sbrk();
char *strcpy();
long lseek();
int (*command)();
char *nameblk;
char *top;
char *nptr;
extern int flags;
#define flc 0001
#define fli 0004
#define flm 0010
#define flu 0020
#define flv 0040
#define flw 0100
#define fls 0200

View File

@@ -0,0 +1,2 @@
#include "tp.h"
#include "tp_defs.h"

View File

@@ -0,0 +1,197 @@
#include "tp.h"
main(argc,argv)
char **argv;
{
register char c,*ptr;
extern cmd(), cmr(),cmx(), cmt();
tname = tc;
command = cmr;
if ((narg = rnarg = argc) < 2) narg = 2;
else {
ptr = argv[1]; /* get first argument */
parg = &argv[2]; /* pointer to second argument */
while (c = *ptr++) switch(c) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
tc[8] = c;
mt[8] = c;
continue;
case 'f':
tname = *parg++;
flags |= flm;
narg--; rnarg--;
continue;
case 'c':
flags |= flc; continue;
case 'd':
setcom(cmd); continue;
case 'i':
flags |= fli; continue;
case 'm':
tname = mt;
flags |= flm;
continue;
case 'r':
flags &= ~flu; setcom(cmr); continue;
case 's':
flags |= fls; continue;
case 't':
setcom(cmt); continue;
case 'u':
flags |= flu; setcom(cmr); continue;
case 'v':
flags |= flv; continue;
case 'w':
flags |= flw; continue;
case 'x':
setcom(cmx); continue;
default:
useerr();
}
}
optap();
top = nptr = nameblk = sbrk(0);
(*command)();
}
optap()
{
extern cmr();
if ((flags & flm) == 0) { /* DECTAPE */
tapsiz = TCSIZ;
ndirent = TCDIRS;
fio =open(tc,2);
} else { /* MAGTAPE */
tapsiz = MTSIZ;
ndirent = MDIRENT;
if(command == cmr) {
fio = open(tname,1);
if (fio < 0) fio = creat(tname,0666);
} else
fio = open(tname,0);
}
if (fio < 0) {
printf("Tape open error\n");
done();
}
ndentb = ndirent/TPB;
edir = &dir[ndirent];
}
setcom(newcom)
int (*newcom)();
{
extern cmr();
if (command != cmr) useerr();
command = newcom;
}
useerr()
{
printf("Bad usage\n");
done();
}
/* /* COMMANDS */
cmd()
{
extern delete();
if (flags & (flm|flc)) useerr();
if (narg <= 2) useerr();
rddir();
gettape(delete);
wrdir();
check();
}
cmr()
{
if (flags & (flc|flm)) clrdir();
else rddir();
getfiles();
update();
check();
}
cmt()
{
extern taboc();
if (flags & (flc|flw)) useerr();
rddir();
if (flags & flv)
printf(" mode uid gid tapa size date time name\n");
gettape(taboc);
check();
}
cmx()
{
extern extract();
if (flags & (flc)) useerr();
rddir();
gettape(extract);
done();
}
check()
{
usage();
done();
}
done()
{
printf("End\n");
exit(0);
}
encode(pname,dptr) /* pname points to the pathname
* nptr points to next location in nameblk
* dptr points to the dir entry */
char *pname;
struct dent *dptr;
{
register char *np;
register n;
dptr->d_namep = np = nptr;
if (np > top - NAMELEN) {
if(sbrk(BRKINCR) == (char *)-1) {
printf("Out of core\n");
done();
} else
top += BRKINCR;
}
if((n=strlen(pname)) > NAMELEN) {
printf("Pathname too long - %s\nFile ignored\n",pname);
clrent(dptr);
}
else {
nptr += n+1;
strcpy(np, pname);
}
}
decode(pname,dptr) /* dptr points to the dir entry
* name is placed in pname[] */
char *pname;
struct dent *dptr;
{
strcpy(pname, dptr->d_namep);
}

View File

@@ -0,0 +1,348 @@
#include "tp.h"
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/dir.h>
struct direct direct;
struct stat statb;
clrdir()
{
register j, *p;
j = ndirent * (DIRSZ/sizeof(int));
p = (int *)dir;
do (*p++ = 0); while (--j);
lastd = 0;
}
clrent(ptr)
struct dent *ptr;
{
register *p, j;
p = (int *)ptr;
j = DIRSZ/sizeof(int);
do *p++ = 0;
while (--j);
if (++ptr == lastd) do {
if (--lastd < dir) {
lastd = 0;
return;
}
} while (lastd->d_namep == 0);
}
rddir()
{
register struct tent *tp;
register struct dent *p1;
struct dent *dptr;
struct tent *tptr;
int count, i, sum;
short reg, *sp;
sum = 0;
clrdir();
rseek(0);
tread(); /* Read the bootstrap block */
if ((tpentry[TPB-1].cksum != 0) && (flags & flm)) {
ndirent = tpentry[TPB-1].cksum;
if(flags & fls) swab((char *)&ndirent, (char *)&ndirent, sizeof(ndirent));
if(ndirent < 0 || ndirent > MDIRENT) ndirent = MDIRENT;
ndentb = ndirent/TPB;
}
dptr = &dir[0];
count = ndirent;
do {
if ((count % TPB) == 0) { /* next block */
tread();
tptr = &tpentry[0];
}
if(flags & fls)
swab((char *)tptr, (char *)tptr, sizeof(*tptr));
sp = (short *)tptr;
reg = 0;
for(i=0;i<sizeof(struct tent)/sizeof(short);i++)
reg += *sp++;
if(flags & fls) {
swab((char *)tptr, (char *)tptr, sizeof(*tptr));
swabdir(tptr);
}
sum |= reg;
p1 = dptr;
if (reg == 0) {
tp = tptr;
if(tp->pathnam[0] != '\0') {
lastd = p1;
encode(tp->pathnam,p1);
p1->d_mode = tp->mode;
p1->d_uid = tp->uid;
p1->d_gid = tp->gid;
p1->d_size = (((long)tp->size0&0377L)<<16)+(tp->size1&0177777L);
p1->d_time = tp->time;
p1->d_tapea = tp->tapea;
}
}
++tptr; /* bump to next tent */
(dptr++)->d_mode &= ~OK;
} while (--count);
if(sum != 0)
if(flags & (fls|fli)) {
printf("Directory checksum\n");
if ((flags & fli) == 0) done();
} else {
flags |= fls;
rddir();
printf("Warning: swabbing required\n");
return;
}
bitmap();
}
wrdir()
{
register struct tent *tp;
register struct dent *dp;
struct dent *dptr;
int count, i;
short reg, *sp;
wseek(0);
if (flags & flm)
reg = open(mheader,0);
else reg = open(theader,0);
if (reg >= 0) {
read(reg,(char *)tapeb,BSIZE);
close(reg);
if(flags & fls)
swab((char *)&ndirent, (char *)&tpentry[TPB-1].cksum, sizeof(ndirent));
else
tpentry[TPB-1].cksum = ndirent;
} else
printf("\7\7\7Warning: cannot read prototype boot block.\n");
dptr = &dir[0];
count = ndirent;
for (;;) {
twrite();
if (count == 0) return;
tp = &tpentry[0];
do {
dp = dptr++; /* dptr set to next entry */
if (dp->d_namep) {
decode(tp->pathnam,dp);
tp->mode = dp->d_mode;
tp->uid = dp->d_uid;
tp->gid = dp->d_gid;
tp->time = dp->d_time;
tp->size0 = dp->d_size >> 16;
tp->size1 = dp->d_size;
tp->tapea = dp->d_tapea;
if(flags & fls) {
swabdir(tp);
swab((char *)tp, (char *)tp, sizeof(*tp));
}
reg = 0;
sp = (short *)tp;
for(i=0;i<sizeof(struct tent)/sizeof(short)-1;i++)
reg -= *sp++;
*sp = reg;
if(flags & fls)
swab((char *)tp, (char *)tp, sizeof(*tp));
} else {
sp = (short *)tp;
for(i=0;i<sizeof(struct tent)/sizeof(short);i++)
*sp++ = 0;
}
tp++;
} while (--count % TPB);
}
}
tread()
{
register j, *ptr;
if (read(fio,(char *)tapeb,BSIZE) != BSIZE) {
printf("Tape read error\n");
if ((flags & fli) == 0) done();
ptr = (int *)tapeb;
j = BSIZE/sizeof(int);
while(j--) *ptr++ = 0;
}
rseeka++;
}
twrite()
{
if (write(fio, (char *)tapeb,BSIZE) != BSIZE) {
printf("Tape write error\n");
done();
}
++wseeka;
}
rseek(blk)
{
rseeka = blk;
if (lseek(fio,(long)blk*BSIZE,0) < 0) seekerr();
}
wseek(blk)
{
register amt, b;
amt = b = blk;
if ((amt -= wseeka) < 0) amt = -amt;
if (amt > 25 && b) {
lseek(fio, (long)(b-1)*BSIZE, 0); /* seek previous block */
read(fio, (char *)&wseeka, 1); /* read next block */
}
wseeka = b;
if (lseek(fio, (long)b*BSIZE, 0) < 0) seekerr();
}
seekerr()
{
printf("Tape seek error\n");
done();
}
verify(key)
{
register c;
if ((flags & (flw | flv)) == 0)
return(0);
repeat: printf("%c %s ", key, name);
if ((flags & flw) == 0) {
printf("\n");
return(0);
}
c = getchar();
if (c == 'n' && getchar() == '\n')
done();
if (c == '\n')
return(-1);
if (c == 'y' && getchar() == '\n')
return(0);
while (getchar() != '\n');
goto repeat;
}
getfiles()
{
if ((narg -= 2) == 0) {
strcpy(name, ".");
callout();
} else while (--narg >= 0) {
strcpy(name, *parg++);
callout();
}
}
expand()
{
register char *p0, *save0;
int n, fid;
if ((fid = open(name,0)) < 0) fserr();
for (;;) {
if ((n = read(fid, (char *)&direct, sizeof(direct))) != sizeof(direct)) {
if (n == 0) {
close(fid);
return;
}
fserr();
}
if (direct.d_ino == 0) /* null entry */
continue;
p0 = name;
if (direct.d_name[0] == '.') /* don't save .xxxx */
continue;
while (*p0++);
save0 = --p0; /* save loc of \0 */
if (p0[-1] != '/')
*p0++ = '/';
strcpy(p0, direct.d_name);
callout();
*save0 = 0; /* restore */
}
}
fserr()
{
printf("%s -- Cannot open file\n", name);
done();
}
callout()
{
register struct dent *d;
register char *ptr1, *ptr0;
struct dent *empty;
int mode;
if (stat(name,&statb) < 0) fserr();
mode = statb.st_mode;
if ((mode &= S_IFMT) != 0) {
if (mode == S_IFDIR) /* directory */
expand();
if(mode != S_IFREG) return;
}
/* when we reach here we have recursed until we found
* an ordinary file. Now we look for it in "dir".
*/
empty = 0;
d = &dir[0];
do {
if (d->d_namep == 0) { /* empty directory slot */
if (empty == 0) /* remember the first one */
empty = d;
continue;
}
decode(name1,d);
ptr0 = name;
ptr1 = name1;
do if (*ptr0++ != *ptr1) goto cont;
while (*ptr1++);
/* veritably the same name */
if (flags & flu) { /* check the times */
if (d->d_time >= statb.st_mtime)
return;
}
if (verify('r') < 0) return;
goto copydir;
cont: continue;
} while (++d <= lastd);
/* name not found in directory */
if ((d = empty) == 0) {
d = lastd +1;
if (d >= edir) {
printf("Directory overflow\n");
done();
}
}
if (verify('a') < 0) return;
if (d > lastd) lastd = d;
encode(name,d);
copydir:
d->d_mode = statb.st_mode | OK;
d->d_uid = statb.st_uid;
d->d_gid = statb.st_gid;
d->d_size = statb.st_size;
d->d_time = statb.st_mtime;
}
swabdir(tp)
register struct tent *tp;
{
swab((char *)tp, (char *)tp, sizeof(*tp));
swab(tp->pathnam, tp->pathnam, NAMELEN);
swab((char *)&tp->uid, (char *)&tp->uid, 4); /* uid,gid,spare,size0 */
}

View File

@@ -0,0 +1,248 @@
#include "tp.h"
gettape(how)
int (*how)();
{
register char *ptr0, *ptr1;
register struct dent *d;
int count;
do {
d = &dir[0];
count = 0;
do {
if (d->d_namep == 0) continue;
decode(name,d);
if (rnarg > 2) {
ptr0 = name;
ptr1 = *parg;
while (*ptr1)
if (*ptr0++ != *ptr1++) goto cont;
if (*ptr0 && *ptr0 != '/') goto cont;
}
(*how)(d); /* delete, extract, or taboc */
++count;
cont: continue;
} while (++d <= lastd);
if (count == 0 && rnarg > 2)
printf("%s not found\n", *parg);
++parg;
} while (--narg > 2);
}
delete(dd)
struct dent *dd;
{
if (verify('d') >= 0)
clrent(dd);
}
update()
{
register struct dent *d;
register b, last;
int first, size;
bitmap();
d = &dir[0];
do {
if(d->d_namep == 0 || (d->d_mode&OK) == 0) continue;
if (d->d_size == 0) continue;
/* find a place on the tape for this file */
size = (d->d_size+BSIZE-1)/BSIZE;
first = ndentb;
toosmall: ++first;
if ((last = first + size) >= tapsiz) maperr();
for (b = first; b < last; ++b)
if (map[(b>>3) & MAPMASK] & (1<<(b&7))) {
first = b;
goto toosmall;
};
d->d_tapea = first;
setmap(d);
} while (++d <= lastd);
wrdir();
update1();
}
update1()
{
register struct dent *d, *id;
register index;
int f;
for (;;) {
d = &dir[0];
index = MTSIZ;
id = 0;
do { /* find new dent with lowest tape address */
if(d->d_namep == 0 || (d->d_mode&OK) == 0) continue;
if (d->d_tapea < index) {
index = d->d_tapea;
id = d;
}
} while (++d <= lastd);
if ((d = id) == 0) return;
d->d_mode &= ~OK; /* change from new to old */
if (d->d_size == 0) continue;
decode(name,d);
wseek(index);
if ((f = open(name,0)) < 0) {
printf("Can't open %s\n", name);
continue;
}
for (index = d->d_size/BSIZE; index != 0; --index) {
if (read(f,(char *)tapeb,BSIZE) != BSIZE) phserr();
twrite();
}
if (index = d->d_size % BSIZE) {
if (read(f,(char *)tapeb,index) != index) phserr();
twrite();
}
if (read(f,(char *)tapeb,1) != 0) phserr();
close(f);
}
}
phserr()
{ printf("%s -- Phase error \n", name); }
bitmap() /* place old files in the map */
{
register char *m;
register count;
register struct dent *d;
for(m=map;m<&map[MAPSIZE];) *m++ = 0;
count = ndirent;
d = dir;
do {
if(d->d_namep != 0 && (d->d_mode&OK) == 0
&& d->d_size != 0) setmap(d);
d++;
} while (--count);
}
setmap(d)
register struct dent *d;
{
unsigned c, block;
char bit;
int i;
c = d->d_size/BSIZE;
if (d->d_size % BSIZE) c++;
block = d->d_tapea;
if ((c += block) >= tapsiz) maperr();
do {
bit = 1 << (block & 7);
i = (block>>3) & MAPMASK;
if (bit & map[i]) maperr();
map[i] |= bit;
} while (++block < c);
}
maperr()
{
printf("Tape overflow\n");
done();
}
usage()
{
register reg,count;
int nused, nentr, nfree;
static lused;
bitmap();
for(count=0,nentr=0;count<ndirent;count++)
if(dir[count].d_namep != 0) nentr++;
nused = nfree = 0;
reg = ndentb;
++reg; /* address of first non-directory tape block */
count = tapsiz - reg;
do {
if (reg >= tapsiz) {
printf("Tape overflow\n");
done();
}
if (map[(reg>>3) & MAPMASK] & (1 << (reg&7))) {
nused++;
lused = reg;
} else {
if (flags & flm) break;
nfree++;
}
reg++;
} while (--count);
printf("%4d entries\n%4d used\n", nentr, nused);
if ((flags & flm)==0)
printf("%4d free\n", nfree);
printf("%4d last\n", lused);
}
taboc(dd)
struct dent *dd;
{
register mode;
register *m;
register char *s;
int count, *localtime();
char work[20];
if (flags & flv) {
mode = dd->d_mode;
s = &work[19];
*s = 0;
for (count = 3; count; --count) {
if (mode&1) *--s = 'x';
else *--s = '-';
if (mode&2) *--s = 'w';
else *--s = '-';
if (mode&4) *--s = 'r';
else *--s = '-';
mode >>= 3;
}
if (mode&4) s[2] = 's';
if (mode&2) s[5] = 's';
printf("%s%4d%4d%5d%9D ",s,dd->d_uid, dd->d_gid,dd->d_tapea,dd->d_size);
m = localtime(&dd->d_time);
printf("%2d/%2d/%2d %2d:%2d ",m[5],m[4]+1,m[3],m[2],m[1]);
}
printf("%s\n", name);
}
extract(d)
register struct dent *d;
{
register count, id;
if (d->d_size==0) return;
if (verify('x') < 0) return;
rseek(d->d_tapea);
unlink(name);
if ((id = creat(name,d->d_mode)) < 0)
printf("%s -- create error\n", name);
count = d->d_size/BSIZE;
while (count--) {
tread();
if (write(id, (char *)tapeb, BSIZE) != BSIZE) goto ng;
}
if (count = d->d_size % BSIZE) {
tread();
if (write(id, (char *)tapeb, count) != count) {
ng: printf("%s -- write error\n", name);
close(id);
return;
}
}
close(id);
chown(name,d->d_uid & 0377, d->d_gid&0377);
}

View File

@@ -0,0 +1,5 @@
char mt[] = "/dev/rmt0";
char tc[] = "/dev/tapx";
int flags = flu;
char mheader[] = "/usr/mdec/mboot";
char theader[] = "/usr/mdec/tboot";

View File

@@ -0,0 +1,14 @@
# include "iodec.h"
/**
** put a single character
**/
int f_log 0;
cputc(c, fn)
char c;
int fn;
{
write(fn,&c,1);
}

View File

@@ -0,0 +1,26 @@
/****************************************************************************
*
* C F I L E C R E A T E R O U T I N E
* -----------------------------------------
*
* The "creat" routine opens a new "C" file and returns a file id.
*
* Calling Sequence:
*
* fid = creat(fname,prot,type);
*
* Where:
*
* fname is the address of a null terminated file name.
* prot is the UNIX file protection
* type is 0 for ASCII, 1 for BINARY
*
*****************************************************************************/
#include <portab.h>
WORD xcreat(fname,prot,type) /****************************/
BYTE *fname; /* -> File name */
WORD prot; /* Open mode */
WORD type; /* ASCII/BINARY flag */
{ /****************************/
return(_creat(fname,prot,type)); /* Call clib routine */
} /****************************/

View File

@@ -0,0 +1,9 @@
/*
* El-Kludg-o Dup routine. Takes advantage of the fact that
* stdout is not closed by Bill Allen's stuff.
*/
dup(n)
register int n;
{
return(n);
}

View File

@@ -0,0 +1,52 @@
#define BLEN 512
#include <klib.h>
struct iob {
int fd; /*file descriptor*/
int cc; /*char count*/
char *cp; /*ptr to next char*/
char cbuf[BLEN]; /*char buffer*/
};
fopen(fname,ibuf,x)
char *fname;
register struct iob *ibuf;
int x;
{
ibuf->cc = 0; /*no chars*/
x = (x == 0) ? 0 : 1;
return(ibuf->fd=open(fname,0,x));
}
getc(ibuf)
register struct iob *ibuf;
{
if(ibuf->cc<=0) {
ibuf->cp = &(ibuf->cbuf[0]);
ibuf->cc = read(ibuf->fd,ibuf->cp,BLEN);
}
if(ibuf->cc <= 0) {
return(-1);
}
ibuf->cc--;
return((int)(*(ibuf->cp)++)&0xff);
}
getw(ibuf)
register struct iob *ibuf;
{
register int j;
register int i;
if((j=getc(ibuf)) == -1)
return(-1);
i = (j&0377) << 8;
if((j=getc(ibuf)) == -1)
return(-1);
i =| (j&0377);
if(i&0100000)
i =| 0xffff0000; /* make it negative */
return(i);
}

View File

@@ -0,0 +1,31 @@
#define BLEN 512
#include <klib.h>
struct iob {
int fd; /*file descriptor*/
int cc; /*char count*/
char *cp; /*ptr to next char*/
char cbuf[BLEN]; /*char buffer*/
} fin;
getchar()
{
char c;
register int i;
if(fin.fd==0) {
if(read(0,&c,1)<=0 || c==4)
return(0);
i = c;
return(i&0xff);
}
if(fin.cc<=0) {
fin.cp = &(fin.cbuf[0]);
fin.cc = read(fin.fd,fin.cp,BLEN);
}
if(fin.cc <= 0) {
return(0);
}
fin.cc--;
i = *(fin.cp)++;
return(i&0xff);
}

View File

@@ -0,0 +1,52 @@
#define BLEN 512
#include <klib.h>
struct iob {
int fd; /*file descriptor*/
int cc; /*char count*/
char *cp; /*ptr to next char*/
char cbuf[BLEN]; /*char buffer*/
};
fopen(fname,ibuf,x)
char *fname;
register struct iob *ibuf;
int x;
{
ibuf->cc = 0; /*no chars*/
x = (x == 0) ? 0 : 1;
return(ibuf->fd=open(fname,0,x));
}
getc(ibuf)
register struct iob *ibuf;
{
if(ibuf->cc<=0) {
ibuf->cp = &(ibuf->cbuf[0]);
ibuf->cc = read(ibuf->fd,ibuf->cp,BLEN);
}
if(ibuf->cc <= 0) {
return(-1);
}
ibuf->cc--;
return((int)(*(ibuf->cp)++)&0xff);
}
getw(ibuf)
register struct iob *ibuf;
{
register int j;
register int i;
if((j=getc(ibuf)) == -1)
return(-1);
i = (j&0377);
if((j=getc(ibuf)) == -1)
return(-1);
i =| (j&0377) << 8;
if(i&0100000)
i =| 0xffff0000; /* make it negative */
return(i);
}

View File

@@ -0,0 +1,24 @@
# define MAXFILES 15
struct fileps
{
char *buff; /* beginning of buffer */
char *bptr; /* current position */
int nchars; /* number of characters internal */
int bsize; /* size of buffer */
char eoferr; /* end of file flag */
char wrflag; /* mode flag */
char *pbuff; /* bottom of peek buffer */
};
struct fileps __filehdr[MAXFILES];
struct param
{
int bufsize; /* initial buffer size */
int peeksize; /* initial peek size */
};
extern struct param __param;
int __statbuf[MAXFILES];

View File

@@ -0,0 +1,25 @@
/*
* This file defines procedure names used by the assembler, compiler,
* etc. to be the names used in this library.
*
* (In case you haven't guessed, the "k" in "klib" stands for:
*
* K L U D G E !)
*/
#define creat xcreat
#define open xopen
#define fopen xfopen
#define getc xgetc
#define getw xgetw
#define fcreat xfcreat
#define putw xputw
#define putc xputc
#define putchar(x) fputc(x,stdout)
#define strcmp xstrcmp
#define index xindex
#define strcpy xstrcpy
/*
* Defining the names in this manner allows using the V7 UNIX library
* to run the asinine V6 calls in the Alcyon software.
*
*/

View File

@@ -0,0 +1,20 @@
$ set noon
$ klib
$ !
$ ! Klib creation for vms
$ !
$ del *.o;*
$ cc68 cputc
$ cc68 creat
$ cc68 dup
$ cc68 getc
$ cc68 getchar
$ cc68 open
$ cc68 putc
$ cc68 putchar
$ cc68 seek
$ cc68 strcmp
$ del lib6.a;*
$ ar68 r lib6.a cputc.o putchar.o putc.o getchar.o
$ ar68 r lib6.a getc.o open.o creat.o seek.o
$ ar68 r lib6.a strcmp.o dup.o

View File

@@ -0,0 +1,100 @@
$1cp68 cputc.c $1x.i
$1c068 $1x.i $1x.ic $1x.st
$1c168 $1x.ic cputc.s -l
$1as68 -s 0$1 -f $1 -l -u cputc.s
era $1x.i
era $1x.ic
era $1x.st
era cputc.s
$1cp68 CREAT.c $1x.i
$1c068 $1x.i $1x.ic $1x.st
$1c168 $1x.ic CREAT.s -l
$1as68 -s 0$1 -f $1 -l -u CREAT.s
era $1x.i
era $1x.ic
era $1x.st
era CREAT.s
$1cp68 dup.c $1x.i
$1c068 $1x.i $1x.ic $1x.st
$1c168 $1x.ic dup.s -l
$1as68 -s 0$1 -f $1 -l -u dup.s
era $1x.i
era $1x.ic
era $1x.st
era dup.s
$1cp68 getc.c $1x.i
$1c068 $1x.i $1x.ic $1x.st
$1c168 $1x.ic getc.s -l
$1as68 -s 0$1 -f $1 -l -u getc.s
era $1x.i
era $1x.ic
era $1x.st
era getc.s
$1cp68 getchar.c $1x.i
$1c068 $1x.i $1x.ic $1x.st
$1c168 $1x.ic getchar.s -l
$1as68 -s 0$1 -f $1 -l -u getchar.s
era $1x.i
era $1x.ic
era $1x.st
era getchar.s
$1cp68 OPEN.c $1x.i
$1c068 $1x.i $1x.ic $1x.st
$1c168 $1x.ic OPEN.s -l
$1as68 -s 0$1 -f $1 -l -u OPEN.s
era $1x.i
era $1x.ic
era $1x.st
era OPEN.s
$1cp68 putc.c $1x.i
$1c068 $1x.i $1x.ic $1x.st
$1c168 $1x.ic putc.s -l
$1as68 -s 0$1 -f $1 -l -u putc.s
era $1x.i
era $1x.ic
era $1x.st
era putc.s
$1cp68 putchar.c $1x.i
$1c068 $1x.i $1x.ic $1x.st
$1c168 $1x.ic putchar.s -l
$1as68 -s 0$1 -f $1 -l -u putchar.s
era $1x.i
era $1x.ic
era $1x.st
era putchar.s
$1cp68 seek.c $1x.i
$1c068 $1x.i $1x.ic $1x.st
$1c168 $1x.ic seek.s -l
$1as68 -s 0$1 -f $1 -l -u seek.s
era $1x.i
era $1x.ic
era $1x.st
era seek.s
$1cp68 STRCMP.c $1x.i
$1c068 $1x.i $1x.ic $1x.st
$1c168 $1x.ic STRCMP.s -l
$1as68 -s 0$1 -f $1 -l -u STRCMP.s
era $1x.i
era $1x.ic
era $1x.st
era STRCMP.s
era lib6.a
$1ar68 rf $1 lib6.a cputc.o putchar.o putc.o getchar.o
$1ar68 rf $1 lib6.a getc.o open.o creat.o seek.o
$1ar68 rf $1 lib6.a strcmp.o dup.o
era *.o
user 6!make $1

View File

@@ -0,0 +1,31 @@
/****************************************************************************
*
* C F I L E O P E N R O U T I N E
* -------------------------------------
*
* The "open" routine opens a "C" file and returns a file id.
*
* Calling Sequence:
*
* fid = open(fname,mode,type);
*
* Where:
*
* fname is the address of a null terminated file name.
* mode is the open mode:
*
* 0 => READ access only
* 1 => WRITE access only
* 2 => Both READ and WRITE
* type is 0 for ASCII files, 1 for BINARY
*
*
*****************************************************************************/
#include <portab.h> /* */
WORD xopen(fname,mode,xtype) /****************************/
BYTE *fname; /* -> File name */
WORD mode; /* Open mode */
WORD xtype; /* File type */
{ /****************************/
return(_open(fname,mode,xtype)); /* Call clib routine */
} /****************************/

View File

@@ -0,0 +1,54 @@
/*****************************************************************************
*
* C P / M C R U N T I M E L I B H E A D E R F I L E
* -------------------------------------------------------------
* Copyright 1982 by Digital Research Inc. All rights reserved.
*
* This is an include file for assisting the user to write portable
* programs for C.
*
*****************************************************************************/
#define ALCYON 1 /* using Alcyon compiler */
/*
* Standard type definitions
*/
/***************************/
#define BYTE char /* Signed byte */
#define BOOLEAN char /* 2 valued (true/false) */
#define WORD short /* Signed word (16 bits) */
#define UWORD unsigned int /* unsigned word */
#define LONG long /* signed long (32 bits) */
#define ULONG unsigned long /* Unsigned long */
#define REG register /* register variable */
#define LOCAL auto /* Local var on 68000 */
#define EXTERN extern /* External variable */
#define MLOCAL static /* Local to module */
#define GLOBAL /**/ /* Global variable */
#define VOID /**/ /* Void function return */
#define DEFAULT int /* Default size */
#define FLOAT float /* Floating point */
#define DOUBLE double /* Double precision */
/***************************/
#ifdef ALCYON
#define UBYTE char
#else
#define UBYTE unsigned char /* Unsigned byte */
#endif
/****************************************************************************/
/* Miscellaneous Definitions: */
/****************************************************************************/
#define FAILURE (-1) /* Function failure return val */
#define SUCCESS (0) /* Function success return val */
#define YES 1 /* "TRUE" */
#define NO 0 /* "FALSE" */
#define FOREVER for(;;) /* Infinite loop declaration */
#define NULL 0 /* Null pointer value */
#define ZERO 0 /* Zero value */
#define EOF (-1) /* EOF Value */
#define TRUE (1) /* Function TRUE value */
#define FALSE (0) /* Function FALSE value */
/*************************** end of portab.h ********************************/

View File

@@ -0,0 +1,63 @@
#define BLEN 512
#include <klib.h>
struct iob {
int fd; /*file descriptor*/
int cc; /*char count*/
char *cp; /*ptr to next char*/
char cbuf[BLEN]; /*char buffer*/
};
fcreat(fname,ibuf,x)
char *fname;
int x;
register struct iob *ibuf;
{
ibuf->cc = BLEN; /*no chars*/
ibuf->cp = &(ibuf->cbuf[0]);
x = (x == 0) ? 0 : 1;
return(ibuf->fd=creat(fname,2,x));
}
putc(c,ibuf)
char c;
register struct iob *ibuf;
{
if(ibuf->cc<=0) {
ibuf->cp = &(ibuf->cbuf[0]);
if(write(ibuf->fd,ibuf->cp,BLEN) != BLEN)
return(-1);
ibuf->cc = BLEN;
}
*(ibuf->cp)++ = c;
ibuf->cc--;
return(c);
}
putw(w,ibuf)
int w;
register struct iob *ibuf;
{
register j;
int i;
putc((w>>8)&0xff,ibuf);
putc(w&0xff,ibuf);
return(w);
}
myfflush(ibuf)
register struct iob *ibuf;
{
register i;
i = BLEN - ibuf->cc;
ibuf->cc = BLEN;
ibuf->cp = &(ibuf->cbuf[0]);
if(write(ibuf->fd,ibuf->cp,i) != i)
return(-1);
return(0);
}

View File

@@ -0,0 +1,42 @@
#define BLEN 512
#include <klib.h>
struct iob {
int fd; /*file descriptor*/
int cc; /*char count*/
char *cp; /*ptr to next char*/
char cbuf[BLEN]; /*char buffer*/
} fout = {0,BLEN,&fout.cbuf[0]};
xputchar(cc)
char cc;
{
if(fout.fd <= 1) {
if(write(1,&cc,1) != 1)
return(-1);
return(cc);
}
/* buffered output*/
if(fout.cc<=0) {
fout.cp = &(fout.cbuf[0]);
if(write(fout.fd,fout.cp,BLEN) != BLEN)
return(-1);
fout.cc = BLEN;
}
*(fout.cp)++ = cc;
fout.cc--;
return(cc);
}
myflush()
{
register i;
i = BLEN - fout.cc;
fout.cc = BLEN;
fout.cp = &(fout.cbuf[0]);
if(write(fout.fd,fout.cp,i) != i)
return(-1);
return(0);
}

View File

@@ -0,0 +1,63 @@
#define BLEN 512
#include <klib.h>
struct iob {
int fd; /*file descriptor*/
int cc; /*char count*/
char *cp; /*ptr to next char*/
char cbuf[BLEN]; /*char buffer*/
};
fcreat(fname,ibuf,x)
char *fname;
int x;
register struct iob *ibuf;
{
ibuf->cc = BLEN; /*no chars*/
ibuf->cp = &(ibuf->cbuf[0]);
x = (x == 0) ? 0 : 1;
return(ibuf->fd=creat(fname,2,x));
}
putc(c,ibuf)
char c;
register struct iob *ibuf;
{
if(ibuf->cc<=0) {
ibuf->cp = &(ibuf->cbuf[0]);
if(write(ibuf->fd,ibuf->cp,BLEN) != BLEN)
return(-1);
ibuf->cc = BLEN;
}
*(ibuf->cp)++ = c;
ibuf->cc--;
return(c);
}
putw(w,ibuf)
int w;
register struct iob *ibuf;
{
register j;
int i;
putc((char)w,ibuf);
putc((char)(w>>8),ibuf);
return(w);
}
myfflush(ibuf)
register struct iob *ibuf;
{
register i;
i = BLEN - ibuf->cc;
ibuf->cc = BLEN;
ibuf->cp = &(ibuf->cbuf[0]);
if(write(ibuf->fd,ibuf->cp,i) != i)
return(-1);
return(0);
}

View File

@@ -0,0 +1,18 @@
/*
* Seek.c -- Whitesmith's equivalent of V6 seek
*/
long lseek();
seek(fildes,offset,ptrname)
int fildes; /* UNIX / WS file descriptor */
int offset; /* File offset, bytes */
int ptrname; /* Sense variable */
{
offset &= 0xffff; /* Clear sign extension problems*/
if(ptrname > 2) /* Not byte sense seek */
{ /* */
offset = offset << 9; /* Multiply by 512 */
ptrname -= 3; /* reset to range 0 .. 2 */
} /********************************/
return(lseek(fildes,(long)offset,ptrname));
}

View File

@@ -0,0 +1,16 @@
E:SEND KLIB.H
E:SEND MAKE.SUB
E:SEND SEEK.C
E:SEND OPEN.C
E:SEND LIB6.A
E:SEND CREAT.C
E:SEND GETC.C
E:SEND GETCHAR.C
E:SEND PUTC.C
E:SEND STRCMP.C
E:SEND PUTCHAR.C
E:SEND CPUTC.C
E:SEND DUP.C
E:SEND IODEC.H
E:SEND PORTAB.H
E:SEND SEND4.SUB

View File

@@ -0,0 +1,37 @@
/*********************************************************************
* STRCMP - compares strings
*
* Special version which is case - insensitive.
*
* WORD strcmp(s1,s2)
* BYTE *s1, *s2;
*
* 'strcmp' compares null terminated strings s1 and s2.
* Returns:
* strcmp < 0 if s1<s2
* strcmp = 0 if s1=s2
* strcmp > 0 if s1>s2
*********************************************************************/
#include <portab.h>
WORD xstrcmp(s1,s2)
REG BYTE *s1, *s2;
{
REG BYTE a,b;
while (*s1 && *s2)
{
a = _toupper(*s1++);
b = _toupper(*s2++);
if (a > b) return (1);
if (a < b) return (-1);
}
return(0);
}
MLOCAL BYTE _toupper(c)
REG BYTE c;
{
if(c >= 'a' && c <= 'z')
c -= 'a' - 'A';
return(c);
}

View File

@@ -0,0 +1,16 @@
e:vax KLIB.H s
e:vax MAKE.SUB s
e:vax SEEK.C s
e:vax OPEN.C s
e:vax CREAT.C s
e:vax GETC.C s
e:vax GETCHAR.C s
e:vax PUTC.C s
e:vax STRCMP.C s
e:vax PUTCHAR.C s
e:vax CPUTC.C s
e:vax DUP.C s
e:vax IODEC.H s
e:vax PORTAB.H s
e:vax SEND4.SUB s
e:vax up4.sub s

View File

@@ -0,0 +1,18 @@
$ set noon
$ klib
$ !
$ ! Klib creation for vms
$ !
$ del *.obj;*
$ cx cputc
$ cx creat
$ cx dup
$ cx getcvms
$ cx getchar
$ cx open
$ cx putcvms
$ cx putchar
$ cx seek
$ cx strcmp
$ del klib.olb;*
$ lib/creat klib *.obj

View File

@@ -0,0 +1,126 @@
/*
Copyright 1982
Alcyon Corporation
8716 Production Ave.
San Diego, Ca. 92121
*/
/*char *version "@(#) atof - dec 29, 1982"; */
/*
* Ascii String to IEEE Floating Point Routine :
* IEEE Standard Single Precision Representation Floating Point
*
* float
* atof(buf)
* char *buf;
*
* No more than 9 significant digits are allowed in single precision.
* Largest positive number is 3.4 * 10^33 and the smallest positive
* number is 1.2 * 10^-38.
* Rely's on the fact that a long and a float are both 32 bits.
*/
#define BIAS 127L
#define EXPSIZ 4
#define FRACSIZ 20
long fptoieee();
float strbin();
float power10();
long
atof(buf)
char *buf;
{
char ibuf[FRACSIZ], ebuf[EXPSIZ];
register char *ip, *ep;
long ieee; /* return value */
int dp, esign, isign, ebin, places;
float ibin, fp;
ip = &ibuf; ep = &ebuf; dp = 0; places = 0L;
while (*buf == ' ' || *buf == '\t') /* ignore white spaces */
buf++;
isign = (*buf == '-');
if (*buf == '-' || *buf == '+')
buf++;
while (*buf && *buf != 'e' && *buf != 'E') {
if (*buf == '.')
dp++;
else { /* digit seen */
*ip++ = *buf;
if (dp)
places++;
}
buf++;
}
*ip = 0;
if (*buf == 'e' || *buf == 'E') { /* exponent string */
buf++;
esign = (*buf == '-');
if (*buf == '-' || *buf == '+')
buf++;
while (*buf) /* get exponent string */
*ep++ = *buf++;
}
*ep = 0;
ibin = strbin(ibuf);
ebin = atoi(ebuf);
places = (esign) ? -ebin - places : ebin - places;
fp = ibin * power10(places);
ieee = fptoieee(fp);
if (isign) /* negative float */
ieee =| 0x80000000;
return( ieee );
}
float
power10(pwr) /* 10^pwr */
int pwr;
{
float f;
if (pwr < 0L) /* negative power */
for (f = 1.0; pwr < 0; pwr++)
f = f / 10.0;
else /* positive power */
for (f = 1.0; pwr > 0; pwr--)
f = f * 10.0;
return(f);
}
long
fptoieee(f) /* convert current machine float to ieee rep */
float f; /* unsigned float... */
{
register long exp, l;
if (f == 0.0)
return(0L);
exp = 0L;
for( ; f >= 2.0; f = f / 2.0)
exp++;
for( ; f < 1.0; f = f * 2.0)
exp--;
f = f - 1.0; /* implicit 1, eg. 1.F */
if (f != 0.0)
f = f * 8388608.0; /* 2 ^ 23 */
l = f;
exp =+ BIAS;
l =| ((exp<<23) & 0x7f800000);
return(l);
}
float
strbin(p) /* decimal string => binary long */
char *p;
{
float f;
for (f = 0.0; *p >= '0' && *p <= '9'; p++) {
f = f * 10.0;
f = f + (*p - '0');
}
return(f);
}

View File

@@ -0,0 +1,26 @@
/* atoi - convert decimal number in ascii to integer */
#include <portab.h>
#include <ctype.h>
WORD atoi(s)
REG BYTE *s;
{
REG WORD val;
REG WORD isneg;
val = 0;
isneg = FALSE;
while( isspace(*s) )
s++;
if( *s == '+' )
s++;
else if( *s == '-' ) {
s++;
isneg++;
}
while( *s >= '0' && *s <= '9' )
val = 10 * val + ( *s++ - '0' );
if( isneg )
val = -val;
return( val );
}

Some files were not shown because too many files have changed in this diff Show More